[Android] Register ML callbacks sooner
Geoffrey Métais
git at videolan.org
Wed May 17 12:04:22 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 15 18:14:46 2017 +0200| [24959f615eaa90b563d405202965f6a195c71c98] | committer: Geoffrey Métais
Register ML callbacks sooner
> https://code.videolan.org/videolan/vlc-android/commit/24959f615eaa90b563d405202965f6a195c71c98
---
.../vlc/gui/audio/AudioBrowserFragment.java | 29 +++++++---------------
.../videolan/vlc/gui/video/VideoGridFragment.java | 17 +++++--------
2 files changed, 15 insertions(+), 31 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 2fc6bb7..23dd096 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -77,7 +77,6 @@ import java.util.Random;
public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable {
public final static String TAG = "VLC/AudioBrowserFragment";
- private MediaBrowser mMediaBrowser;
private MainActivity mMainActivity;
private AudioBrowserAdapter mArtistsAdapter;
@@ -168,18 +167,26 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
public void onStart() {
+ if (mMediaLibrary.isInitiated())
+ onMedialibraryReady();
+ else
+ setupMediaLibraryReceiver();
super.onStart();
mFabPlay.setImageResource(R.drawable.ic_fab_shuffle);
setFabPlayShuffleAllVisibility();
for (View rv : mLists)
registerForContextMenu(rv);
+ mViewPager.addOnPageChangeListener(this);
}
@Override
public void onStop() {
super.onStop();
+ mMediaLibrary.removeMediaUpdatedCb();
+ mMediaLibrary.removeMediaAddedCb();
for (View rv : mLists)
unregisterForContextMenu(rv);
+ mViewPager.removeOnPageChangeListener(this);
}
private void setupTabLayout() {
@@ -189,19 +196,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
@Override
- public void onPause() {
- super.onPause();
-
- mViewPager.removeOnPageChangeListener(this);
- mMediaLibrary.removeMediaUpdatedCb();
- mMediaLibrary.removeMediaAddedCb();
- if (mMediaBrowser != null) {
- mMediaBrowser.release();
- mMediaBrowser = null;
- }
- }
-
- @Override
public void onAttach(Context context) {
super.onAttach(context);
mMainActivity = (MainActivity) context;
@@ -211,11 +205,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
public void onResume() {
super.onResume();
setSearchVisibility(false);
- mViewPager.addOnPageChangeListener(this);
- if (mMediaLibrary.isInitiated() && !mMediaLibrary.isWorking())
- onMedialibraryReady();
- else
- setupMediaLibraryReceiver();
}
protected void onMedialibraryReady() {
@@ -335,7 +324,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
if (id == R.id.audio_view_info) {
- showInfoDialog((MediaWrapper) mSongsAdapter.getItem(position));
+ showInfoDialog(mSongsAdapter.getItem(position));
return true;
}
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 73abf94..f96256b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -129,6 +129,10 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
public void onStart() {
+ if (mMediaLibrary.isInitiated())
+ onMedialibraryReady();
+ else if (mGroup == null)
+ setupMediaLibraryReceiver();
super.onStart();
mFabPlay.setImageResource(R.drawable.ic_fab_play);
registerForContextMenu(mGridView);
@@ -139,22 +143,13 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
super.onResume();
setSearchVisibility(false);
updateViewMode();
- if (mMediaLibrary.isInitiated())
- onMedialibraryReady();
- else if (mGroup == null)
- setupMediaLibraryReceiver();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mMediaLibrary.removeMediaUpdatedCb();
- mMediaLibrary.removeMediaAddedCb();
}
@Override
public void onStop() {
super.onStop();
+ mMediaLibrary.removeMediaUpdatedCb();
+ mMediaLibrary.removeMediaAddedCb();
unregisterForContextMenu(mGridView);
}
More information about the Android
mailing list