mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 22:12:55 +00:00
Include URI in ImportFileTask error messages
This commit is contained in:
parent
9d318a0d54
commit
aff441a7ee
4 changed files with 29 additions and 14 deletions
|
@ -616,11 +616,11 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
|
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
|
||||||
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
|
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
|
||||||
ImportFileTask task = new ImportFileTask(this, result -> {
|
ImportFileTask task = new ImportFileTask(this, result -> {
|
||||||
if (result.getException() == null) {
|
if (result.getError() == null) {
|
||||||
CustomSvgIcon icon = new CustomSvgIcon(result.getFile());
|
CustomSvgIcon icon = new CustomSvgIcon(result.getFile());
|
||||||
selectIcon(icon);
|
selectIcon(icon);
|
||||||
} else {
|
} 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);
|
task.execute(getLifecycle(), params);
|
||||||
|
|
|
@ -137,10 +137,10 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
||||||
|
|
||||||
ImportFileTask.Params params = new ImportFileTask.Params(uri, "import", null);
|
ImportFileTask.Params params = new ImportFileTask.Params(uri, "import", null);
|
||||||
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
|
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
|
||||||
if (result.getException() == null) {
|
if (result.getError() == null) {
|
||||||
startImportEntriesActivity(_importerDef, result.getFile());
|
startImportEntriesActivity(_importerDef, result.getFile());
|
||||||
} else {
|
} 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);
|
task.execute(getLifecycle(), params);
|
||||||
|
|
|
@ -56,8 +56,8 @@ public class WelcomeSlide extends SlideFragment {
|
||||||
private void startImportVault(Uri uri) {
|
private void startImportVault(Uri uri) {
|
||||||
ImportFileTask.Params params = new ImportFileTask.Params(uri, "intro-import", null);
|
ImportFileTask.Params params = new ImportFileTask.Params(uri, "intro-import", null);
|
||||||
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
|
ImportFileTask task = new ImportFileTask(requireContext(), result -> {
|
||||||
if (result.getException() != null) {
|
if (result.getError() != null) {
|
||||||
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getException());
|
Dialogs.showErrorDialog(requireContext(), R.string.reading_file_error, result.getError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
|
||||||
Context context = getDialog().getContext();
|
Context context = getDialog().getContext();
|
||||||
|
|
||||||
Params p = params[0];
|
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) {
|
if (inStream == null) {
|
||||||
throw new IOException("openInputStream returned null");
|
throw new IOException("openInputStream returned null");
|
||||||
}
|
}
|
||||||
|
@ -41,10 +42,10 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
|
||||||
IOUtils.copy(inStream, outStream);
|
IOUtils.copy(inStream, outStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Result(tempFile, null);
|
return new Result(uri, tempFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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 {
|
public static class Result {
|
||||||
private final File _file;
|
private final Uri _uri;
|
||||||
private final Exception _e;
|
private File _file;
|
||||||
|
private Exception _e;
|
||||||
|
|
||||||
public Result(File file, Exception e) {
|
public Result(Uri uri, File file) {
|
||||||
|
_uri = uri;
|
||||||
_file = file;
|
_file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(Uri uri, Exception e) {
|
||||||
|
_uri = uri;
|
||||||
_e = e;
|
_e = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uri getUri() {
|
||||||
|
return _uri;
|
||||||
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
return _file;
|
return _file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Exception getException() {
|
public String getError() {
|
||||||
return _e;
|
if (_e == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("ImportFileTask(uri=\"%s\"): %s", _uri, _e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue