[Android] Use an interface to specify refresh actions

Edward Wang git at videolan.org
Tue Sep 2 10:12:25 CEST 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Mon Sep  1 16:52:13 2014 -0700| [dec3d729b642107acccbed6164a91763b512b242] | committer: Edward Wang

Use an interface to specify refresh actions

Fulfill a long-standing TODO

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=dec3d729b642107acccbed6164a91763b512b242
---

 .../videolan/vlc/gui/DirectoryViewFragment.java    |    4 +++-
 .../src/org/videolan/vlc/gui/HistoryFragment.java  |    4 +++-
 .../src/org/videolan/vlc/gui/MainActivity.java     |   13 ++++------
 .../org/videolan/vlc/interfaces/IRefreshable.java  |   25 ++++++++++++++++++++
 4 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index 5a2f4f6..5993bfd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -27,6 +27,7 @@ import org.videolan.libvlc.LibVLC;
 import org.videolan.vlc.R;
 import org.videolan.vlc.audio.AudioServiceController;
 import org.videolan.vlc.gui.video.VideoPlayerActivity;
+import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCRunnable;
@@ -51,7 +52,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.ListView;
 
-public class DirectoryViewFragment extends ListFragment implements ISortable {
+public class DirectoryViewFragment extends ListFragment implements IRefreshable, ISortable {
     public final static String TAG = "VLC/DirectoryViewFragment";
 
     private DirectoryAdapter mDirectoryAdapter;
@@ -201,6 +202,7 @@ public class DirectoryViewFragment extends ListFragment implements ISortable {
         Util.toaster(getActivity(), R.string.notavailable);
     }
 
+    @Override
     public void refresh() {
         if (mDirectoryAdapter != null)
             mDirectoryAdapter.refresh();
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 3c3aea4..42a2219 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -23,6 +23,7 @@ package org.videolan.vlc.gui;
 import org.videolan.libvlc.LibVLC;
 import org.videolan.vlc.R;
 import org.videolan.vlc.audio.AudioServiceController;
+import org.videolan.vlc.interfaces.IRefreshable;
 
 import android.os.Bundle;
 import android.support.v4.app.ListFragment;
@@ -38,7 +39,7 @@ import android.view.ViewGroup;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.ListView;
 
-public class HistoryFragment extends ListFragment {
+public class HistoryFragment extends ListFragment implements IRefreshable {
     public final static String TAG = "VLC/HistoryFragment";
 
     private HistoryAdapter mHistoryAdapter;
@@ -104,6 +105,7 @@ public class HistoryFragment extends ListFragment {
         return super.onContextItemSelected(item);
     }
 
+    @Override
     public void refresh() {
         Log.d(TAG, "Refreshing view!");
         if( mHistoryAdapter != null )
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 362f2f7..3b574c6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -40,6 +40,7 @@ import org.videolan.vlc.gui.audio.EqualizerFragment;
 import org.videolan.vlc.gui.video.MediaInfoFragment;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 import org.videolan.vlc.gui.video.VideoListAdapter;
+import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
@@ -605,12 +606,13 @@ public class MainActivity extends ActionBarActivity {
 
         // Intent to start a new Activity
         Intent intent;
+        // Current fragment loaded
+        Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
 
         // Handle item selection
         switch (item.getItemId()) {
             case R.id.ml_menu_sortby_name:
             case R.id.ml_menu_sortby_length:
-                Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
                 if (current == null)
                     break;
                 if (current instanceof ISortable)
@@ -632,13 +634,8 @@ public class MainActivity extends ActionBarActivity {
                 break;
             // Refresh
             case R.id.ml_menu_refresh:
-                // TODO: factor this into each fragment
-                if(mCurrentFragment != null && mCurrentFragment.equals("directories")) {
-                    DirectoryViewFragment directoryView = (DirectoryViewFragment) getFragment(mCurrentFragment);
-                    directoryView.refresh();
-                }
-                else if(mCurrentFragment != null && mCurrentFragment.equals("history"))
-                    ((HistoryFragment) getFragment(mCurrentFragment)).refresh();
+                if(current != null && current instanceof IRefreshable)
+                    ((IRefreshable) current).refresh();
                 else
                     MediaLibrary.getInstance().loadMediaItems(this, true);
                 break;
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IRefreshable.java b/vlc-android/src/org/videolan/vlc/interfaces/IRefreshable.java
new file mode 100644
index 0000000..2ac64b9
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IRefreshable.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * IRefreshable.java
+ *****************************************************************************
+ * Copyright © 2014 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.vlc.interfaces;
+
+public interface IRefreshable {
+    public void refresh();
+}



More information about the Android mailing list