Commit 794bc610 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Handle inner folders

parent 75fb31d9
......@@ -28,7 +28,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -263,6 +262,7 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
mMediaDirsLocation.add(dir.getPath());
}
mCustomDirsLocation = Arrays.asList(CustomDirectories.getCustomDirectories());
mMediaDirsLocation.addAll(mCustomDirsLocation);
}
public void addAll(ArrayList<MediaWrapper> mediaList){
......
......@@ -28,12 +28,11 @@ import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CheckBox;
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 {
......@@ -67,25 +66,23 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
vh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaWrapper mw = new MediaWrapper(((Storage)getItem(vh.getAdapterPosition())).getPath());
MediaWrapper mw = new MediaWrapper(((Storage) getItem(vh.getAdapterPosition())).getPath());
mw.setType(MediaWrapper.TYPE_DIR);
fragment.browse(mw, holder.getAdapterPosition());
((StorageBrowserFragment) fragment).browse(mw, holder.getAdapterPosition(), vh.checkBox.isChecked());
}
});
vh.checkBox.setChecked(mMediaDirsLocation == null || mMediaDirsLocation.isEmpty() ||
mMediaDirsLocation.contains(storage.getPath()));
vh.checkBox.setEnabled(true);
vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
vh.checkBox.setEnabled(!((StorageBrowserFragment) fragment).mScannedDirectory);
vh.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
public void onClick(View v) {
boolean isChecked = ((CheckBox)v).isChecked();
String path = ((Storage)getItem(vh.getAdapterPosition())).getPath();
updateMediaDirs();
if (isChecked)
addDir(path);
else
mDbManager.removeDir(path);
updateMediaDirs();
fragment.updateLib();
removeDir(path);
}
});
if (hasContextMenu) {
......@@ -113,6 +110,12 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
addItem(storage, notify, top);
}
private void removeDir(String path) {
mDbManager.removeDir(path);
updateMediaDirs();
fragment.updateLib();
}
private void addDir(final String path) {
new Thread(new Runnable() {
@Override
......@@ -123,7 +126,20 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
mDbManager.removeDir(parentPath);
parentPath = Strings.getParent(parentPath);
}
refreshFragment();
updateMediaDirs();
fragment.updateLib();
}
}).start();
}
void refreshFragment(){
fragment.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (mMediaDirsLocation == null || mMediaDirsLocation.isEmpty())
fragment.refresh();
}
});
}
}
......@@ -23,15 +23,24 @@
package org.videolan.vlc.gui.browser;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import org.videolan.libvlc.Media;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import java.util.ArrayList;
public class StorageBrowserFragment extends FileBrowserFragment {
public static final String KEY_IN_MEDIALIB = "key_in_medialib";
boolean mScannedDirectory = false;
public StorageBrowserFragment(){
mHandler = new BrowserFragmentHandler(this);
mAdapter = new StorageBrowserAdapter(this);
......@@ -43,6 +52,22 @@ public class StorageBrowserFragment extends FileBrowserFragment {
return new StorageBrowserFragment();
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if (bundle == null)
bundle = getArguments();
if (bundle != null){
mScannedDirectory = bundle.getBoolean(KEY_IN_MEDIALIB);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory);
}
@Override
protected void browseRoot() {
String storages[] = AndroidDevices.getMediaDirectories();
......@@ -82,4 +107,16 @@ public class StorageBrowserFragment extends FileBrowserFragment {
}
mAdapter.notifyDataSetChanged();
}
public void browse (MediaWrapper media, int position, boolean scanned){
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
Fragment next = createFragment();
Bundle args = new Bundle();
args.putParcelable(KEY_MEDIA, media);
args.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory || scanned);
next.setArguments(args);
ft.replace(R.id.fragment_placeholder, next, media.getLocation());
ft.addToBackStack(mMrl);
ft.commit();
}
}
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