Commit a232e385 authored by Geoffrey Métais's avatar Geoffrey Métais

Quick access for main media folders in browser

parent 0f6e8709
......@@ -567,4 +567,5 @@
<string name="settings_ml_block_scan">Medialibrary is scanning your devices right now</string>
<string name="recommendations">Recommendations</string>
<string name="recommendations_desc">Recommendations cards on launcher</string>
<string name="browser_quick_access">Quick Access</string>
</resources>
......@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.browser;
import android.databinding.ViewDataBinding;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.support.annotation.MainThread;
import android.text.TextUtils;
import android.view.LayoutInflater;
......@@ -43,6 +44,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.BrowserItemBinding;
import org.videolan.vlc.databinding.BrowserItemSeparatorBinding;
import org.videolan.vlc.gui.helpers.SelectorViewHolder;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.MediaItemFilter;
import org.videolan.vlc.util.Util;
......@@ -69,9 +71,13 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
protected final BaseBrowserFragment fragment;
private int mTop = 0, mMediaCount = 0, mSelectionCount = 0;
private ItemFilter mFilter = new ItemFilter();
private final boolean mFilesRoot, mNetworkRoot;
BaseBrowserAdapter(BaseBrowserFragment fragment){
BaseBrowserAdapter(BaseBrowserFragment fragment) {
this.fragment = fragment;
final boolean root = fragment.isRootDirectory();
mFilesRoot = root && fragment instanceof FileBrowserFragment;
mNetworkRoot = root && fragment instanceof NetworkBrowserFragment;
}
@Override
......@@ -109,9 +115,9 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
final MediaWrapper media = (MediaWrapper) getItem(position);
vh.binding.setItem(media);
vh.binding.setHasContextMenu(true);
if (fragment instanceof NetworkBrowserFragment && fragment.isRootDirectory())
if (mNetworkRoot)
vh.binding.setProtocol(getProtocol(media));
vh.binding.setCover(getIcon(media));
vh.binding.setCover(getIcon(media, mFilesRoot));
vh.setContextMenuListener();
vh.selectView(media.hasStateFlags(FLAG_SELECTED));
}
......@@ -192,7 +198,7 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
public boolean onLongClick(View v) {
int position = getLayoutPosition();
return position < mDataset.size() && position >= 0
&& fragment.onLongClick(v, position, mDataset.get(position));
&& fragment.onLongClick(v, position, mDataset.get(position));
}
@Override
......@@ -289,11 +295,19 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
return mMediaCount;
}
BitmapDrawable getIcon(MediaWrapper media) {
BitmapDrawable getIcon(MediaWrapper media, boolean specialFolders) {
switch (media.getType()){
case MediaWrapper.TYPE_AUDIO:
return IMAGE_AUDIO;
case MediaWrapper.TYPE_DIR:
if (specialFolders) {
final Uri uri = media.getUri();
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI.equals(uri))
return IMAGE_VIDEO;
else if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI.equals(uri)
|| AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI.equals(uri))
return IMAGE_AUDIO;
}
return IMAGE_FOLDER;
case MediaWrapper.TYPE_VIDEO:
return IMAGE_VIDEO;
......@@ -304,8 +318,6 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
}
}
String getProtocol(MediaWrapper media) {
if (!fragment.isRootDirectory() || !(fragment instanceof NetworkBrowserFragment))
return null;
if (media.getType() != MediaWrapper.TYPE_DIR)
return null;
return media.getUri().getScheme();
......
......@@ -126,7 +126,6 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
public BaseBrowserFragment() {
mHandler = new BrowserFragmentHandler(this);
mAdapter = new BaseBrowserAdapter(this);
if (mBrowserHandler == null) {
HandlerThread handlerThread = new HandlerThread("vlc-browser", Process.THREAD_PRIORITY_DEFAULT+Process.THREAD_PRIORITY_LESS_FAVORABLE);
handlerThread.start();
......@@ -188,6 +187,7 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new BaseBrowserAdapter(this);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
......
......@@ -25,6 +25,8 @@ package org.videolan.vlc.gui.browser;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatEditText;
......@@ -33,6 +35,7 @@ import android.text.TextUtils;
import android.view.MenuItem;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.media.DummyItem;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.media.Storage;
......@@ -85,7 +88,7 @@ public class FileBrowserFragment extends BaseBrowserFragment {
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
String storages[] = AndroidDevices.getMediaDirectories();
final String storages[] = AndroidDevices.getMediaDirectories();
MediaWrapper directory;
final ArrayList<MediaLibraryItem> devices = new ArrayList<>(storages.length);
for (String mediaDirLocation : storages) {
......@@ -97,14 +100,25 @@ public class FileBrowserFragment extends BaseBrowserFragment {
directory.setDisplayTitle(VLCApplication.getAppResources().getString(R.string.internal_memory));
devices.add(directory);
}
// Set folders shortcuts
devices.add(new DummyItem(getString(R.string.browser_quick_access)));
final MediaWrapper movies = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI);
movies.setType(MediaWrapper.TYPE_DIR);
devices.add(movies);
if (!(FileBrowserFragment.this instanceof FilePickerFragment)) {
final MediaWrapper music = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI);
music.setType(MediaWrapper.TYPE_DIR);
devices.add(music);
final MediaWrapper podcasts = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI);
podcasts.setType(MediaWrapper.TYPE_DIR);
devices.add(podcasts);
}
VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
mAdapter.update(devices);
}
});
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
mRoot = true;
}
});
}
......
......@@ -48,7 +48,7 @@ public class FilePickerAdapter extends BaseBrowserAdapter {
vh.binding.setItem(media);
vh.binding.setHasContextMenu(false);
vh.binding.setProtocol(null);
vh.binding.setCover(getIcon(media));
vh.binding.setCover(getIcon(media, false));
}
}
......
......@@ -24,9 +24,11 @@ import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.InputDevice;
......@@ -53,7 +55,6 @@ import java.util.StringTokenizer;
public class AndroidDevices {
public final static String TAG = "VLC/UiTools/AndroidDevices";
public final static String EXTERNAL_PUBLIC_DIRECTORY = Environment.getExternalStorageDirectory().getPath();
public final static boolean isPhone;
public final static boolean hasCombBar;
public final static boolean hasNavBar;
......@@ -218,4 +219,19 @@ public class AndroidDevices {
} catch (PackageManager.NameNotFoundException ignored) {}
return false;
}
public static class MediaFolders {
public final static Uri EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI = getFolderUri(Environment.DIRECTORY_MOVIES);
public final static Uri EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI = getFolderUri(Environment.DIRECTORY_MUSIC);
public final static Uri EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI = getFolderUri(Environment.DIRECTORY_PODCASTS);
@NonNull
private static Uri getFolderUri(String type) {
try {
return Uri.parse("file://"+ Environment.getExternalStoragePublicDirectory(type).getCanonicalPath());
} catch (IOException ignored) {
return Uri.parse("file://"+Environment.getExternalStoragePublicDirectory(type).getPath());
}
}
}
}
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