Commit 8c8775ab authored by Geoffrey Métais's avatar Geoffrey Métais

BrowserFragment instead of interface

parent 791b3b91
......@@ -31,7 +31,7 @@ import java.util.concurrent.locks.ReentrantLock;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.vlc.gui.video.VideoBrowserInterface;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.BitmapUtil;
import org.videolan.vlc.util.VLCInstance;
......@@ -45,7 +45,7 @@ import android.view.Display;
public class Thumbnailer implements Runnable {
public final static String TAG = "VLC/Thumbnailer";
private VideoBrowserInterface mVideoBrowser;
private IVideoBrowser mVideoBrowser;
private final Queue<MediaWrapper> mItems = new LinkedList<MediaWrapper>();
......@@ -66,7 +66,7 @@ public class Thumbnailer implements Runnable {
mPrefix = context.getResources().getString(R.string.thumbnail);
}
public void start(VideoBrowserInterface videoBrowser) {
public void start(IVideoBrowser videoBrowser) {
if (mLibVlc == null) {
try {
mLibVlc = VLCInstance.getLibVlcInstance();
......@@ -213,7 +213,7 @@ public class Thumbnailer implements Runnable {
Log.d(TAG, "Thumbnailer stopped");
}
public void setVideoBrowser(VideoBrowserInterface browser){
public void setVideoBrowser(IVideoBrowser browser){
mVideoBrowser = browser;
}
}
/*
* *************************************************************************
* BrowserFragment.java
* **************************************************************************
* Copyright © 2015 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.gui;
import android.support.v4.app.Fragment;
public class BrowserFragment extends Fragment {
protected volatile boolean mReadyToDisplay = true;
protected void setReadyToDisplay(boolean ready){}
protected void display(){}
}
......@@ -28,7 +28,6 @@ import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.IBrowser;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.util.Util;
......@@ -42,7 +41,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.PopupMenu;
......@@ -60,10 +58,11 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
public class DirectoryViewFragment extends ListFragment implements IBrowser, IRefreshable, ISortable, SwipeRefreshLayout.OnRefreshListener {
public class DirectoryViewFragment extends BrowserFragment implements IRefreshable, ISortable, SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {
public final static String TAG = "VLC/DirectoryViewFragment";
private DirectoryAdapter mDirectoryAdapter;
private ListView mListView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private boolean mReady = true;
......@@ -98,13 +97,16 @@ public class DirectoryViewFragment extends ListFragment implements IBrowser, IRe
}
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.directories);
View v = inflater.inflate(R.layout.directory_view, container, false);
mListView = (ListView) v.findViewById(android.R.id.list);
mListView.setOnItemClickListener(this);
mDirectoryAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
setListAdapter(mDirectoryAdapter);
mListView.setAdapter(mDirectoryAdapter);
final ListView listView = (ListView)v.findViewById(android.R.id.list);
listView.setNextFocusUpId(R.id.ml_menu_search);
listView.setNextFocusLeftId(android.R.id.list);
......@@ -198,13 +200,14 @@ public class DirectoryViewFragment extends ListFragment implements IBrowser, IRe
}
@Override
public void onListItemClick(ListView l, View v, int p, long id) {
int success = mDirectoryAdapter.browse(p);
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int success = mDirectoryAdapter.browse(position);
if(success < 0) /* Clicked on a media file */
openMediaFile(p);
openMediaFile(position);
else
setSelection(success);
mListView.setSelection(success);
}
public boolean isRootDirectory () {
......@@ -215,7 +218,7 @@ public class DirectoryViewFragment extends ListFragment implements IBrowser, IRe
int success = mDirectoryAdapter.browse("..");
if(success >= 0)
setSelection(success);
mListView.setSelection(success);
};
private void openMediaFile(int p) {
......
......@@ -23,9 +23,10 @@ package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.interfaces.IBrowser;
import org.videolan.vlc.interfaces.IRefreshable;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.SwipeRefreshLayout;
......@@ -38,13 +39,15 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
public class HistoryFragment extends ListFragment implements IBrowser, IRefreshable, SwipeRefreshLayout.OnRefreshListener {
public class HistoryFragment extends BrowserFragment implements IRefreshable, SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {
public final static String TAG = "VLC/HistoryFragment";
private HistoryAdapter mHistoryAdapter;
private ListView mListView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private boolean mReady = true;
......@@ -61,19 +64,22 @@ public class HistoryFragment extends ListFragment implements IBrowser, IRefresha
private void focusHelper(boolean idIsEmpty) {
View parent = View.inflate(getActivity(), R.layout.history_list,
null);
mListView = (ListView) parent.findViewById(android.R.id.list);
mListView.setOnItemClickListener(this);
MainActivity main = (MainActivity)getActivity();
main.setMenuFocusDown(idIsEmpty, android.R.id.list);
main.setSearchAsFocusDown(idIsEmpty, parent,
android.R.id.list);
android.R.id.list);
}
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.history);
View v = inflater.inflate(R.layout.history_list, container, false);
setListAdapter(mHistoryAdapter);
mListView.setAdapter(mHistoryAdapter);
final ListView listView = (ListView)v.findViewById(android.R.id.list);
listView.setNextFocusUpId(R.id.ml_menu_search);
listView.setNextFocusLeftId(android.R.id.list);
......@@ -113,8 +119,8 @@ public class HistoryFragment extends ListFragment implements IBrowser, IRefresha
}
@Override
public void onListItemClick(ListView l, View v, int p, long id) {
playListIndex(p);
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
playListIndex(position);
}
private void playListIndex(int position) {
......
......@@ -39,7 +39,6 @@ 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.IBrowser;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.util.AndroidDevices;
......@@ -88,7 +87,7 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
public class MainActivity extends ActionBarActivity implements OnItemClickListener {
public final static String TAG = "VLC/MainActivity";
protected static final String ACTION_SHOW_PROGRESSBAR = "org.videolan.vlc.gui.ShowProgressBar";
......@@ -231,8 +230,8 @@ public class MainActivity extends ActionBarActivity {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder) instanceof IBrowser)
((IBrowser) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)).setReadyToDisplay(true);
if (getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder) instanceof BrowserFragment)
((BrowserFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)).setReadyToDisplay(true);
}
};
......@@ -241,60 +240,7 @@ public class MainActivity extends ActionBarActivity {
// set a custom shadow that overlays the main content when the drawer opens
mRootContainer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
SidebarAdapter.SidebarEntry entry = (SidebarEntry) mListView.getItemAtPosition(position);
Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
if(current == null || (entry != null && current.getTag().equals(entry.id))) { /* Already selected */
if (mFocusedPrior != 0)
findViewById(R.id.ml_menu_search).requestFocus();
mRootContainer.closeDrawer(mSideMenu);
return;
}
// This should not happen
if(entry == null || entry.id == null)
return;
if (entry.type == SidebarEntry.TYPE_FRAGMENT) {
/* Slide down the audio player */
slideDownAudioPlayer();
/* Switch the fragment */
Fragment fragment = getFragment(entry.id);
if (fragment instanceof IBrowser)
((IBrowser)fragment).setReadyToDisplay(false);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, fragment, entry.id);
ft.addToBackStack(mCurrentFragment);
ft.commit();
supportInvalidateOptionsMenu();
mCurrentFragment = entry.id;
mSidebarAdapter.setCurrentFragment(mCurrentFragment);
/*
* Set user visibility hints to work around weird Android
* behaviour of duplicate context menu events.
*/
current.setUserVisibleHint(false);
getFragment(mCurrentFragment).setUserVisibleHint(true);
// HACK ALERT: Set underlying audio browser to be invisible too.
if(current.getTag().equals("tracks"))
getFragment("audio").setUserVisibleHint(false);
if (mFocusedPrior != 0)
findViewById(R.id.ml_menu_search).requestFocus();
mRootContainer.closeDrawer(mSideMenu);
}else if (entry.attributeID == R.attr.ic_menu_preferences){
startActivityForResult(new Intent(mContext, PreferencesActivity.class), ACTIVITY_RESULT_PREFERENCES);
}
}
});
mListView.setOnItemClickListener(this);
/* Set up the audio player */
mAudioPlayer = new AudioPlayer();
......@@ -779,6 +725,7 @@ public class MainActivity extends ActionBarActivity {
}
// Note. onKeyDown will not occur while moving within a list
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
View v = getCurrentFocus();
......@@ -1034,4 +981,55 @@ public class MainActivity extends ActionBarActivity {
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SidebarAdapter.SidebarEntry entry = (SidebarEntry) mListView.getItemAtPosition(position);
Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
if(current == null || (entry != null && current.getTag().equals(entry.id))) { /* Already selected */
if (mFocusedPrior != 0)
findViewById(R.id.ml_menu_search).requestFocus();
mRootContainer.closeDrawer(mSideMenu);
return;
}
// This should not happen
if(entry == null || entry.id == null)
return;
if (entry.type == SidebarEntry.TYPE_FRAGMENT) {
/* Slide down the audio player */
slideDownAudioPlayer();
/* Switch the fragment */
Fragment fragment = getFragment(entry.id);
if (fragment instanceof BrowserFragment)
((BrowserFragment)fragment).setReadyToDisplay(false);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, fragment, entry.id);
ft.addToBackStack(mCurrentFragment);
ft.commit();
supportInvalidateOptionsMenu();
mCurrentFragment = entry.id;
mSidebarAdapter.setCurrentFragment(mCurrentFragment);
/*
* Set user visibility hints to work around weird Android
* behaviour of duplicate context menu events. TODO
*/
current.setUserVisibleHint(false);
getFragment(mCurrentFragment).setUserVisibleHint(true);
// HACK ALERT: Set underlying audio browser to be invisible too.
if(current.getTag().equals("tracks"))
getFragment("audio").setUserVisibleHint(false);
if (mFocusedPrior != 0)
findViewById(R.id.ml_menu_search).requestFocus();
mRootContainer.closeDrawer(mSideMenu);
}else if (entry.attributeID == R.attr.ic_menu_preferences){
startActivityForResult(new Intent(mContext, PreferencesActivity.class), ACTIVITY_RESULT_PREFERENCES);
}
}
}
......@@ -26,7 +26,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.ContextMenu;
......@@ -55,9 +54,9 @@ import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.BrowserFragment;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.interfaces.IBrowser;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCRunnable;
......@@ -72,7 +71,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, IBrowser {
public class AudioBrowserFragment extends BrowserFragment implements SwipeRefreshLayout.OnRefreshListener {
public final static String TAG = "VLC/AudioBrowserFragment";
private FlingViewGroup mFlingViewGroup;
......@@ -99,7 +98,6 @@ public class AudioBrowserFragment extends Fragment implements SwipeRefreshLayout
public final static int MODE_GENRE = 3;
public final static int MSG_LOADING = 0;
private volatile boolean mReadyToDisplay = true;
private volatile boolean mDisplaying = false;
/* All subclasses of Fragment must include a public empty constructor. */
......
......@@ -32,7 +32,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
......@@ -67,10 +66,11 @@ import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Thumbnailer;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.BrowserFragment;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.interfaces.IBrowser;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCRunnable;
......@@ -79,7 +79,7 @@ import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class VideoGridFragment extends Fragment implements IBrowser, ISortable, VideoBrowserInterface, SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {
public class VideoGridFragment extends BrowserFragment implements ISortable, IVideoBrowser, SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {
public final static String TAG = "VLC/VideoListFragment";
......
package org.videolan.vlc.gui.video;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.WeakHandler;
import android.os.Message;
public class VideoListHandler extends WeakHandler<VideoBrowserInterface> {
public class VideoListHandler extends WeakHandler<IVideoBrowser> {
public static final int UPDATE_ITEM = 0;
public static final int MEDIA_ITEMS_UPDATED = 100;
public VideoListHandler(VideoBrowserInterface owner) {
public VideoListHandler(IVideoBrowser owner) {
super(owner);
}
@Override
public void handleMessage(Message msg) {
VideoBrowserInterface owner = getOwner();
IVideoBrowser owner = getOwner();
if(owner == null) return;
switch (msg.what) {
......
/*****************************************************************************
* AudioBrowserListAdapter.java
*****************************************************************************
* Copyright © 2011-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 IBrowser {
void setReadyToDisplay(boolean ready);
void display();
}
......@@ -18,13 +18,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui.video;
package org.videolan.vlc.interfaces;
import java.util.concurrent.BrokenBarrierException;
import org.videolan.vlc.MediaWrapper;
public interface VideoBrowserInterface {
public interface IVideoBrowser {
public static final long HEADER_VIDEO = 0;
public static final long HEADER_MUSIC = 1;
public static final long HEADER_CATEGORIES = 2;
......
......@@ -38,7 +38,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Thumbnailer;
import org.videolan.vlc.gui.audio.MediaComparators;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoBrowserInterface;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.gui.video.VideoListHandler;
import org.videolan.vlc.util.Util;
......@@ -50,7 +50,7 @@ import java.util.Map;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class GridFragment extends VerticalGridFragment implements VideoBrowserInterface {
public class GridFragment extends VerticalGridFragment implements IVideoBrowser {
private static final String TAG = "VLC/GridFragment";
private static final int NUM_COLUMNS = 5;
......
......@@ -32,9 +32,8 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Thumbnailer;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoBrowserInterface;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.gui.video.VideoListHandler;
import org.videolan.vlc.util.Util;
import android.app.Activity;
import android.app.FragmentManager;
......@@ -58,7 +57,7 @@ import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
public class MainTvActivity extends Activity implements VideoBrowserInterface {
public class MainTvActivity extends Activity implements IVideoBrowser {
private static final int NUM_ITEMS_PREVIEW = 5;
......@@ -298,7 +297,7 @@ public class MainTvActivity extends Activity implements VideoBrowserInterface {
sThumbnailer.addJob(media);
}
if (sThumbnailer.getJobsCount() > 0)
sThumbnailer.start((VideoBrowserInterface) mContext);
sThumbnailer.start((IVideoBrowser) mContext);
}
}
}).start();
......
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