Commit 23e94289 authored by Geoffrey Métais's avatar Geoffrey Métais

Fix browsing to root in subtitles picker

Close #420
parent 5ad3cd8d
......@@ -28,6 +28,7 @@ import android.content.DialogInterface;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatEditText;
import android.text.InputType;
......@@ -85,30 +86,42 @@ public class FileBrowserFragment extends BaseBrowserFragment {
@Override
protected void browseRoot() {
mMrl = null;
final FragmentActivity activity = getActivity();
if (activity == null) return;
activity.setTitle(R.string.directories);
final String internalmemoryTitle = getString(R.string.internal_memory);
final String browserStorage = getString(R.string.browser_storages);
final String quickAccess = getString(R.string.browser_quick_access);
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
final String storages[] = AndroidDevices.getMediaDirectories();
MediaWrapper directory;
final ArrayList<MediaLibraryItem> devices = new ArrayList<>(storages.length);
devices.add(new DummyItem(getString(R.string.browser_storages)));
final boolean isFilePicker = FileBrowserFragment.this instanceof FilePickerFragment;
if (!isFilePicker) {
devices.add(new DummyItem(browserStorage));
}
for (String mediaDirLocation : storages) {
if (!(new File(mediaDirLocation).exists()))
continue;
directory = new MediaWrapper(AndroidUtil.PathToUri(mediaDirLocation));
directory.setType(MediaWrapper.TYPE_DIR);
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
directory.setDisplayTitle(VLCApplication.getAppResources().getString(R.string.internal_memory));
directory.setDisplayTitle(internalmemoryTitle);
devices.add(directory);
}
// Set folders shortcuts
devices.add(new DummyItem(getString(R.string.browser_quick_access)));
if (!isFilePicker) {
devices.add(new DummyItem(quickAccess));
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_FILE.exists()) {
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)) {
if (!isFilePicker) {
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_FILE.exists()) {
final MediaWrapper music = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI);
music.setType(MediaWrapper.TYPE_DIR);
......
......@@ -37,14 +37,14 @@ public class FilePickerActivity extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_picker_activity);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, new FilePickerFragment(), "picker");
ft.commit();
}
@Override
public void onBackPressed() {
FilePickerFragment fpf = ((FilePickerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder));
final FilePickerFragment fpf = ((FilePickerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder));
if (fpf.isRootDirectory())
finish();
else if (getSupportFragmentManager().getBackStackEntryCount() > 0)
......@@ -55,6 +55,5 @@ public class FilePickerActivity extends AppCompatActivity {
public void onHomeClick(View v) {
((FilePickerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)).browseRoot();
setTitle(R.string.directories);
}
}
......@@ -110,7 +110,7 @@ public class FilePickerFragment extends FileBrowserFragment {
mRoot = true;
mAdapter.clear();
browseRoot();
} else {
} else if (mMrl != null) {
MediaWrapper mw = new MediaWrapper(Uri.parse(FileUtils.getParent(mMrl)));
browse(mw, 0, false);
}
......
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