Commit dec3d729 authored by Edward Wang's avatar Edward Wang

Use an interface to specify refresh actions

Fulfill a long-standing TODO
parent 62ca25d6
......@@ -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();
......
......@@ -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 )
......
......@@ -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;
......
/*****************************************************************************
* 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();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment