[Android] Fix sort not remembered

Geoffrey Métais git at videolan.org
Thu Jul 25 18:27:47 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 25 18:21:19 2019 +0200| [c020981f91fd04095a60b0cba5590d9cc3dc9e8e] | committer: Geoffrey Métais

Fix sort not remembered

Fix #938

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

 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt      |  2 +-
 .../vlc/providers/medialibrary/MedialibraryProvider.kt       |  9 +++++----
 vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt | 12 +++++++-----
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index c119886c1..09bfe5261 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -371,7 +371,7 @@ object UiTools {
         item = menu.findItem(R.id.ml_menu_sortby_date)
         item?.setTitle(if (sort == AbstractMedialibrary.SORT_RELEASEDATE && !desc) R.string.sortby_date_desc else R.string.sortby_date)
         item = menu.findItem(R.id.ml_menu_sortby_last_modified)
-        item?.setTitle(if (sort == AbstractMedialibrary.SORT_RELEASEDATE && !desc) R.string.sortby_last_modified_date_desc else R.string.sortby_last_modified_date)
+        item?.setTitle(if (sort == AbstractMedialibrary.SORT_LASTMODIFICATIONDATE && !desc) R.string.sortby_last_modified_date_desc else R.string.sortby_last_modified_date)
         //        item = menu.findItem(R.id.ml_menu_sortby_number); TODO sort by track number
         //        if (item != null) item.setTitle(sort == AbstractMedialibrary.SORT_ && !desc ? R.string.sortby_number_desc : R.string.sortby_number);
 
diff --git a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
index 13d952c69..deb36e665 100644
--- a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
@@ -37,8 +37,9 @@ import org.videolan.vlc.viewmodels.SortableModel
 import kotlin.properties.Delegates
 
 abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context, val scope: SortableModel) : HeaderProvider(),
-    ISortModel
+        ISortModel
 {
+    private val settings = Settings.getInstance(context)
     protected val medialibrary = AbstractMedialibrary.getInstance()
     private lateinit var dataSource : DataSource<Int, T>
     val loading = MutableLiveData<Boolean>().apply { value = true }
@@ -46,8 +47,8 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
         private set
 
     protected open val sortKey : String = this.javaClass.simpleName
-    var sort = AbstractMedialibrary.SORT_DEFAULT
-    var desc = false
+    var sort = settings.getInt(sortKey, AbstractMedialibrary.SORT_DEFAULT)
+    var desc = settings.getBoolean("${sortKey}_desc", false)
 
     private val pagingConfig = Config(
             pageSize = MEDIALIBRARY_PAGE_SIZE,
@@ -72,7 +73,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
             }
             this.sort = sort
             refresh()
-            Settings.getInstance(context).edit()
+            settings.edit()
                     .putInt(sortKey, sort)
                     .putBoolean("${sortKey}_desc", desc)
                     .apply()
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
index c2a5b9293..4748797d1 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
@@ -2,15 +2,17 @@ package org.videolan.vlc.viewmodels
 
 import android.content.Context
 import org.videolan.medialibrary.interfaces.AbstractMedialibrary
-import org.videolan.vlc.util.*
+import org.videolan.vlc.util.ISortModel
+import org.videolan.vlc.util.RefreshModel
+import org.videolan.vlc.util.Settings
 
 abstract class SortableModel(protected val context: Context): ScopedModel(), RefreshModel,
     ISortModel
 {
-
+    private val settings = Settings.getInstance(context)
     protected open val sortKey : String = this.javaClass.simpleName
-    var sort = AbstractMedialibrary.SORT_DEFAULT
-    var desc = false
+    var sort = settings.getInt(sortKey, AbstractMedialibrary.SORT_DEFAULT)
+    var desc = settings.getBoolean("${sortKey}_desc", false)
 
     var filterQuery : String? = null
 
@@ -25,7 +27,7 @@ abstract class SortableModel(protected val context: Context): ScopedModel(), Ref
             }
             this.sort = sort
             refresh()
-            Settings.getInstance(context).edit()
+            settings.edit()
                     .putInt(sortKey, sort)
                     .putBoolean("${sortKey}_desc", desc)
                     .apply()



More information about the Android mailing list