[Android] Respect video group setting

Geoffrey Métais git at videolan.org
Wed Apr 4 18:35:45 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 21 15:34:43 2018 +0100| [4b066693d99a363cdceda7ac65e23a5447918e40] | committer: Geoffrey Métais

Respect video group setting

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

 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java      | 10 ++++++----
 vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt  |  9 ++++-----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 6530699c1..d76ba4db4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -90,7 +90,9 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
         super.onCreate(savedInstanceState);
         mAdapter = new VideoListAdapter(this);
         if (savedInstanceState != null) setGroup(savedInstanceState.getString(KEY_GROUP));
-        mProvider = ViewModelProviders.of(this, new VideosProvider.Factory(mGroup)).get(VideosProvider.class);
+        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
+        final int minGroupLengthValue = Integer.valueOf(preferences.getString("video_min_group_length", "6"));
+        mProvider = ViewModelProviders.of(this, new VideosProvider.Factory(mGroup, minGroupLengthValue)).get(VideosProvider.class);
     }
 
 
@@ -129,17 +131,17 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         mSwipeRefreshLayout.setOnRefreshListener(this);
-        mDividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
+        mDividerItemDecoration = new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL);
         if (mAdapter.isListMode()) mGridView.addItemDecoration(mDividerItemDecoration);
         if (savedInstanceState != null) {
             final List<MediaWrapper> list = (List<MediaWrapper>) VLCApplication.getData("list"+getTitle());
             if (!Util.isListEmpty(list)) mAdapter.update(list);
         }
         mGridView.setAdapter(mAdapter);
-        mProvider.getDataset().observe(getActivity(), new Observer<List<MediaWrapper>>() {
+        mProvider.getDataset().observe(requireActivity(), new Observer<List<MediaWrapper>>() {
             @Override
             public void onChanged(@Nullable List<MediaWrapper> mediaWrappers) {
-                mAdapter.update(mediaWrappers);
+                if (mediaWrappers != null) mAdapter.update(mediaWrappers);
             }
         });
     }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
index 204c0af7d..401b3a030 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
@@ -31,7 +31,7 @@ import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.vlc.media.MediaGroup
 import org.videolan.vlc.util.Util
 
-class VideosProvider(private val group: String?) : MedialibraryModel<MediaWrapper>(), MediaAddedCb {
+class VideosProvider(private val group: String?, private val minGroupLen: Int) : MedialibraryModel<MediaWrapper>(), MediaAddedCb {
 
     override fun canSortByDuration() = true
     override fun canSortByLastModified() = true
@@ -60,8 +60,7 @@ class VideosProvider(private val group: String?) : MedialibraryModel<MediaWrappe
                     if (title.toLowerCase().startsWith(group.toLowerCase())) displayList.add(item)
                 }
             } else {
-                //TODO get length value from prefs
-                MediaGroup.group(list, 6).mapTo(displayList) { it.media }
+                MediaGroup.group(list, minGroupLen).mapTo(displayList) { it.media }
             }
             displayList
         }
@@ -80,10 +79,10 @@ class VideosProvider(private val group: String?) : MedialibraryModel<MediaWrappe
         Medialibrary.lastThumb.removeObserver(thumbObs)
     }
 
-    class Factory(val group: String?): ViewModelProvider.NewInstanceFactory() {
+    class Factory(val group: String?, private val minGroupLen : Int): ViewModelProvider.NewInstanceFactory() {
         override fun <T : ViewModel> create(modelClass: Class<T>): T {
             @Suppress("UNCHECKED_CAST")
-            return VideosProvider(group) as T
+            return VideosProvider(group, minGroupLen) as T
         }
     }
 }



More information about the Android mailing list