Include URI in ImportFileTask error messages

This commit is contained in:
Alexander Bakker 2022-11-28 18:50:49 +01:00
parent 9d318a0d54
commit aff441a7ee
4 changed files with 29 additions and 14 deletions

View File

@ -616,11 +616,11 @@ public class EditEntryActivity extends AegisActivity {
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
ImportFileTask task = new ImportFileTask(this, result -> {
if (result.getException() == null) {
if (result.getError() == null) {
CustomSvgIcon icon = new CustomSvgIcon(result.getFile());
selectIcon(icon);
} else {
Dialogs.showErrorDialog(this, R.string.reading_file_error, result.getException());
Dialogs.showErrorDialog(this, R.string.reading_file_error, result.getError());
}
});
task.execute(getLifecycle(), params);

View File

@ -137,10 +137,10 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
ImportFileTask.Params params = new ImportFileTask.Params(uri, "import", null);
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
if (result.getException() == null) {
if (result.getError() == null) {
startImportEntriesActivity(_importerDef, result.getFile());
} else {
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getException());
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getError());
}
});
task.execute(getLifecycle(), params);

View File

@ -56,8 +56,8 @@ public class WelcomeSlide extends SlideFragment {
private void startImportVault(Uri uri) {
ImportFileTask.Params params = new ImportFileTask.Params(uri, "intro-import", null);
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
if (result.getException() != null) {
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getException());
if (result.getError() != null) {
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getError());
return;
}

View File

@ -28,7 +28,8 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
Context context = getDialog().getContext();
Params p = params[0];
try (InputStream inStream = context.getContentResolver().openInputStream(p.getUri())) {
Uri uri = p.getUri();
try (InputStream inStream = context.getContentResolver().openInputStream(uri)) {
if (inStream == null) {
throw new IOException("openInputStream returned null");
}
@ -41,10 +42,10 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
IOUtils.copy(inStream, outStream);
}
return new Result(tempFile, null);
return new Result(uri, tempFile);
} catch (IOException e) {
e.printStackTrace();
return new Result(null, e);
return new Result(uri, e);
}
}
@ -83,20 +84,34 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
}
public static class Result {
private final File _file;
private final Exception _e;
private final Uri _uri;
private File _file;
private Exception _e;
public Result(File file, Exception e) {
public Result(Uri uri, File file) {
_uri = uri;
_file = file;
}
public Result(Uri uri, Exception e) {
_uri = uri;
_e = e;
}
public Uri getUri() {
return _uri;
}
public File getFile() {
return _file;
}
public Exception getException() {
return _e;
public String getError() {
if (_e == null) {
return null;
}
return String.format("ImportFileTask(uri=\"%s\"): %s", _uri, _e);
}
}
}