[Android] Enable breadcrumb browsing for OTG devices

Geoffrey Métais git at videolan.org
Mon Aug 6 18:33:08 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Aug  6 18:32:40 2018 +0200| [83801612f34aed5a5414657863838f309cd6d5fc] | committer: Geoffrey Métais

Enable breadcrumb browsing for OTG devices

> https://code.videolan.org/videolan/vlc-android/commit/83801612f34aed5a5414657863838f309cd6d5fc
---

 vlc-android/res/values/strings.xml                 |  1 +
 .../vlc/gui/browser/BaseBrowserFragment.kt         |  2 +-
 .../org/videolan/vlc/gui/browser/PathAdapter.kt    | 23 +++++++++++++---------
 .../src/org/videolan/vlc/util/Browserutils.kt      |  2 +-
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 84f0a0435..5752684cb 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -617,4 +617,5 @@
     <string name="tv_my_new_videos">My new videos</string>
     <string name="cast_option_title">Cast medias on another screen</string>
     <string name="otg_device_title">OTG device</string>
+    <string name="browser">Browser</string>
 </resources>
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 b40adcd1d..6beb44939 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -213,7 +213,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
         viewModel.saveList(media)
         args.putParcelable(KEY_MEDIA, media)
         next.arguments = args
-        if (save) ft.addToBackStack(if (isRootDirectory) "root" else FileUtils.getFileNameFromPath(mrl))
+        if (save) ft.addToBackStack(if (isRootDirectory) "root" else currentMedia?.title ?: FileUtils.getFileNameFromPath(mrl))
         ft.replace(R.id.fragment_placeholder, next, media.title)
         ft.commit()
     }
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 0acdf724e..ff2ba1af5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
@@ -1,24 +1,19 @@
 package org.videolan.vlc.gui.browser
 
 import android.support.v7.widget.RecyclerView
-import android.util.Log
 import android.view.LayoutInflater
 import android.view.ViewGroup
 import android.widget.TextView
 import org.videolan.vlc.R
 import org.videolan.vlc.util.AndroidDevices
-import org.videolan.vlc.util.FileUtils
 
-private val EXTERNAL_PUBLIC_DIRECTORY_TAG = FileUtils.getFileNameFromPath(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
 class PathAdapter(val browser: BaseBrowserFragment, path: String) : RecyclerView.Adapter<PathAdapter.ViewHolder>() {
 
-    init {
-        Log.d("PathAdapter", path)
-    }
-
     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 = mutableListOf("browser").apply { addAll(path.replace(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, memoryTitle).split('/').filter { !it.isEmpty() } ) }
+    private val segments = prepareSegments(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)
@@ -35,10 +30,20 @@ class PathAdapter(val browser: BaseBrowserFragment, path: String) : RecyclerView
             root.setOnClickListener {
                 browser.backTo(adapterPosition.let { when (it) {
                     0 -> "root"
-                    1 -> if (segments[1] == memoryTitle) EXTERNAL_PUBLIC_DIRECTORY_TAG else segments[1]
                     else -> segments[it]
                 }})
             }
         }
     }
+
+    private fun prepareSegments(path: String) : MutableList<String>{
+        val string = when {
+            path.startsWith("/tree/") -> if (path.endsWith(':')) "" else path.substringAfterLast(':')
+            else -> path.replace(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, memoryTitle)
+        }
+        val list = mutableListOf(browserTitle)
+        if (path.startsWith("/tree/")) list.add(otgDevice)
+        list.addAll(string.split('/').filter { !it.isEmpty() })
+        return list
+    }
 }
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index 02879a714..ff802e92c 100644
--- a/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -27,7 +27,7 @@ import org.videolan.vlc.database.models.BrowserFav
 
 
 fun isSchemeSupported(scheme: String?) = when(scheme) {
-    "file", "smb", "ssh", "nfs" -> true
+    "file", "smb", "ssh", "nfs", "content" -> true
     else -> false
 }
 



More information about the Android mailing list