mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
- Added file suffix verification. It allows to show to the user only the desired file type (such as .jar, or .zip).
This commit is contained in:
parent
012d4dd0d7
commit
86ee2ed497
@ -24,17 +24,31 @@ public class FileListView extends LinearLayout
|
|||||||
private AlertDialog build;
|
private AlertDialog build;
|
||||||
private String lockPath = "/";
|
private String lockPath = "/";
|
||||||
|
|
||||||
|
//For filtering by file types:
|
||||||
|
private final String[] fileSuffixes;
|
||||||
|
|
||||||
public FileListView(AlertDialog build) {
|
public FileListView(AlertDialog build) {
|
||||||
this(build.getContext(), null);
|
this(build.getContext(), null, new String[0]);
|
||||||
this.build = build;
|
this.build = build;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileListView(Context context, AttributeSet attrs) {
|
public FileListView(AlertDialog build, String fileSuffix) {
|
||||||
this(context, attrs, 0);
|
this(build.getContext(), null, new String[]{fileSuffix});
|
||||||
|
this.build = build;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileListView(Context context, AttributeSet attrs, int defStyle) {
|
public FileListView(AlertDialog build, String[] fileSuffixes){
|
||||||
|
this(build.getContext(), null, fileSuffixes);
|
||||||
|
this.build = build;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileListView(Context context, AttributeSet attrs, String[] fileSuffixes) {
|
||||||
|
this(context, attrs, 0, fileSuffixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileListView(Context context, AttributeSet attrs, int defStyle, String[] fileSuffixes) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
this.fileSuffixes = fileSuffixes;
|
||||||
init(context);
|
init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +98,7 @@ public class FileListView extends LinearLayout
|
|||||||
{
|
{
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void listFileAt(final String path)
|
public void listFileAt(final String path)
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
@ -101,9 +116,26 @@ public class FileListView extends LinearLayout
|
|||||||
|
|
||||||
if(listFile.length != 0){
|
if(listFile.length != 0){
|
||||||
Arrays.sort(listFile, new SortFileName());
|
Arrays.sort(listFile, new SortFileName());
|
||||||
for(File file : listFile){
|
if(fileSuffixes.length > 0){ //Meaning we want only specific files
|
||||||
fileAdapter.add(file);
|
for(File file : listFile){
|
||||||
|
if(file.isDirectory()){
|
||||||
|
fileAdapter.add(file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String suffix : fileSuffixes){
|
||||||
|
if(file.getName().endsWith("." + suffix)){
|
||||||
|
fileAdapter.add(file);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //We get every file
|
||||||
|
for(File file : listFile){
|
||||||
|
fileAdapter.add(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
mainLv.setAdapter(fileAdapter);
|
mainLv.setAdapter(fileAdapter);
|
||||||
if (build != null) build.setTitle(new File(path).getName());
|
if (build != null) build.setTitle(new File(path).getName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user