Commit 75fb31d9 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Storage selection back in settings

parent 7ba51519
......@@ -2,6 +2,10 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/general_prefs_category" >
<PreferenceScreen
android:key="directories"
android:summary="@string/directories_summary"
android:title="@string/directories" />
<ListPreference
android:defaultValue="-1"
......
......@@ -65,9 +65,9 @@ import org.videolan.vlc.audio.AudioService;
import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.browser.BaseBrowserFragment;
import org.videolan.vlc.gui.browser.FileBrowserFragment;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
import org.videolan.vlc.gui.browser.NetworkBrowserFragment;
import org.videolan.vlc.gui.browser.StorageBrowserFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import org.videolan.vlc.gui.video.VideoListAdapter;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
......@@ -458,7 +458,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
boolean showLast = current instanceof AudioBrowserFragment || (current instanceof VideoGridFragment && mSettings.getString(PreferencesActivity.VIDEO_LAST, null) != null);
menu.findItem(R.id.ml_menu_last_playlist).setVisible(showLast);
if (current instanceof FileBrowserFragment && ((FileBrowserFragment) current).isRootDirectory())
if (current instanceof StorageBrowserFragment && ((StorageBrowserFragment) current).isRootDirectory())
menu.findItem(R.id.ml_menu_add_dir).setVisible(true);
else
menu.findItem(R.id.ml_menu_add_dir).setVisible(false);
......@@ -534,8 +534,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
item.setIcon(R.drawable.ic_menu_bookmark_w);
break;
case R.id.ml_menu_add_dir:
if (current != null && current instanceof FileBrowserFragment)
((FileBrowserFragment) current).showAddDirectoryDialog();
if (current != null && current instanceof StorageBrowserFragment)
((StorageBrowserFragment) current).showAddDirectoryDialog();
break;
}
mDrawerLayout.closeDrawer(mListView);
......
......@@ -92,6 +92,20 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
findPreference("ui_category").setEnabled(false);
}
// Directories
Preference directoriesPref = findPreference("directories");
directoriesPref.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(getApplicationContext(), SecondaryActivity.class);
intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER);
startActivity(intent);
// setResult(RESULT_RESCAN);
return true;
}
});
// Screen orientation
ListPreference screenOrientationPref = (ListPreference) findPreference("screen_orientation");
screenOrientationPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
......
......@@ -34,6 +34,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.gui.audio.AudioAlbumFragment;
import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment;
import org.videolan.vlc.gui.audio.EqualizerFragment;
import org.videolan.vlc.gui.browser.StorageBrowserFragment;
import org.videolan.vlc.gui.video.MediaInfoFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import org.videolan.vlc.gui.video.VideoListAdapter;
......@@ -50,6 +51,7 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
public static final String ABOUT = "about";
public static final String MEDIA_INFO = "mediaInfo";
public static final String VIDEO_GROUP_LIST = "videoGroupList";
public static final String STORAGE_BROWSER = "storage_browser";
Fragment mFragment;
......@@ -136,9 +138,10 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
((MediaInfoFragment)mFragment).setMediaLocation(getIntent().getStringExtra("param"));
} else if(id.equals(VIDEO_GROUP_LIST)) {
mFragment = new VideoGridFragment();
((VideoGridFragment)mFragment).setGroup(getIntent().getStringExtra("param"));
}
else {
((VideoGridFragment) mFragment).setGroup(getIntent().getStringExtra("param"));
} else if (id.equals(STORAGE_BROWSER)){
mFragment = new StorageBrowserFragment();
} else {
throw new IllegalArgumentException("Wrong fragment id.");
}
}
......
......@@ -37,7 +37,6 @@ import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.audio.MediaComparators;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.CustomDirectories;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
......@@ -50,7 +49,7 @@ import java.util.LinkedList;
import java.util.List;
public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "VLC/BaseBrowserAdapter";
protected static final String TAG = "VLC/BaseBrowserAdapter";
private static final int TYPE_MEDIA = 0;
private static final int TYPE_SEPARATOR = 1;
......@@ -72,7 +71,7 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder vh;
View v;
if (viewType == TYPE_MEDIA || viewType == TYPE_STORAGE) {
if (viewType == TYPE_MEDIA) {
v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.directory_view_item, parent, false);
vh = new MediaViewHolder(v);
......@@ -89,8 +88,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
int viewType = getItemViewType(position);
if (viewType == TYPE_MEDIA) {
onBindMediaViewHolder(holder, position);
} else if (viewType == TYPE_STORAGE) {
onBindStorageViewHolder(holder, position);
} else {
SeparatorViewHolder vh = (SeparatorViewHolder) holder;
vh.title.setText(getItem(position).toString());
......@@ -154,85 +151,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
}
private void onBindStorageViewHolder(final RecyclerView.ViewHolder holder, int position) {
final MediaViewHolder vh = (MediaViewHolder) holder;
final Storage storage = (Storage) getItem(position);
boolean isPublicStorage = TextUtils.equals(storage.getPath(), AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
boolean hasContextMenu = !isPublicStorage && mCustomDirsLocation.contains(storage.getPath());
vh.title.setText(isPublicStorage ? holder.itemView.getContext().getString(R.string.internal_memory) : storage.getName());
vh.icon.setVisibility(View.GONE);
vh.checkBox.setVisibility(View.VISIBLE);
vh.more.setVisibility(hasContextMenu ? View.VISIBLE : View.GONE);
String description = storage.getDescription();
if (!TextUtils.isEmpty(description)) {
vh.text.setVisibility(View.VISIBLE);
vh.text.setText(description);
} else
vh.text.setVisibility(View.INVISIBLE);
vh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaWrapper mw = new MediaWrapper(((Storage)getItem(vh.getAdapterPosition())).getPath());
mw.setType(MediaWrapper.TYPE_DIR);
fragment.browse(mw, holder.getAdapterPosition());
}
});
vh.checkBox.setChecked(mMediaDirsLocation == null || mMediaDirsLocation.isEmpty() ||
mMediaDirsLocation.contains(storage.getPath()));
vh.checkBox.setEnabled(true);
vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
String path = ((Storage)getItem(vh.getAdapterPosition())).getPath();
updateMediaDirs();
if (isChecked) {
addDir(path);
} else {
if (mMediaDirsLocation == null || mMediaDirsLocation.isEmpty()){
String storagePath;
for (Object storage : mMediaList){
storagePath = ((Storage)storage).getPath();
if (!TextUtils.equals(storagePath, path))
mDbManager.addDir(storagePath);
}
} else
mDbManager.removeDir(path);
}
fragment.updateLib();
}
});
if (hasContextMenu) {
vh.more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fragment.onPopupMenu(vh.more, holder.getAdapterPosition());
}
});
vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
fragment.mRecyclerView.openContextMenu(holder.getAdapterPosition());
return true;
}
});
}
}
private void addDir(final String path) {
new Thread(new Runnable() {
@Override
public void run() {
mDbManager.addDir(path);
File tmpFile = new File(path).getParentFile();
while (tmpFile != null && !tmpFile.getPath().equals("/")) {
mDbManager.removeDir(tmpFile.getPath());
tmpFile = tmpFile.getParentFile();
}
}
}).start();
}
@Override
public int getItemCount() {
return mMediaList.size();
......@@ -278,6 +196,10 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return name;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
......
......@@ -34,7 +34,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.ContextMenu;
import android.view.LayoutInflater;
......@@ -199,7 +198,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
ft.commit();
}
@Override
public void onMediaAdded(int index, Media media) {
mAdapter.addItem(media, mReadyToDisplay && mRoot, mRoot);
......
......@@ -42,6 +42,7 @@ import android.widget.Toast;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.CustomDirectories;
......@@ -93,10 +94,13 @@ public class FileBrowserFragment extends BaseBrowserFragment {
protected void browseRoot() {
mAdapter.updateMediaDirs();
String storages[] = AndroidDevices.getMediaDirectories();
BaseBrowserAdapter.Storage storage;
MediaWrapper directory;
for (String mediaDirLocation : storages) {
storage = new BaseBrowserAdapter.Storage(mediaDirLocation);
mAdapter.addItem(storage, false, false);
directory = new MediaWrapper(mediaDirLocation);
directory.setType(MediaWrapper.TYPE_DIR);
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
directory.setTitle(getString(R.string.internal_memory));
mAdapter.addItem(directory, false, false);
}
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
if (mReadyToDisplay) {
......
/*
* *************************************************************************
* StorageBrowserAdapter.java
* **************************************************************************
* Copyright © 2015 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.browser;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import org.videolan.libvlc.Media;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Strings;
public class StorageBrowserAdapter extends BaseBrowserAdapter {
public StorageBrowserAdapter(BaseBrowserFragment fragment) {
super(fragment);
updateMediaDirs();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder vh;
View v;
v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.directory_view_item, parent, false);
vh = new MediaViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
final MediaViewHolder vh = (MediaViewHolder) holder;
final Storage storage = (Storage) getItem(position);
boolean hasContextMenu = mCustomDirsLocation.contains(storage.getPath());
vh.title.setText(storage.getName());
vh.icon.setVisibility(View.GONE);
vh.checkBox.setVisibility(View.VISIBLE);
vh.more.setVisibility(hasContextMenu ? View.VISIBLE : View.GONE);
vh.text.setVisibility(View.GONE);
vh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaWrapper mw = new MediaWrapper(((Storage)getItem(vh.getAdapterPosition())).getPath());
mw.setType(MediaWrapper.TYPE_DIR);
fragment.browse(mw, holder.getAdapterPosition());
}
});
vh.checkBox.setChecked(mMediaDirsLocation == null || mMediaDirsLocation.isEmpty() ||
mMediaDirsLocation.contains(storage.getPath()));
vh.checkBox.setEnabled(true);
vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
String path = ((Storage)getItem(vh.getAdapterPosition())).getPath();
updateMediaDirs();
if (isChecked)
addDir(path);
else
mDbManager.removeDir(path);
updateMediaDirs();
fragment.updateLib();
}
});
if (hasContextMenu) {
vh.more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fragment.onPopupMenu(vh.more, holder.getAdapterPosition());
}
});
vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
fragment.mRecyclerView.openContextMenu(holder.getAdapterPosition());
return true;
}
});
}
}
public void addItem(Media media, boolean notify, boolean top){
String path = media.getMrl();
if (path.startsWith("file://"))
path = path.substring(7);
Storage storage = new Storage(path);
addItem(storage, notify, top);
}
private void addDir(final String path) {
new Thread(new Runnable() {
@Override
public void run() {
mDbManager.addDir(path);
String parentPath = Strings.getParent(path);
while (parentPath != null && !TextUtils.equals(parentPath, "/")) {
mDbManager.removeDir(parentPath);
parentPath = Strings.getParent(parentPath);
}
}
}).start();
}
}
/*
* *************************************************************************
* StorageBrowserFragment.java
* **************************************************************************
* Copyright © 2015 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.browser;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import org.videolan.libvlc.Media;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
public class StorageBrowserFragment extends FileBrowserFragment {
public StorageBrowserFragment(){
mHandler = new BrowserFragmentHandler(this);
mAdapter = new StorageBrowserAdapter(this);
ROOT = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY;
}
@Override
protected Fragment createFragment() {
return new StorageBrowserFragment();
}
@Override
protected void browseRoot() {
String storages[] = AndroidDevices.getMediaDirectories();
BaseBrowserAdapter.Storage storage;
for (String mediaDirLocation : storages) {
storage = new BaseBrowserAdapter.Storage(mediaDirLocation);
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
storage.setName(getString(R.string.internal_memory));
mAdapter.addItem(storage, false, false);
}
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
if (mReadyToDisplay) {
updateEmptyView();
mAdapter.notifyDataSetChanged();
}
}
@Override
protected void update() {
mAdapter.updateMediaDirs();
super.update();
}
@Override
public void onMediaAdded(int index, Media media) {
if (media.getType() != Media.Type.Directory)
return;
super.onMediaAdded(index, media);
}
protected void updateDisplay() {
if (!mAdapter.isEmpty()) {
if (mSavedPosition > 0) {
mLayoutManager.scrollToPositionWithOffset(mSavedPosition, 0);
mSavedPosition = 0;
}
}
mAdapter.notifyDataSetChanged();
}
}
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