[Android] Use viewmodels to load tracks on FAB actions

Geoffrey Métais git at videolan.org
Thu Sep 6 18:16:33 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep  6 18:15:52 2018 +0200| [6df8b0592af5b061c1656caa96919a99889b58b2] | committer: Geoffrey Métais

Use viewmodels to load tracks on FAB actions

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

 .../videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java  |  5 +++--
 .../org/videolan/vlc/gui/audio/AudioBrowserAdapter.java   | 15 ---------------
 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.java  |  3 ++-
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 7e2bb8040..0b7431447 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -55,6 +55,7 @@ import org.videolan.vlc.viewmodels.paged.PagedAlbumsModel;
 import org.videolan.vlc.viewmodels.paged.PagedTracksModel;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, TabLayout.OnTabSelectedListener {
@@ -261,10 +262,10 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
         final List<MediaWrapper> list ;
         if (mViewPager.getCurrentItem() == 0) {
             list = new ArrayList<>();
-            for (MediaLibraryItem item : mAlbumsAdapter.getMediaItems())
+            for (MediaLibraryItem item : albumModel.getAll())
                 list.addAll(Util.arrayToArrayList(item.getTracks()));
         } else {
-            list = (List<MediaWrapper>) (List<?>) mSongsAdapter.getMediaItems();
+            list = Arrays.asList(tracksModel.getAll());
         }
         MediaUtils.INSTANCE.openList(getActivity(), list, 0);
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 961a1e201..6e09fef12 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -30,7 +30,6 @@ import android.content.Context;
 import android.databinding.ViewDataBinding;
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Build;
-import android.support.annotation.MainThread;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v7.util.DiffUtil;
@@ -40,7 +39,6 @@ import android.view.ViewGroup;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.medialibrary.media.MediaLibraryItem;
-import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.tools.MultiSelectAdapter;
 import org.videolan.tools.MultiSelectHelper;
 import org.videolan.vlc.BR;
@@ -54,8 +52,6 @@ import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.ModelsHelper;
 import org.videolan.vlc.util.Util;
 
-import java.util.ArrayList;
-import java.util.LinkedList;
 import java.util.List;
 
 import static org.videolan.medialibrary.media.MediaLibraryItem.FLAG_SELECTED;
@@ -159,17 +155,6 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
         return currentList == null || currentList.isEmpty();
     }
 
-    public List<MediaLibraryItem> getAll() {
-        return getCurrentList();
-    }
-
-    List<MediaLibraryItem> getMediaItems() {
-        final List<MediaLibraryItem> list = new ArrayList<>();
-        final PagedList<MediaLibraryItem> currentList = getCurrentList();
-        if (currentList != null) for (MediaLibraryItem item : currentList) if (!(item.getItemType() == MediaLibraryItem.TYPE_DUMMY)) list.add(item);
-        return list;
-    }
-
     int getListWithPosition(List<MediaLibraryItem> list, int position) {
         int offset = 0, count = getItemCount();
         for (int i = 0; i < count; ++i)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 4b0c8c1ae..fb59270cc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -61,6 +61,7 @@ import org.videolan.vlc.viewmodels.paged.PagedGenresModel;
 import org.videolan.vlc.viewmodels.paged.PagedPlaylistsModel;
 import org.videolan.vlc.viewmodels.paged.PagedTracksModel;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
 
@@ -230,7 +231,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
 
     @Override
     public void onFabPlayClick(View view) {
-        final List<MediaWrapper> list = ((List<MediaWrapper>)(List<?>) mSongsAdapter.getMediaItems());
+        final List<MediaWrapper> list = Arrays.asList(tracksModel.getAll());
         final int count = list.size();
         if (count > 0) {
             final Random rand = new Random();



More information about the Android mailing list