Commit 1ed5df99 authored by Geoffrey Métais's avatar Geoffrey Métais

Extract MediaBrowser from SortedBrowserFragment

parent 11489a04
......@@ -36,7 +36,7 @@ import org.videolan.vlc.util.AndroidDevices;
import java.io.File;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class DirectoryBrowserFragment extends SortedBrowserFragment{
public class DirectoryBrowserFragment extends MediaSortedFragment{
public static final String TAG = "VLC/NetworkBrowserFragment";
......
/*
* ************************************************************************
* MediaSortedFragment.java
* *************************************************************************
* Copyright © 2016 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* 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.tv.browser;
import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.MediaBrowser;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.util.VLCInstance;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public abstract class MediaSortedFragment extends SortedBrowserFragment implements MediaBrowser.EventListener {
protected Uri mUri;
protected MediaBrowser mMediaBrowser;
abstract protected void browseRoot();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null){
mUri = savedInstanceState.getParcelable(KEY_URI);
} else {
Intent intent = getActivity().getIntent();
if (intent != null)
mUri = intent.getData();
}
}
protected void browse() {
mMediaBrowser = new MediaBrowser(VLCInstance.get(), this);
if (mMediaBrowser != null) {
if (mUri != null)
mMediaBrowser.browse(mUri, true);
else
browseRoot();
((BrowserActivityInterface)getActivity()).showProgress(true);
}
}
public void onPause(){
super.onPause();
if (mMediaBrowser != null) {
mMediaBrowser.release();
mMediaBrowser = null;
}
((BrowserActivityInterface)getActivity()).updateEmptyView(false);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mUri != null)
outState.putParcelable(KEY_URI, mUri);
}
public void onMediaAdded(int index, Media media) {
addMedia(media);
if (mUri == null) { // we are at root level
sort();
}
((BrowserActivityInterface)getActivity()).updateEmptyView(false);
((BrowserActivityInterface)getActivity()).showProgress(false);
}
public void onMediaRemoved(int index, Media media) {}
public void onBrowseEnd() {
sort();
mHandler.sendEmptyMessage(HIDE_LOADING);
}
}
......@@ -31,7 +31,7 @@ import org.videolan.vlc.media.MediaWrapper;
import org.videolan.vlc.util.Util;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class NetworkBrowserFragment extends SortedBrowserFragment {
public class NetworkBrowserFragment extends MediaSortedFragment {
public static final String TAG = "VLC/NetworkBrowserFragment";
......
......@@ -25,7 +25,6 @@ package org.videolan.vlc.gui.tv.browser;
import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
......@@ -43,7 +42,6 @@ import android.support.v4.util.ArrayMap;
import android.support.v4.util.SimpleArrayMap;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.MediaBrowser;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.MediaComparators;
......@@ -56,7 +54,6 @@ import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.media.MediaWrapper;
import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.WeakHandler;
import java.util.ArrayList;
......@@ -65,7 +62,7 @@ import java.util.Map;
import java.util.TreeMap;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public abstract class SortedBrowserFragment extends BrowseFragment implements BrowserFragmentInterface, OnItemViewSelectedListener, OnItemViewClickedListener, IVideoBrowser, MediaBrowser.EventListener {
public abstract class SortedBrowserFragment extends BrowseFragment implements BrowserFragmentInterface, OnItemViewSelectedListener, OnItemViewClickedListener, IVideoBrowser {
public static final String TAG = "VLC/SortedBrowserFragment";
......@@ -75,8 +72,6 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
public static final int UPDATE_ITEM = 2;
public static final int HIDE_LOADING = 3;
protected Uri mUri;
protected MediaBrowser mMediaBrowser;
protected ArrayObjectAdapter mAdapter = new ArrayObjectAdapter(new ListRowPresenter());
protected MediaWrapper mItemSelected;
......@@ -84,18 +79,13 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
SimpleArrayMap<String, Integer> mMediaIndex = new SimpleArrayMap<>();
protected BrowserHandler mHandler = new BrowserHandler(this);
abstract protected void browseRoot();
abstract protected void browse();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null){
mUri = savedInstanceState.getParcelable(KEY_URI);
mItemSelected = savedInstanceState.getParcelable(SELECTED_ITEM);
} else {
Intent intent = getActivity().getIntent();
if (intent != null)
mUri = intent.getData();
}
setOnItemViewClickedListener(this);
setOnItemViewSelectedListener(this);
......@@ -106,13 +96,6 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
setBrandColor(getResources().getColor(R.color.orange800));
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHeadersState(HEADERS_HIDDEN);
}
public void onResume() {
super.onResume();
if (mAdapter.size() == 0) {
......@@ -120,13 +103,10 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
}
}
public void onPause(){
super.onPause();
if (mMediaBrowser != null) {
mMediaBrowser.release();
mMediaBrowser = null;
}
((BrowserActivityInterface)getActivity()).updateEmptyView(false);
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHeadersState(HEADERS_HIDDEN);
}
......@@ -135,19 +115,6 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
super.onSaveInstanceState(outState);
if (mItemSelected != null)
outState.putParcelable(SELECTED_ITEM, mItemSelected);
if (mUri != null)
outState.putParcelable(KEY_URI, mUri);
}
protected void browse() {
mMediaBrowser = new MediaBrowser(VLCInstance.get(), this);
if (mMediaBrowser != null) {
if (mUri != null)
mMediaBrowser.browse(mUri, true);
else
browseRoot();
((BrowserActivityInterface)getActivity()).showProgress(true);
}
}
public void showDetails() {
......@@ -161,23 +128,6 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
startActivity(intent);
}
public void onMediaAdded(int index, Media media) {
addMedia(media);
if (mUri == null) { // we are at root level
sort();
}
((BrowserActivityInterface)getActivity()).updateEmptyView(false);
((BrowserActivityInterface)getActivity()).showProgress(false);
}
public void onMediaRemoved(int index, Media media) {}
public void onBrowseEnd() {
sort();
mHandler.sendEmptyMessage(HIDE_LOADING);
}
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
mItemSelected = (MediaWrapper)item;
......@@ -199,6 +149,7 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
return MainTvActivity.HEADER_DIRECTORIES;
return -1;
}
@Override
public void refresh() {
mMediaItemMap.clear();
......@@ -285,10 +236,10 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
public String Letter;
public ArrayList<MediaWrapper> mediaList;
public ListItem(String letter, MediaWrapper MediaWrapper) {
public ListItem(String letter, MediaWrapper mediaWrapper) {
mediaList = new ArrayList<>();
if (MediaWrapper != null)
mediaList.add(MediaWrapper);
if (mediaWrapper != null)
mediaList.add(mediaWrapper);
Letter = letter;
}
}
......
......@@ -63,30 +63,13 @@ public class VideoBrowserFragment extends SortedBrowserFragment {
sThumbnailer.setVideoBrowser(null);
}
@Override
public void refresh() {
mMediaIndex.clear();
super.refresh();
}
@Override
protected void browseRoot() {
browse();
}
@Override
protected void browse() {
mVideos = MediaLibrary.getInstance().getVideoItems();
MediaWrapper media;
for (int i = 0 ; i < mVideos.size() ; ++i) {
media = mVideos.get(i);
String letter = media.getTitle().substring(0, 1).toUpperCase();
if (mMediaItemMap.containsKey(letter)){
mMediaItemMap.get(letter).mediaList.add(media);
} else {
ListItem item = new ListItem(letter, media);
mMediaItemMap.put(letter, item);
}
addMedia(media);
mMediaIndex.put(media.getLocation(), Integer.valueOf(i));
}
sort();
......
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