[Android] Breadcrumb helper in browsers

Geoffrey Métais git at videolan.org
Tue Jun 12 16:55:32 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May  9 17:10:40 2018 +0200| [d44d3bb6d8cb1854c90cc93c9e2110748969e586] | committer: Geoffrey Métais

Breadcrumb helper in browsers

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

 .../res/drawable-hdpi/divider_grey_50_18dp.png     | Bin 0 -> 193 bytes
 .../res/drawable-mdpi/divider_grey_50_18dp.png     | Bin 0 -> 151 bytes
 .../res/drawable-xhdpi/divider_grey_50_18dp.png    | Bin 0 -> 220 bytes
 .../res/drawable-xxhdpi/divider_grey_50_18dp.png   | Bin 0 -> 292 bytes
 .../res/drawable-xxxhdpi/divider_grey_50_18dp.png  | Bin 0 -> 390 bytes
 vlc-android/res/layout/browser_path_item.xml       |  10 +++++
 vlc-android/res/layout/toolbar.xml                 |  15 +++++--
 .../vlc/gui/browser/BaseBrowserFragment.kt         |  24 ++++++++++-
 .../org/videolan/vlc/gui/browser/PathAdapter.kt    |  44 +++++++++++++++++++++
 9 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/drawable-hdpi/divider_grey_50_18dp.png b/vlc-android/res/drawable-hdpi/divider_grey_50_18dp.png
new file mode 100644
index 000000000..0bf3cd2f3
Binary files /dev/null and b/vlc-android/res/drawable-hdpi/divider_grey_50_18dp.png differ
diff --git a/vlc-android/res/drawable-mdpi/divider_grey_50_18dp.png b/vlc-android/res/drawable-mdpi/divider_grey_50_18dp.png
new file mode 100644
index 000000000..ffb0feb8c
Binary files /dev/null and b/vlc-android/res/drawable-mdpi/divider_grey_50_18dp.png differ
diff --git a/vlc-android/res/drawable-xhdpi/divider_grey_50_18dp.png b/vlc-android/res/drawable-xhdpi/divider_grey_50_18dp.png
new file mode 100644
index 000000000..991fb2b53
Binary files /dev/null and b/vlc-android/res/drawable-xhdpi/divider_grey_50_18dp.png differ
diff --git a/vlc-android/res/drawable-xxhdpi/divider_grey_50_18dp.png b/vlc-android/res/drawable-xxhdpi/divider_grey_50_18dp.png
new file mode 100644
index 000000000..abf93b3d9
Binary files /dev/null and b/vlc-android/res/drawable-xxhdpi/divider_grey_50_18dp.png differ
diff --git a/vlc-android/res/drawable-xxxhdpi/divider_grey_50_18dp.png b/vlc-android/res/drawable-xxxhdpi/divider_grey_50_18dp.png
new file mode 100644
index 000000000..735b52ceb
Binary files /dev/null and b/vlc-android/res/drawable-xxxhdpi/divider_grey_50_18dp.png differ
diff --git a/vlc-android/res/layout/browser_path_item.xml b/vlc-android/res/layout/browser_path_item.xml
new file mode 100644
index 000000000..8dbfac089
--- /dev/null
+++ b/vlc-android/res/layout/browser_path_item.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="wrap_content"
+    android:layout_height="18dp"
+    android:paddingBottom="2dp"
+    android:layout_marginBottom="4dp"
+    android:textColor="@color/grey50"
+    tools:text="folder"/>
\ No newline at end of file
diff --git a/vlc-android/res/layout/toolbar.xml b/vlc-android/res/layout/toolbar.xml
index 8d3461f7a..a3abd1e03 100644
--- a/vlc-android/res/layout/toolbar.xml
+++ b/vlc-android/res/layout/toolbar.xml
@@ -5,20 +5,29 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/appbar"
     android:layout_width="match_parent"
-    android:layout_height="?attr/actionBarSize"
+    android:layout_height="wrap_content"
+    android:background="?attr/background_actionbar"
     app:theme="@style/Toolbar.VLC"
     android:fitsSystemWindows="true">
     <android.support.v7.widget.Toolbar
         android:id="@+id/main_toolbar"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="wrap_content"
         app:navigationContentDescription="@string/abc_action_bar_up_description"
         app:theme="@style/Toolbar.VLC"
         app:popupTheme="?attr/toolbar_popup_style"
-        android:background="?attr/background_actionbar"
         app:navigationIcon="?attr/homeAsUpIndicator"
         app:titleMarginStart="@dimen/default_margin"
         app:layout_scrollFlags="scroll|enterAlways"
         android:keyboardNavigationCluster="true"
         tools:targetApi="o" />
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/ariane"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="8dp"
+        android:layout_marginLeft="16dp"
+        android:visibility="gone"
+        android:layout_marginStart="16dp"
+        app:layout_scrollFlags="scroll|enterAlways" />
 </android.support.design.widget.AppBarLayout>
\ No newline at end of file
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 1842c12fc..bb30bcb29 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -28,9 +28,12 @@ import android.net.Uri
 import android.os.Bundle
 import android.os.Message
 import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentManager
+import android.support.v4.content.ContextCompat
 import android.support.v4.widget.SwipeRefreshLayout
 import android.support.v7.preference.PreferenceManager
 import android.support.v7.view.ActionMode
+import android.support.v7.widget.DividerItemDecoration
 import android.support.v7.widget.LinearLayoutManager
 import android.support.v7.widget.RecyclerView
 import android.text.TextUtils
@@ -126,6 +129,23 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
         viewModel.dataset.observe(this, Observer<MutableList<MediaLibraryItem>> { mediaLibraryItems -> adapter.update(mediaLibraryItems!!) })
         viewModel.getDescriptionUpdate().observe(this, Observer { pair -> if (pair != null) adapter.notifyItemChanged(pair.first, pair.second) })
         initFavorites()
+
+        val ariane = requireActivity().findViewById<RecyclerView>(R.id.ariane)
+        currentMedia?.let {
+            ariane.visibility = View.VISIBLE
+            ariane.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
+            ariane.adapter = PathAdapter(this, Uri.decode(it.uri.path))
+            if (ariane.itemDecorationCount == 0) {
+                val did = DividerItemDecoration(requireContext(), DividerItemDecoration.HORIZONTAL)
+                did.setDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.divider_grey_50_18dp)!!)
+                ariane.addItemDecoration(did)
+            }
+            ariane.scrollToPosition(ariane.adapter.itemCount -1)
+        } ?: run { ariane.visibility = View.GONE }
+    }
+
+    fun backTo(tag: String) {
+        requireActivity().supportFragmentManager.popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE)
     }
 
     protected open fun initFavorites() {}
@@ -191,8 +211,8 @@ 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 mrl)
-        ft.replace(R.id.fragment_placeholder, next, media.location)
+        if (save) ft.addToBackStack(if (isRootDirectory) "root" else 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
new file mode 100644
index 000000000..0acdf724e
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/PathAdapter.kt
@@ -0,0 +1,44 @@
+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 segments = mutableListOf("browser").apply { addAll(path.replace(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, memoryTitle).split('/').filter { !it.isEmpty() } ) }
+
+    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
+        return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.browser_path_item, parent, false) as TextView)
+    }
+
+    override fun getItemCount() = segments.size
+
+    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
+        holder.root.text = segments[position]
+    }
+
+    inner class ViewHolder(val root : TextView) : RecyclerView.ViewHolder(root) {
+        init {
+            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]
+                }})
+            }
+        }
+    }
+}
\ No newline at end of file



More information about the Android mailing list