From a2516850022972bed0f2d8c1f23f1590ce88d8c0 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Mon, 1 Apr 2019 23:36:31 +0200 Subject: [PATCH] Add a dialog that displays a list of errors that occurred during import --- .../aegis/ui/PreferencesFragment.java | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 28 insertions(+) diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java index a427e316..2c3adb1c 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java @@ -2,6 +2,9 @@ package com.beemdevelopment.aegis.ui; import android.Manifest; import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.media.MediaScannerConnection; @@ -10,6 +13,7 @@ import android.os.Bundle; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; +import android.text.TextUtils; import android.view.Gravity; import android.view.View; import android.view.Window; @@ -514,7 +518,29 @@ public class PreferencesFragment extends PreferenceFragmentCompat { } _result.putExtra("needsRecreate", true); + Snackbar bar = Snackbar.make(getView(), String.format(Locale.getDefault(), getString(R.string.imported_entries_count), entries.size(), errors.size()), Snackbar.LENGTH_LONG); + if (errors.size() > 0) { + bar.setAction(R.string.details, v -> { + List messages = new ArrayList<>(); + for (DatabaseImporterEntryException e : errors) { + messages.add(e.getMessage()); + } + + String message = TextUtils.join("\n\n", messages); + Dialogs.showSecureDialog(new AlertDialog.Builder(getActivity()) + .setTitle(R.string.import_error_title) + .setMessage(message) + .setPositiveButton(android.R.string.ok, null) + .setNeutralButton(android.R.string.copy, (dialog, which) -> { + ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("text/plain", message); + clipboard.setPrimaryClip(clip); + Toast.makeText(getActivity(), getString(R.string.errors_copied), Toast.LENGTH_SHORT).show(); + }) + .create()); + }); + } bar.show(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 15c88922..b62e2a1a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -114,6 +114,7 @@ Aegis has been setup and is ready to go. Vault not found, starting setup… Code copied to the clipboard + Errors copied to the clipboard An error occurred while trying to unlock the vault An error occurred while trying to save the vault Disable encryption @@ -128,6 +129,7 @@ An error occurred while trying to read the file Error: unable to obtain root access Imported %d entries. %d errors. + One or more errors occurred during the import An error occurred while trying to export the database The database has been exported to: This action will export the database out of Aegis\' private storage.