[Android] Fix show hidden setting initial value

Nicolas Pomepuy git at videolan.org
Wed Aug 10 09:15:06 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug  9 11:01:24 2022 +0200| [686dcb257f22157d6aa7e414998e771cdda04008] | committer: Duncan McNamara

Fix show hidden setting initial value

Fixes #2642

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

 application/tools/src/main/java/org/videolan/tools/Settings.kt    | 5 +++++
 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt       | 8 ++++----
 .../src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt       | 3 +++
 .../src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt    | 3 ++-
 4 files changed, 14 insertions(+), 5 deletions(-)

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 b99f28fe2..57132a804 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -26,6 +26,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
     var videoDoubleTapJumpDelay = 10
     var audioJumpDelay = 10
     var audioLongJumpDelay = 20
+    var showHiddenFiles = false
     private var audioControlsChangeListener: (() -> Unit)? = null
     lateinit var device : DeviceInfo
         private set
@@ -45,6 +46,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
         videoDoubleTapJumpDelay = prefs.getInt(KEY_VIDEO_DOUBLE_TAP_JUMP_DELAY, 10)
         audioJumpDelay = prefs.getInt(KEY_AUDIO_JUMP_DELAY, 10)
         audioLongJumpDelay = prefs.getInt(KEY_AUDIO_LONG_JUMP_DELAY, 20)
+        showHiddenFiles = prefs.getBoolean(BROWSER_SHOW_HIDDEN_FILES, true)
         return prefs
     }
 
@@ -171,6 +173,9 @@ const val WIDGETS_BACKGROUND_LAST_COLORS = "widgets_background_last_colors"
 const val WIDGETS_FOREGROUND_LAST_COLORS = "widgets_foreground_last_colors"
 const val CUSTOM_POPUP_HEIGHT = "custom_popup_height"
 
+//files
+const val BROWSER_SHOW_HIDDEN_FILES = "browser_show_hidden_files"
+
 class DeviceInfo(context: Context) {
     val pm = context.packageManager
     val tm = context.getSystemService<TelephonyManager>()!!
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index aa0417b02..d63dd596e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -120,7 +120,6 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
             mrl = requireActivity().intent.dataString
             requireActivity().intent = null
         }
-        showHiddenFiles = Settings.getInstance(requireContext()).getBoolean("browser_show_hidden_files", false)
         isRootDirectory = defineIsRoot()
         browserFavRepository = BrowserFavRepository.getInstance(requireContext())
         PlaybackService.serviceFlow.onEach {
@@ -152,7 +151,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
 
         val browserShowHiddenFiles = menu.findItem(R.id.browser_show_hidden_files)
         browserShowHiddenFiles.isVisible = true
-        browserShowHiddenFiles.isChecked = Settings.getInstance(requireActivity()).getBoolean("browser_show_hidden_files", true)
+        browserShowHiddenFiles.isChecked = Settings.showHiddenFiles
         if (requireActivity().isTalkbackIsEnabled()) menu.findItem(R.id.play_all).isVisible = true
         UiTools.updateSortTitles(this)
     }
@@ -471,8 +470,9 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
                 true
             }
             R.id.browser_show_hidden_files -> {
-                item.isChecked = !Settings.getInstance(requireActivity()).getBoolean("browser_show_hidden_files", true)
-                Settings.getInstance(requireActivity()).putSingle("browser_show_hidden_files", item.isChecked)
+                item.isChecked = !Settings.getInstance(requireActivity()).getBoolean(BROWSER_SHOW_HIDDEN_FILES, true)
+                Settings.getInstance(requireActivity()).putSingle(BROWSER_SHOW_HIDDEN_FILES, item.isChecked)
+                Settings.showHiddenFiles = item.isChecked
                 viewModel.updateShowHiddenFiles(item.isChecked)
                 true
             }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
index 892170765..85d3c76bd 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
@@ -37,6 +37,8 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.AndroidDevices
 import org.videolan.resources.CTX_FAV_ADD
+import org.videolan.tools.BROWSER_SHOW_HIDDEN_FILES
+import org.videolan.tools.Settings
 import org.videolan.tools.removeFileScheme
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.SecondaryActivity
@@ -84,6 +86,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
     }
 
     protected open fun setupBrowser() {
+        showHiddenFiles = Settings.getInstance(requireActivity()).getBoolean(BROWSER_SHOW_HIDDEN_FILES, true)
         viewModel = getBrowserModel(category = TYPE_FILE, url = if (!isRootDirectory) mrl else null, showHiddenFiles = showHiddenFiles)
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
index 8ab91f93d..593d28b18 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
@@ -37,6 +37,7 @@ import org.videolan.libvlc.Dialog
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.resources.CTX_FAV_ADD
 import org.videolan.tools.NetworkMonitor
+import org.videolan.tools.Settings
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.helpers.MedialibraryUtils
@@ -66,7 +67,7 @@ class NetworkBrowserFragment : BaseBrowserFragment(), IDialogManager {
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
-        viewModel = getBrowserModel(TYPE_NETWORK, mrl, showHiddenFiles)
+        viewModel = getBrowserModel(TYPE_NETWORK, mrl, Settings.showHiddenFiles)
         if (isRootDirectory) swipeRefreshLayout.isEnabled = false
     }
 



More information about the Android mailing list