Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
kairusds committed Oct 17, 2024
1 parent f29fa2c commit 127b32a
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions app/src/main/java/github/kairusds/libvlcandroidtest/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,67 +191,71 @@ private void setVLCMedia(String path){
}

private void showFilePickerDialog(File dir){
executor.execute(() -> {
File[] files = dir.listFiles();
ArrayList<String> fileList = new ArrayList<>();
HashMap<String, String> paths = new HashMap<>();
fileList.add("..");

if(files != null){
Tika tika = new Tika();
for(File file : files){
if(file.isDirectory()){
fileList.add(file.getName());
paths.put(file.getName(), file.getAbsolutePath());
}else{
String mimetype = tika.detect(file.getName());
if(mimetype.startsWith("video/")){
try{
executor.execute(() -> {
File[] files = dir.listFiles();
ArrayList<String> fileList = new ArrayList<>();
HashMap<String, String> paths = new HashMap<>();
fileList.add("..");

if(files != null){
Tika tika = new Tika();
for(File file : files){
if(file.isDirectory()){
fileList.add(file.getName());
paths.put(file.getName(), file.getAbsolutePath());
}else{
String mimetype = tika.detect(file.getName());
if(mimetype.startsWith("video/")){
fileList.add(file.getName());
paths.put(file.getName(), file.getAbsolutePath());
}
}
}
}
}

handler.post(() -> {
if(files == null){
toast("Unable to access directory");
executor.shutdown();
executor = null;
return;
}

ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.select_dialog_item, fileList);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Choose a file or directory");
builder.setAdapter(adapter, (dialog, which) -> {
if(which == 0){
File parentDir = dir.getParentFile();
if(parentDir != null){
dialog.dismiss();
showFilePickerDialog(parentDir);
}else{
toast("No parent directory");
}
}else{
String filename = fileList.get(which);
String filepath = paths.get(filename);
File selectedFile = new File(filepath);
if(selectedFile.isDirectory()){
dialog.dismiss();
showFilePickerDialog(selectedFile);

handler.post(() -> {
if(files == null){
toast("Unable to access directory");
executor.shutdown();
executor = null;
return;
}

ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.select_dialog_item, fileList);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Choose a file or directory");
builder.setAdapter(adapter, (dialog, which) -> {
if(which == 0){
File parentDir = dir.getParentFile();
if(parentDir != null){
dialog.dismiss();
showFilePickerDialog(parentDir);
}else{
toast("No parent directory");
}
}else{
setVLCMedia(filepath);
dialog.dismiss();
executor.shutdown();
executor = null;
String filename = fileList.get(which);
String filepath = paths.get(filename);
File selectedFile = new File(filepath);
if(selectedFile.isDirectory()){
dialog.dismiss();
showFilePickerDialog(selectedFile);
}else{
setVLCMedia(filepath);
dialog.dismiss();
executor.shutdown();
executor = null;
}
}
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
});
builder.setNegativeButton("Cancel", null);
builder.show();
});
});
}catch(Exception e){
toast(e.getMessage());
}
}

@Override
Expand Down

0 comments on commit 127b32a

Please sign in to comment.