[Android] Fix browser initial sort and sort on resume
Nicolas Pomepuy
git at videolan.org
Wed Jun 22 10:04:20 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Jun 22 11:14:22 2022 +0200| [f6cf2774118ed017eda351fe0562eb16e4caf55c] | committer: Nicolas Pomepuy
Fix browser initial sort and sort on resume
Fixes #2579
> https://code.videolan.org/videolan/vlc-android/commit/f6cf2774118ed017eda351fe0562eb16e4caf55c
---
.../vlc/gui/browser/FileBrowserFragment.kt | 2 +-
.../vlc/viewmodels/browser/BrowserModel.kt | 25 +++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
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 a9c9f71c3..41385ca47 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
@@ -130,7 +130,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
override fun onResume() {
super.onResume()
- viewModel.sort(viewModel.sort)
+ viewModel.reSort()
}
override fun onPrepareOptionsMenu(menu: Menu) {
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index 7758788ec..1c0c1a666 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -73,11 +73,34 @@ open class BrowserModel(
fun browseRoot() = provider.browseRoot()
+ /**
+ * Sorts again. Useful on resume
+ *
+ */
+ fun reSort() {
+ resetSort()
+ viewModelScope.launch {
+ val comp = provider.comparator
+ dataset.value = withContext(coroutineContextProvider.Default) { dataset.value.apply { sortWith(comp) }.also { provider.computeHeaders(dataset.value) } }
+ }
+ }
+
+ /**
+ * Resets the sorts info from the shared preferences for the model and provider
+ *
+ */
+ private fun resetSort() {
+ sort = settings.getInt(sortKey, Medialibrary.SORT_DEFAULT)
+ desc = settings.getBoolean("${sortKey}_desc", false)
+ provider.desc = desc
+ provider.sort = sort
+ }
+
@MainThread
override fun sort(sort: Int) {
viewModelScope.launch {
this at BrowserModel.sort = sort
- desc = !desc
+ desc = if (sort == Medialibrary.SORT_DEFAULT) false else !desc
provider.sort = sort
provider.desc = desc
val comp = provider.comparator
More information about the Android
mailing list