[Android] Clean ViewModels registration

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


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 28 11:06:49 2018 +0200| [89adbcd939b2d64db7ac3d9a30b3bbc71382527f] | committer: Geoffrey Métais

Clean ViewModels registration

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

 vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java      |  4 ++--
 .../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java   | 10 +++++-----
 .../src/org/videolan/vlc/gui/browser/FileBrowserFragment.java  |  2 +-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java      |  4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 09f8bf43c..32fea216c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -75,11 +75,11 @@ public class HistoryFragment extends MediaBrowserFragment<HistoryProvider> imple
         mEmptyView = view.findViewById(android.R.id.empty);
         mSwipeRefreshLayout = view.findViewById(R.id.swipeLayout);
         mRecyclerView = view.findViewById(android.R.id.list);
-        mProvider = ViewModelProviders.of(getActivity()).get(HistoryProvider.class);
+        mProvider = ViewModelProviders.of(requireActivity()).get(HistoryProvider.class);
         mProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
             @Override
             public void onChanged(@Nullable List<MediaWrapper> mediaWrappers) {
-                mHistoryAdapter.update(mediaWrappers);
+                if (mediaWrappers != null) mHistoryAdapter.update(mediaWrappers);
             }
         });
     }
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 22a17e64c..942eb2d53 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -166,11 +166,11 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
     }
 
     private void setupObservers() {
-        artistProvider = ViewModelProviders.of(getActivity()).get(ArtistProvider.class);
-        albumProvider = ViewModelProviders.of(getActivity()).get(AlbumProvider.class);
-        tracksProvider = ViewModelProviders.of(getActivity()).get(TracksProvider.class);
-        genresprovider = ViewModelProviders.of(getActivity()).get(Genresprovider.class);
-        playlistsProvider = ViewModelProviders.of(getActivity()).get(PlaylistsProvider.class);
+        artistProvider = ViewModelProviders.of(requireActivity()).get(ArtistProvider.class);
+        albumProvider = ViewModelProviders.of(requireActivity()).get(AlbumProvider.class);
+        tracksProvider = ViewModelProviders.of(requireActivity()).get(TracksProvider.class);
+        genresprovider = ViewModelProviders.of(requireActivity()).get(Genresprovider.class);
+        playlistsProvider = ViewModelProviders.of(requireActivity()).get(PlaylistsProvider.class);
         mProvidersList = new AudioModel[] {artistProvider, albumProvider, tracksProvider, genresprovider, playlistsProvider};
         //Register current tab first
         final int currentTab = mViewPager.getCurrentItem();
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index ecbbde6a4..0798ff2f0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -73,7 +73,7 @@ public class FileBrowserFragment extends BaseBrowserFragment {
     }
 
     protected void setupBrowser() {
-        if (mRoot) mProvider = ViewModelProviders.of(getActivity(), new FileBrowserProvider.Factory(null)).get(FileBrowserProvider.class);
+        if (mRoot) mProvider = ViewModelProviders.of(requireActivity(), new FileBrowserProvider.Factory(null)).get(FileBrowserProvider.class);
         else mProvider = ViewModelProviders.of(this, new FileBrowserProvider.Factory(mMrl)).get(FileBrowserProvider.class);
     }
 
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 a05069059..7027be81d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -93,7 +93,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
         if (savedInstanceState != null) setGroup(savedInstanceState.getString(KEY_GROUP));
         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, Medialibrary.SORT_DEFAULT)).get(VideosProvider.class);
+        mProvider = ViewModelProviders.of(requireActivity(), new VideosProvider.Factory(mGroup, minGroupLengthValue, Medialibrary.SORT_DEFAULT)).get(VideosProvider.class);
     }
 
 
@@ -139,7 +139,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
             if (!Util.isListEmpty(list)) mAdapter.update(list);
         }
         mGridView.setAdapter(mAdapter);
-        mProvider.getDataset().observe(requireActivity(), new Observer<List<MediaWrapper>>() {
+        mProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
             @Override
             public void onChanged(@Nullable List<MediaWrapper> mediaWrappers) {
                 if (mediaWrappers != null) mAdapter.update(mediaWrappers);



More information about the Android mailing list