filter files and folders by a file extension
This commit is contained in:
parent
e4167c3aab
commit
5404a689ff
|
|
@ -11,8 +11,6 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.3'
|
||||
classpath 'com.novoda:bintray-release:0.3.4'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ apply plugin: 'com.android.library'
|
|||
*/
|
||||
|
||||
// must be applied after your artifact generating plugin (eg. java / com.android.library)
|
||||
apply plugin: 'bintray-release'
|
||||
//apply plugin: 'bintray-release'
|
||||
|
||||
// query git for the the SHA, Tag and commit count. Use these to automate versioning.
|
||||
def gitTag = 'git describe --tags'.execute([], project.rootDir).text.trim()
|
||||
|
|
@ -34,14 +34,4 @@ dependencies {
|
|||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
publish {
|
||||
groupId = 'com.nononsenseapps'
|
||||
artifactId = 'filepicker'
|
||||
publishVersion = gitTag
|
||||
description = 'An extendable Android file/directory-picker you can include in your app'
|
||||
website = 'https://github.com/spacecowboy/NoNonsense-FilePicker'
|
||||
licences = ['MPL-2.0']
|
||||
uploadName = 'com.nononsenseapps:filepicker'
|
||||
bintrayUser = project.hasProperty("BINTRAY_USER")? BINTRAY_USER: "Dummy"
|
||||
bintrayKey = project.hasProperty("BINTRAY_KEY") ? BINTRAY_KEY: "Dummy"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import java.io.File;
|
|||
*/
|
||||
public class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
||||
|
||||
private static final String[] extensions = new String[]{".doc", ".docx", ".xlsx", ".xls", ".png", ".jpg", ".tif", ".pdf", ".jpeg"};
|
||||
|
||||
protected static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
protected boolean showHiddenItems = false;
|
||||
private File mRequestedPath = null;
|
||||
|
|
@ -38,7 +40,7 @@ public class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
|||
*
|
||||
* @param showHiddenItems whether hidden items should be shown or not
|
||||
*/
|
||||
public void showHiddenItems(boolean showHiddenItems){
|
||||
public void showHiddenItems(boolean showHiddenItems) {
|
||||
this.showHiddenItems = showHiddenItems;
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +50,7 @@ public class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
|||
* @return true if hidden items are shown, otherwise false
|
||||
*/
|
||||
|
||||
public boolean areHiddenItemsShown(){
|
||||
public boolean areHiddenItemsShown() {
|
||||
return showHiddenItems;
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +239,9 @@ public class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
|||
if (listFiles != null) {
|
||||
for (java.io.File f : listFiles) {
|
||||
if (isItemVisible(f)) {
|
||||
files.add(f);
|
||||
if ((f.isFile() && isNeededExtension(f.toString())) || (f.isDirectory() && directoryHasNeededFiles(f))) {
|
||||
files.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -292,6 +296,39 @@ public class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
|||
};
|
||||
}
|
||||
|
||||
private boolean directoryHasNeededFiles(@NonNull final File file) {
|
||||
final File[] fileList = file.listFiles();
|
||||
if (fileList == null) {
|
||||
return isNeededExtension(file.toString());
|
||||
}
|
||||
if (fileList.length > 0) {
|
||||
for (final File fileInDirectory : fileList) {
|
||||
if (!isItemVisible(fileInDirectory)) {
|
||||
continue;
|
||||
}
|
||||
if (!fileInDirectory.isDirectory()) {
|
||||
if (isNeededExtension(fileInDirectory.toString())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (directoryHasNeededFiles(fileInDirectory)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNeededExtension(@NonNull final String fileName) {
|
||||
for (final String extension : extensions) {
|
||||
if (fileName.endsWith(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name is validated to be non-null, non-empty and not containing any
|
||||
* slashes.
|
||||
|
|
|
|||
Loading…
Reference in New Issue