[Android] ViewModel saves sorting preference instead of View

Geoffrey Métais git at videolan.org
Thu Dec 13 16:26:50 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 13 11:21:09 2018 +0100| [b90695fed96dadf25cb29f70dd69e2e3d1e362c2] | committer: Geoffrey Métais

ViewModel saves sorting preference instead of View

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

 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java    | 8 +-------
 vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt      | 5 +++++
 vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt | 5 +++++
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
index b6cc5a933..287621796 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
@@ -295,13 +295,7 @@ public abstract class MediaBrowserFragment<T extends SortableModel> extends Frag
     }
 
     protected void sortBy(int sort) {
-        final T model = getViewModel();
-        model.sort(sort);
-        final String key = model.getKey();
-        Settings.INSTANCE.getInstance(requireContext()).edit()
-                .putInt(key, sort)
-                .putBoolean(key+"_desc", model.getDesc())
-                .apply();
+        getViewModel().sort(sort);
     }
 
     public Menu getMenu() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
index ddbba6ef2..6fca893a7 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
@@ -3,6 +3,7 @@ package org.videolan.vlc.viewmodels
 import android.content.Context
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.vlc.util.RefreshModel
+import org.videolan.vlc.util.Settings
 import org.videolan.vlc.util.canSortBy
 
 abstract class SortableModel(protected val context: Context): ScopedModel(), RefreshModel {
@@ -35,6 +36,10 @@ abstract class SortableModel(protected val context: Context): ScopedModel(), Ref
             }
             this.sort = sort
             refresh()
+            Settings.getInstance(context).edit()
+                    .putInt(sortKey, sort)
+                    .putBoolean("${sortKey}_desc", desc)
+                    .apply()
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
index dec33be20..2b5e24738 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -9,6 +9,7 @@ import androidx.paging.PositionalDataSource
 import kotlinx.coroutines.launch
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.vlc.util.Settings
 import org.videolan.vlc.viewmodels.SortableModel
 
 abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableModel(context), Medialibrary.OnMedialibraryReadyListener, Medialibrary.OnDeviceChangeListener {
@@ -63,6 +64,10 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
             desc = false
         } else desc = !desc
         refresh()
+        Settings.getInstance(context).edit()
+                .putInt(sortKey, sort)
+                .putBoolean("${sortKey}_desc", desc)
+                .apply()
     }
 
     fun isFiltering() = filter != null



More information about the Android mailing list