Skip to content
Permalink
Browse files

Merge pull request #7791 from JosJuice/android-show-files

Android: Show files in the directory picker
  • Loading branch information...
JosJuice committed Feb 16, 2019
2 parents b5c3881 + c520a03 commit 286aafd4ed2949f0b93230fee969c6a32fe75f07
@@ -4,20 +4,23 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.dolphinemu.dolphinemu.R;

import com.nononsenseapps.filepicker.FilePickerFragment;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class CustomFilePickerFragment extends FilePickerFragment
{
private static final Set<String> extensions = new HashSet<>(Arrays.asList(
"gcm", "tgc", "iso", "ciso", "gcz", "wbfs", "wad", "dol", "elf"));

@NonNull
@Override
public Uri toUri(@NonNull final File file)
@@ -41,4 +44,33 @@ public Uri toUri(@NonNull final File file)
cancel.setVisibility(View.GONE);
}
}

@Override
protected boolean isItemVisible(@NonNull final File file)
{
// Some users jump to the conclusion that Dolphin isn't able to detect their
// files if the files don't show up in the file picker when mode == MODE_DIR.
// To avoid this, show files even when the user needs to select a directory.

return (showHiddenItems || !file.isHidden()) &&
(file.isDirectory() ||
extensions.contains(fileExtension(file.getName()).toLowerCase()));
}

@Override
public boolean isCheckable(@NonNull final File file)
{
// We need to make a small correction to the isCheckable logic due to
// overriding isItemVisible to show files when mode == MODE_DIR.
// AbstractFilePickerFragment always treats files as checkable when
// allowExistingFile == true, but we don't want files to be checkable when mode == MODE_DIR.

return super.isCheckable(file) && !(mode == MODE_DIR && file.isFile());
}

private static String fileExtension(@NonNull String filename)
{
int i = filename.lastIndexOf('.');
return i < 0 ? "" : filename.substring(i + 1);
}
}

0 comments on commit 286aafd

Please sign in to comment.
You can’t perform that action at this time.