[Android] Breadcrumb: SD card support
Geoffrey Métais
git at videolan.org
Wed Aug 8 15:46:39 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 8 15:44:52 2018 +0200| [67f92f0154c7316e08eaee51d73b1f880f9ad528] | committer: Geoffrey Métais
Breadcrumb: SD card support
> https://code.videolan.org/videolan/vlc-android/commit/67f92f0154c7316e08eaee51d73b1f880f9ad528
---
.../medialibrary/media/MediaLibraryItem.java | 1 +
.../vlc/gui/browser/BaseBrowserFragment.kt | 2 +-
.../org/videolan/vlc/gui/browser/PathAdapter.kt | 30 +++++++++++++++++-----
.../videolan/vlc/providers/FileBrowserProvider.kt | 1 +
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index 7e1055c80..0913ecf13 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -18,6 +18,7 @@ public abstract class MediaLibraryItem implements Parcelable {
public static final int FLAG_NONE = 0;
public static final int FLAG_SELECTED = 1;
public static final int FLAG_FAVORITE = 1 << 1;
+ public static final int FLAG_STORAGE = 1 << 2;
public abstract MediaWrapper[] getTracks();
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index e2d626b56..8cd075cda 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -139,7 +139,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
if (media != null && isSchemeSupported(media.uri?.scheme)) {
ariane.visibility = View.VISIBLE
ariane.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
- ariane.adapter = PathAdapter(this, Uri.decode(media.uri.path))
+ ariane.adapter = PathAdapter(this, media)
if (ariane.itemDecorationCount == 0) {
val did = DividerItemDecoration(requireContext(), DividerItemDecoration.HORIZONTAL)
did.setDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.divider_grey_50_18dp)!!)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
index ff2ba1af5..5d524d3c7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
@@ -1,19 +1,28 @@
package org.videolan.vlc.gui.browser
+import android.net.Uri
+import android.support.v4.util.SimpleArrayMap
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
+import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.util.AndroidDevices
-class PathAdapter(val browser: BaseBrowserFragment, path: String) : RecyclerView.Adapter<PathAdapter.ViewHolder>() {
+private val storages = SimpleArrayMap<String, String>()
+
+class PathAdapter(val browser: BaseBrowserFragment, media: MediaWrapper) : RecyclerView.Adapter<PathAdapter.ViewHolder>() {
+
+ init {
+ if (media.hasStateFlags(MediaLibraryItem.FLAG_STORAGE)) storages.put(Uri.decode(media.uri.path), media.title)
+ }
private val memoryTitle = browser.getString(R.string.internal_memory)
private val browserTitle = browser.getString(R.string.browser)
private val otgDevice = browser.getString(R.string.otg_device_title)
-
- private val segments = prepareSegments(path)
+ private val segments = prepareSegments(Uri.decode(media.uri.path))
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.browser_path_item, parent, false) as TextView)
@@ -36,14 +45,21 @@ class PathAdapter(val browser: BaseBrowserFragment, path: String) : RecyclerView
}
}
- private fun prepareSegments(path: String) : MutableList<String>{
+ private fun prepareSegments(path: String) : MutableList<String> {
+ val isOtg = path.startsWith("/tree/")
val string = when {
- path.startsWith("/tree/") -> if (path.endsWith(':')) "" else path.substringAfterLast(':')
- else -> path.replace(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, memoryTitle)
+ isOtg -> if (path.endsWith(':')) "" else path.substringAfterLast(':')
+ path.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY) -> path.replace(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, memoryTitle)
+ else -> replaceStoragePath(path)
}
val list = mutableListOf(browserTitle)
- if (path.startsWith("/tree/")) list.add(otgDevice)
+ if (isOtg) list.add(otgDevice)
list.addAll(string.split('/').filter { !it.isEmpty() })
return list
}
+
+ private fun replaceStoragePath(path: String): String {
+ if (storages.size() > 0) for (i in 0..storages.size()) if (path.startsWith(storages.keyAt(i))) return path.replace(storages.keyAt(i), storages.valueAt(i))
+ return path
+ }
}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
index ced9b64f3..cd29e303a 100644
--- a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
@@ -109,6 +109,7 @@ open class FileBrowserProvider(
} else {
val deviceName = FileUtils.getStorageTag(directory.title)
if (deviceName != null) directory.setDisplayTitle(deviceName)
+ directory.addStateFlags(MediaLibraryItem.FLAG_STORAGE)
}
devices.add(directory)
}
More information about the Android
mailing list