[Android] Fill video groups description in ViewModel

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


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 28 14:58:08 2018 +0200| [8b7729d69f4d63edc4f40cb4aa374c6fdf345e3b] | committer: Geoffrey Métais

Fill video groups description in ViewModel

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

 vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java       | 6 ------
 vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java | 4 +---
 vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt    | 8 +++++++-
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
index 42c778be5..5d428b0f1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
@@ -44,7 +44,6 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.AsyncImageLoader;
 import org.videolan.vlc.gui.helpers.AudioUtil;
-import org.videolan.vlc.media.MediaGroup;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public class CardPresenter extends Presenter {
@@ -119,11 +118,6 @@ public class CardPresenter extends Presenter {
         if (item instanceof MediaWrapper) {
             final MediaWrapper mw = (MediaWrapper) item;
             holder.mCardView.setTitleText(mw.getTitle());
-            if (mw.getType() == MediaWrapper.TYPE_GROUP) {
-                MediaGroup mediaGroup = (MediaGroup) mw;
-                final int size = mediaGroup.size();
-                mediaGroup.setDescription(VLCApplication.getAppResources().getQuantityString(R.plurals.videos_quantity, size, size));
-            }
             holder.mCardView.setContentText(mw.getDescription());
             holder.updateCardViewImage(mw);
             if (mIsSeenMediaMarkerVisible
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index d9fd3cd3d..cb1555d51 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -191,9 +191,7 @@ public class VideoListAdapter extends DiffUtilAdapter<MediaWrapper, VideoListAda
         long seen = 0L;
 
         if (media.getType() == MediaWrapper.TYPE_GROUP) {
-            MediaGroup mediaGroup = (MediaGroup) media;
-            final int size = mediaGroup.size();
-            text = VLCApplication.getAppResources().getQuantityString(R.plurals.videos_quantity, size, size);
+            text = media.getDescription();
         } else {
             /* Time / Duration */
             if (media.getLength() > 0) {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
index faaf4ad1e..48803458a 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/VideosProvider.kt
@@ -30,6 +30,8 @@ import kotlinx.coroutines.experimental.withContext
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.interfaces.MediaAddedCb
 import org.videolan.medialibrary.media.MediaWrapper
+import org.videolan.vlc.R
+import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.media.MediaGroup
 import org.videolan.vlc.util.Util
 
@@ -37,6 +39,7 @@ open class VideosProvider(private val group: String?, private val minGroupLen: I
 
     override fun canSortByDuration() = true
     override fun canSortByLastModified() = true
+    private val res by lazy { VLCApplication.getAppResources() }
 
     private val thumbObs = Observer<MediaWrapper> { media -> updateActor.offer(MediaUpdate(listOf(media!!))) }
 
@@ -65,7 +68,10 @@ open class VideosProvider(private val group: String?, private val minGroupLen: I
                         if (title.startsWith(loGroup)) displayList.add(item)
                     }
                 }
-                minGroupLen > 0 -> MediaGroup.group(list, minGroupLen).mapTo(displayList) { it.media }
+                minGroupLen > 0 -> MediaGroup.group(list, minGroupLen).mapTo(displayList) {
+                    if (it.size() > 1 && res !== null) { it.description = res.getQuantityString(R.plurals.videos_quantity, it.size(), it.size()) }
+                    it.media
+                }
                 else -> displayList.addAll(list)
             }
             displayList



More information about the Android mailing list