[Android] Register top level viewmodels with main activity
Geoffrey Métais
git at videolan.org
Wed Apr 4 18:35:24 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 15 17:22:13 2018 +0100| [3ca26ebb23b2116f6e030fd2a19ee663176ad0dd] | committer: Geoffrey Métais
Register top level viewmodels with main activity
It allows to retain them while we switch from one category to another
> https://code.videolan.org/videolan/vlc-android/commit/3ca26ebb23b2116f6e030fd2a19ee663176ad0dd
---
vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java | 2 +-
.../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java | 10 +++++-----
.../src/org/videolan/vlc/gui/browser/FileBrowserFragment.java | 3 ++-
.../src/org/videolan/vlc/gui/video/VideoGridFragment.java | 2 +-
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index b0fa1a103..09f8bf43c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -75,7 +75,7 @@ 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(this).get(HistoryProvider.class);
+ mProvider = ViewModelProviders.of(getActivity()).get(HistoryProvider.class);
mProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
@Override
public void onChanged(@Nullable List<MediaWrapper> 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 5722fc72f..22a17e64c 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(this).get(ArtistProvider.class);
- albumProvider = ViewModelProviders.of(this).get(AlbumProvider.class);
- tracksProvider = ViewModelProviders.of(this).get(TracksProvider.class);
- genresprovider = ViewModelProviders.of(this).get(Genresprovider.class);
- playlistsProvider = ViewModelProviders.of(this).get(PlaylistsProvider.class);
+ 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);
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 a686d5734..ecbbde6a4 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,8 @@ public class FileBrowserFragment extends BaseBrowserFragment {
}
protected void setupBrowser() {
- mProvider = ViewModelProviders.of(this, new FileBrowserProvider.Factory(mMrl)).get(FileBrowserProvider.class);
+ if (mRoot) mProvider = ViewModelProviders.of(getActivity(), new FileBrowserProvider.Factory(null)).get(FileBrowserProvider.class);
+ else mProvider = ViewModelProviders.of(this, new FileBrowserProvider.Factory(mMrl)).get(FileBrowserProvider.class);
}
public String getTitle() {
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 caef573c5..164605ee9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -136,7 +136,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
if (!Util.isListEmpty(list)) mAdapter.update(list);
}
mGridView.setAdapter(mAdapter);
- mProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
+ mProvider.getDataset().observe(getActivity(), new Observer<List<MediaWrapper>>() {
@Override
public void onChanged(@Nullable List<MediaWrapper> mediaWrappers) {
mAdapter.update(mediaWrappers);
More information about the Android
mailing list