[Android] TV: allow mixing folders and files in the browser

Nicolas Pomepuy git at videolan.org
Mon Oct 3 07:38:42 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 29 13:52:21 2022 +0200| [ba8b6cc6c3048e5e589be2ac5f410e06b0434d54] | committer: Duncan McNamara

TV: allow mixing folders and files in the browser

Fixes #2686

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

 application/resources/src/main/res/values/strings.xml     |  2 ++
 .../videolan/television/ui/preferences/PreferencesUi.kt   |  2 ++
 .../tools/src/main/java/org/videolan/tools/Settings.kt    |  3 +++
 application/vlc-android/res/xml/preferences_ui.xml        |  8 ++++++++
 .../src/org/videolan/vlc/providers/BrowserProvider.kt     |  4 ++--
 .../vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt | 15 +++++++++------
 6 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index f0a10b375..9879caeb4 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -442,6 +442,8 @@
     <string name="artists_show_all_title">Show all artists</string>
     <string name="show_headers">Show headers</string>
     <string name="show_headers_summary">Split lists by headers depending on the sort type</string>
+    <string name="tv_folders_first">Show folders first</string>
+    <string name="tv_folders_first_summary">Show folders and then files in the file browser</string>
 
     <string name="extensions_prefs_category">Extensions</string>
     <string name="extensions_empty">No extension detected</string>
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesUi.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesUi.kt
index bb2303d0c..67fb5f6ba 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesUi.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesUi.kt
@@ -61,6 +61,7 @@ class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPrefer
         tvUiPref.setDefaultValue(true)
         findPreference<Preference>(KEY_APP_THEME)?.isVisible = false
         findPreference<Preference>(LIST_TITLE_ELLIPSIZE)?.isVisible = false
+        findPreference<Preference>(TV_FOLDERS_FIRST)?.isVisible = true
         prepareLocaleList()
         currentLocale = AppContextProvider.locale
     }
@@ -95,6 +96,7 @@ class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPrefer
                 (activity as PreferencesActivity).setRestartApp()
             }
             "browser_show_all_files" -> (activity as PreferencesActivity).setRestart()
+            TV_FOLDERS_FIRST -> Settings.tvFoldersFirst = sharedPreferences.getBoolean(TV_FOLDERS_FIRST, true)
         }
     }
 
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index f8df8f85b..c21f25c6d 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -28,6 +28,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
     var audioLongJumpDelay = 20
     var showHiddenFiles = false
     var showTrackNumber = true
+    var tvFoldersFirst = true
     private var audioControlsChangeListener: (() -> Unit)? = null
     lateinit var device : DeviceInfo
         private set
@@ -49,6 +50,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
         audioLongJumpDelay = prefs.getInt(KEY_AUDIO_LONG_JUMP_DELAY, 20)
         showHiddenFiles = prefs.getBoolean(BROWSER_SHOW_HIDDEN_FILES, true)
         showTrackNumber = prefs.getBoolean(ALBUMS_SHOW_TRACK_NUMBER, true)
+        tvFoldersFirst = prefs.getBoolean(TV_FOLDERS_FIRST, true)
         return prefs
     }
 
@@ -138,6 +140,7 @@ const val DISPLAY_UNDER_NOTCH = "display_under_notch"
 const val ALLOW_FOLD_AUTO_LAYOUT = "allow_fold_auto_layout"
 const val HINGE_ON_RIGHT = "hinge_on_right"
 const val AUDIO_HINGE_ON_RIGHT = "audio_hinge_on_right"
+const val TV_FOLDERS_FIRST = "tv_folders_first"
 
 const val VIDEO_PAUSED = "VideoPaused"
 const val VIDEO_SPEED = "VideoSpeed"
diff --git a/application/vlc-android/res/xml/preferences_ui.xml b/application/vlc-android/res/xml/preferences_ui.xml
index 979f2eaf8..f5e3eb540 100644
--- a/application/vlc-android/res/xml/preferences_ui.xml
+++ b/application/vlc-android/res/xml/preferences_ui.xml
@@ -41,6 +41,14 @@
             android:summary="@string/show_headers_summary"
             android:title="@string/show_headers"/>
 
+    <CheckBoxPreference
+            app:singleLineTitle="false"
+            android:key="tv_folders_first"
+            android:defaultValue="true"
+            app:isPreferenceVisible="false"
+            android:summary="@string/tv_folders_first_summary"
+            android:title="@string/tv_folders_first"/>
+
     <CheckBoxPreference
             app:singleLineTitle="false"
             android:key="include_missing"
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 38bdb9728..7a009f00f 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -83,8 +83,8 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         else -> true
     }
     fun getComparator(nbOfDigits: Int): Comparator<MediaLibraryItem>? = when {
-            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT) && desc -> tvDescComp
-            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT) && !desc -> tvAscComp
+            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT, Medialibrary.SORT_FILENAME) && desc -> getTvDescComp(Settings.tvFoldersFirst)
+            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT, Medialibrary.SORT_FILENAME) && !desc -> getTvAscComp(Settings.tvFoldersFirst)
             url != null && Uri.parse(url)?.scheme == "upnp" -> null
             sort == Medialibrary.SORT_ALPHA && desc -> descComp
             sort == Medialibrary.SORT_ALPHA && !desc -> ascComp
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 3c2245353..f94cae5d1 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -264,23 +264,26 @@ val descComp by lazy {
     }
 }
 
-val tvAscComp by lazy {
-    Comparator<MediaLibraryItem> { item1, item2 ->
+fun getTvAscComp(foldersFirst: Boolean): Comparator<MediaLibraryItem> = Comparator<MediaLibraryItem> { item1, item2 ->
+    if (foldersFirst) {
         val type1 = (item1 as? MediaWrapper)?.type
         val type2 = (item2 as? MediaWrapper)?.type
         if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
         else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
-        item1?.title?.lowercase(Locale.getDefault())?.compareTo(item2?.title?.lowercase(Locale.getDefault()) ?: "") ?: -1
     }
+    item1?.title?.lowercase(Locale.getDefault())?.compareTo(item2?.title?.lowercase(Locale.getDefault())
+            ?: "") ?: -1
 }
-val tvDescComp by lazy {
-    Comparator<MediaLibraryItem> { item1, item2 ->
+
+fun getTvDescComp(foldersFirst: Boolean): Comparator<MediaLibraryItem> = Comparator<MediaLibraryItem> { item1, item2 ->
+    if (foldersFirst) {
         val type1 = (item1 as? MediaWrapper)?.type
         val type2 = (item2 as? MediaWrapper)?.type
         if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
         else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
-        item2?.title?.lowercase(Locale.getDefault())?.compareTo(item1?.title?.lowercase(Locale.getDefault()) ?: "") ?: -1
     }
+    item2?.title?.lowercase(Locale.getDefault())?.compareTo(item1?.title?.lowercase(Locale.getDefault())
+            ?: "") ?: -1
 }
 
 fun getFilenameAscComp(nbOfDigits: Int): Comparator<MediaLibraryItem> = Comparator<MediaLibraryItem> { item1, item2 ->



More information about the Android mailing list