[Android] Update fragments registrations on hide/show
Geoffrey Métais
git at videolan.org
Tue Aug 29 15:17:38 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Aug 29 15:12:12 2017 +0200| [c2417a4f11252109625d475b37f7eaf07061d8b0] | committer: Geoffrey Métais
Update fragments registrations on hide/show
> https://code.videolan.org/videolan/vlc-android/commit/c2417a4f11252109625d475b37f7eaf07061d8b0
---
.../vlc/gui/audio/AudioBrowserFragment.java | 34 +++++++++-------------
.../vlc/gui/browser/BaseBrowserFragment.java | 14 ++-------
.../videolan/vlc/gui/video/VideoGridFragment.java | 28 +++++++-----------
3 files changed, 25 insertions(+), 51 deletions(-)
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 1cb401d1c..fd304d12c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -150,36 +150,28 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
mSwipeRefreshLayout.setOnRefreshListener(this);
}
- public void onStart() {
- if (mMediaLibrary.isInitiated())
- onMedialibraryReady();
- else
- setupMediaLibraryReceiver();
- super.onStart();
- for (View rv : mLists)
- registerForContextMenu(rv);
- mViewPager.addOnPageChangeListener(this);
- }
-
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if (!hidden) {
+ if (mMediaLibrary.isInitiated())
+ onMedialibraryReady();
+ else
+ setupMediaLibraryReceiver();
+ for (View rv : mLists)
+ registerForContextMenu(rv);
+ mViewPager.addOnPageChangeListener(this);
mFabPlay.setImageResource(R.drawable.ic_fab_shuffle);
setFabPlayShuffleAllVisibility();
+ } else {
+ mMediaLibrary.removeMediaUpdatedCb();
+ mMediaLibrary.removeMediaAddedCb();
+ for (View rv : mLists)
+ unregisterForContextMenu(rv);
+ mViewPager.removeOnPageChangeListener(this);
}
}
- @Override
- public void onStop() {
- super.onStop();
- mMediaLibrary.removeMediaUpdatedCb();
- mMediaLibrary.removeMediaAddedCb();
- for (View rv : mLists)
- unregisterForContextMenu(rv);
- mViewPager.removeOnPageChangeListener(this);
- }
-
private void setupTabLayout() {
mTabLayout.setupWithViewPager(mViewPager);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 94ef519c5..ea785489e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -212,29 +212,19 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
- if (mRoot) {
+ if (hidden || mRoot) {
runOnBrowserThread(new Runnable() {
@Override
public void run() {
releaseBrowser();
}
});
- } else if (!hidden && mFabPlay != null) {
+ } else if (mFabPlay != null) {
mFabPlay.setImageResource(R.drawable.ic_fab_play);
updateFab();
}
}
- public void onStop(){
- super.onStop();
- runOnBrowserThread(new Runnable() {
- @Override
- public void run() {
- releaseBrowser();
- }
- });
- }
-
private void releaseBrowser() {
if (mMediaBrowser != null) {
mMediaBrowser.release();
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 ffe9c8674..f08ad6f40 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -156,35 +156,27 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
mGridView.setAdapter(mAdapter);
}
- public void onStart() {
- if (mMediaLibrary.isInitiated())
- onMedialibraryReady();
- else if (mGroup == null)
- setupMediaLibraryReceiver();
- super.onStart();
- registerForContextMenu(mGridView);
- }
-
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if (!hidden) {
+ if (mMediaLibrary.isInitiated())
+ onMedialibraryReady();
+ else if (mGroup == null)
+ setupMediaLibraryReceiver();
+ registerForContextMenu(mGridView);
setSearchVisibility(false);
updateViewMode();
mFabPlay.setImageResource(R.drawable.ic_fab_play);
setFabPlayVisibility(true);
+ } else {
+ mMediaLibrary.removeMediaUpdatedCb();
+ mMediaLibrary.removeMediaAddedCb();
+ unregisterForContextMenu(mGridView);
}
}
@Override
- public void onStop() {
- super.onStop();
- mMediaLibrary.removeMediaUpdatedCb();
- mMediaLibrary.removeMediaAddedCb();
- unregisterForContextMenu(mGridView);
- }
-
- @Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_GROUP, mGroup);
@@ -197,7 +189,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO);
mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_VIDEO);
}
- if (!isHidden() && mAdapter.isEmpty())
+ if (!isHidden())
mHandler.sendEmptyMessage(UPDATE_LIST);
}
More information about the Android
mailing list