[Android] Media Brower FAB : Simply and factorize code

Alexandre Perraud git at videolan.org
Wed Dec 7 16:31:44 CET 2016


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Tue Dec  6 17:05:29 2016 +0100| [77e420b65abc8a8ad3afd8e574ce2e87190ac553] | committer: Alexandre Perraud

Media Brower FAB : Simply and factorize code

> https://code.videolan.org/videolan/vlc-android/commit/77e420b65abc8a8ad3afd8e574ce2e87190ac553
---

 .../vlc/gui/audio/AudioBrowserFragment.java        | 17 ++++-----------
 .../vlc/gui/browser/MediaBrowserFragment.java      | 25 ++++++++++++++++++++++
 .../videolan/vlc/gui/video/VideoGridFragment.java  | 20 ++++-------------
 3 files changed, 33 insertions(+), 29 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 7ed1abc..21fc8f8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -90,7 +90,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
     private TextView mEmptyView;
     private List<View> mLists;
     private FastScroller mFastScroller;
-    private FloatingActionButton mFabPlayShuffleAll;
     private View mSearchButtonView;
 
     public static final int REFRESH = 101;
@@ -175,22 +174,13 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
 
     public void onStart() {
         super.onStart();
-        mFabPlayShuffleAll = (FloatingActionButton)getActivity().findViewById(R.id.fab);
-        mFabPlayShuffleAll.setImageResource(R.drawable.ic_fab_shuffle);
+        mFabPlay.setImageResource(R.drawable.ic_fab_shuffle);
         setFabPlayShuffleAllVisibility();
-        mFabPlayShuffleAll.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                onFabPlayAllClick(v);
-            }
-        });
     }
 
     @Override
     public void onStop() {
         super.onStop();
-        mFabPlayShuffleAll.setOnClickListener(null);
-        mFabPlayShuffleAll.setVisibility(View.INVISIBLE);
     }
 
     private void setupTabLayout() {
@@ -384,7 +374,8 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
             return false;
     }
 
-    public void onFabPlayAllClick(View view) {
+    @Override
+    public void onFabPlayClick(View view) {
         List<MediaWrapper> list = ((List<MediaWrapper>)(List<?>) mSongsAdapter.getMediaItems());
         int count = list.size();
         if (count > 0) {
@@ -398,7 +389,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
     }
 
     public void setFabPlayShuffleAllVisibility() {
-        mFabPlayShuffleAll.setVisibility(mViewPager.getCurrentItem() == MODE_SONG ? View.VISIBLE : View.INVISIBLE);
+        setFabPlayVisibility(mViewPager.getCurrentItem() == MODE_SONG);
     }
 
     /**
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
index f92db80..da446f5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
@@ -27,6 +27,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.design.widget.BottomSheetDialogFragment;
+import android.support.design.widget.FloatingActionButton;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.view.ActionMode;
 import android.view.ContextMenu;
@@ -53,6 +54,7 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple
     protected volatile boolean mReadyToDisplay = true;
     protected Medialibrary mMediaLibrary;
     protected ActionMode mActionMode;
+    public FloatingActionButton mFabPlay;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -75,8 +77,29 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple
             activity.getSupportActionBar().setSubtitle(getSubTitle());
             getActivity().supportInvalidateOptionsMenu();
         }
+        mFabPlay = (FloatingActionButton)getActivity().findViewById(R.id.fab);
+        setFabPlayVisibility(false);
+        mFabPlay.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                onFabPlayClick(v);
+            }
+        });
     }
 
+    @Override
+    public void onStop() {
+        super.onStop();
+        mFabPlay.setOnClickListener(null);
+        setFabPlayVisibility(false);
+    }
+
+    public void setFabPlayVisibility(boolean enable) {
+        mFabPlay.setVisibility(enable ? View.VISIBLE : View.INVISIBLE);
+    }
+
+    public void onFabPlayClick(View view) {}
+
     public void setReadyToDisplay(boolean ready) {
         if (ready && !mReadyToDisplay)
             display();
@@ -156,11 +179,13 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
     public void startActionMode() {
         mActionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(this);
+        setFabPlayVisibility(false);
     }
 
     protected void stopActionMode() {
         if (mActionMode != null)
             mActionMode.finish();
+        setFabPlayVisibility(true);
     }
 
     public void invalidateActionMode() {
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 1f35441..9b08c1f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -142,15 +142,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
 
     public void onStart() {
         super.onStart();
-        mFabPlayAll = (FloatingActionButton)getActivity().findViewById(R.id.fab);
-        mFabPlayAll.setImageResource(R.drawable.ic_fab_play);
-        setFabPlayAllVisibility(true);
-        mFabPlayAll.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                onFabPlayAllClick(v);
-            }
-        });
+        mFabPlay.setImageResource(R.drawable.ic_fab_play);
+        setFabPlayVisibility(true);
     }
 
     @Override
@@ -333,11 +326,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
         }
     }
 
-    public void setFabPlayAllVisibility(boolean enable) {
-        mFabPlayAll.setVisibility(enable ? View.VISIBLE : View.INVISIBLE);
-    }
-
-    public void onFabPlayAllClick(View view) {
+    @Override
+    public void onFabPlayClick(View view) {
         ArrayList<MediaWrapper> playList = new ArrayList<>();
         MediaUtils.openList(getActivity(), playList, mVideoAdapter.getListWithPosition(playList, 0));
     }
@@ -498,7 +488,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
             stopActionMode();
             return false;
         }
-        setFabPlayAllVisibility(false);
         boolean honeComb = AndroidUtil.isHoneycombOrLater();
         int count = mVideoAdapter.getSelectedPositions().size();
         menu.findItem(R.id.action_video_info).setVisible(count == 1);
@@ -543,7 +532,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
     @Override
     public void onDestroyActionMode(ActionMode mode) {
         mVideoAdapter.setActionMode(false);
-        setFabPlayAllVisibility(true);
     }
 
     private static final int UPDATE_LIST = 14;



More information about the Android mailing list