[Android] Clear option for History

Geoffrey Métais git at videolan.org
Fri Dec 18 12:03:43 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 18 12:03:10 2015 +0100| [e8545edcc7850efe4d56bf55a5669f613d08661f] | committer: Geoffrey Métais

Clear option for History

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

 .../src/org/videolan/vlc/gui/HistoryAdapter.java   | 11 +++++++
 .../src/org/videolan/vlc/gui/HistoryFragment.java  | 38 +++++++++++++++-------
 .../src/org/videolan/vlc/gui/MainActivity.java     |  9 ++---
 .../videolan/vlc/gui/network/MRLPanelFragment.java |  3 +-
 .../src/org/videolan/vlc/interfaces/IHistory.java  |  6 ++++
 5 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
index 8b426a7..f1aed93 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
@@ -94,6 +94,17 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
         return mMediaList.isEmpty();
     }
 
+    public void clear() {
+        VLCApplication.runBackground(new Runnable() {
+            @Override
+            public void run() {
+                MediaDatabase.getInstance().clearHistory();
+            }
+        });
+        mMediaList.clear();
+        notifyDataSetChanged();
+    }
+
     public void remove(final int position) {
         VLCApplication.runBackground(new Runnable() {
             @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index e934b06..bff6c8d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -36,13 +36,14 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.browser.MediaBrowserFragment;
 import org.videolan.vlc.gui.view.DividerItemDecoration;
 import org.videolan.vlc.gui.view.SwipeRefreshLayout;
+import org.videolan.vlc.interfaces.IHistory;
 import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.MediaDatabase;
 import org.videolan.vlc.media.MediaWrapper;
 
 import java.util.ArrayList;
 
-public class HistoryFragment extends MediaBrowserFragment implements IRefreshable, SwipeRefreshLayout.OnRefreshListener {
+public class HistoryFragment extends MediaBrowserFragment implements IRefreshable, IHistory, SwipeRefreshLayout.OnRefreshListener {
 
     public final static String TAG = "VLC/HistoryFragment";
 
@@ -108,9 +109,8 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
         }
     };
 
-    @Override
-    public void onResume() {
-        super.onResume();
+    public void onStart(){
+        super.onStart();
         if (mReadyToDisplay && mHistoryAdapter.isEmpty())
             display();
     }
@@ -151,21 +151,35 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
                 case UPDATE_LIST:
                     focusHelper(mHistoryAdapter.isEmpty());
                     mHistoryAdapter.setList((ArrayList<MediaWrapper>) msg.obj);
-                    if (mHistoryAdapter.isEmpty()){
-                        mRecyclerView.setVisibility(View.GONE);
-                        mEmptyView.setVisibility(View.VISIBLE);
-                    } else {
-                        mEmptyView.setVisibility(View.GONE);
-                        mRecyclerView.setVisibility(View.VISIBLE);
-                    }
+                    updateEmptyView();
                     if( mHistoryAdapter != null ) {
                         mHistoryAdapter.notifyDataSetChanged();
                         focusHelper(mHistoryAdapter.getItemCount() == 0);
                     } else
                         focusHelper(true);
                     mSwipeRefreshLayout.setRefreshing(false);
-
+                    getActivity().supportInvalidateOptionsMenu();
             }
         }
     };
+
+    private void updateEmptyView() {
+        if (mHistoryAdapter.isEmpty()){
+            mRecyclerView.setVisibility(View.GONE);
+            mEmptyView.setVisibility(View.VISIBLE);
+        } else {
+            mEmptyView.setVisibility(View.GONE);
+            mRecyclerView.setVisibility(View.VISIBLE);
+        }
+    }
+
+    public boolean isEmpty() {
+        return mHistoryAdapter.isEmpty();
+    }
+
+    @Override
+    public void clearHistory() {
+        mHistoryAdapter.clear();
+        updateEmptyView();
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index e2e2220..8f41a99 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -73,6 +73,7 @@ import org.videolan.vlc.gui.preferences.PreferencesActivity;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 import org.videolan.vlc.gui.video.VideoListAdapter;
 import org.videolan.vlc.gui.view.HackyDrawerLayout;
+import org.videolan.vlc.interfaces.IHistory;
 import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.media.MediaDatabase;
@@ -491,8 +492,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements Search
                     R.drawable.ic_menu_bookmark_outline_w);
         } else
             menu.findItem(R.id.ml_menu_save).setVisible(false);
-        if (current instanceof MRLPanelFragment)
-            menu.findItem(R.id.ml_menu_clean).setVisible(!((MRLPanelFragment) current).isEmpty());
+        if (current instanceof IHistory)
+            menu.findItem(R.id.ml_menu_clean).setVisible(!((IHistory) current).isEmpty());
         boolean showLast = current instanceof AudioBrowserFragment || (current instanceof VideoGridFragment && mSettings.getString(PreferencesActivity.VIDEO_LAST, null) != null);
         menu.findItem(R.id.ml_menu_last_playlist).setVisible(showLast);
         return true;
@@ -548,8 +549,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements Search
                 }
                 break;
             case R.id.ml_menu_clean:
-                if (current instanceof MRLPanelFragment)
-                    ((MRLPanelFragment)current).clearHistory();
+                if (current instanceof IHistory)
+                    ((IHistory)current).clearHistory();
                 break;
             case R.id.ml_menu_save:
                 if (current == null)
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
index a6c4a02..73bdc9a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
@@ -36,12 +36,13 @@ import android.widget.TextView;
 
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.MainActivity;
+import org.videolan.vlc.interfaces.IHistory;
 import org.videolan.vlc.media.MediaDatabase;
 import org.videolan.vlc.media.MediaUtils;
 
 import java.util.ArrayList;
 
-public class MRLPanelFragment extends Fragment implements View.OnKeyListener, TextView.OnEditorActionListener {
+public class MRLPanelFragment extends Fragment implements IHistory, View.OnKeyListener, TextView.OnEditorActionListener {
     private static final String TAG = "VLC/MrlPanelFragment";
     private RecyclerView mRecyclerView;
     private MRLAdapter mAdapter;
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IHistory.java b/vlc-android/src/org/videolan/vlc/interfaces/IHistory.java
new file mode 100644
index 0000000..b8325cd
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IHistory.java
@@ -0,0 +1,6 @@
+package org.videolan.vlc.interfaces;
+
+public interface IHistory {
+    boolean isEmpty();
+    void clearHistory();
+}



More information about the Android mailing list