Skip to content

Commit

Permalink
Don't crash on inaccessible external storage. Closes #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
x0b committed Sep 16, 2019
1 parent d262d97 commit 0b24379
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ release/
.idea/misc.xml
.idea/modules.xml
.idea/codeStyles/Project.xml

.idea/codeStyles/codeStyleConfig.xml
.idea/inspectionProfiles/Project_Default.xml
.idea/
15 changes: 12 additions & 3 deletions app/src/main/java/ca/pkay/rcloneexplorer/FilePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
Expand All @@ -26,6 +27,7 @@
import com.leinardi.android.speeddial.SpeedDialView;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -333,7 +335,7 @@ private void showStorageMenu() {
builder.setTitle(R.string.select_storage);

int selected = availableStorage.indexOf(root.getAbsolutePath());
CharSequence[] options = availableStorage.toArray(new CharSequence[availableStorage.size()]);
final CharSequence[] options = availableStorage.toArray(new CharSequence[availableStorage.size()]);
builder.setSingleChoiceItems(options, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -344,15 +346,22 @@ public void onClick(DialogInterface dialog, int which) {
builder.setPositiveButton(R.string.select, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switchStorage(userSelected[0]);
try {
switchStorage(userSelected[0]);
} catch (IOException e) {
Log.e("FilePicker", "Path not accessible", e);
}
}
});

builder.show();
}

private void switchStorage(int which) {
private void switchStorage(int which) throws IOException {
File newStorage = new File(availableStorage.get(which));
if(!newStorage.canRead()) {
throw new IOException("Location not accessible");
}
root = current = newStorage;
fileList = new ArrayList<>(Arrays.asList(current.listFiles()));
sortDirectory();
Expand Down

0 comments on commit 0b24379

Please sign in to comment.