Skip to content

Commit

Permalink
Style alert dialog icons
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbakker committed Mar 9, 2024
1 parent 67b90bd commit d856a63
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ protected void onCreate(Bundle savedInstanceState) {

biometricsButton.setOnClickListener(v -> {
if (_prefs.isPasswordReminderNeeded()) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(getString(R.string.password_reminder_dialog_title))
.setMessage(getString(R.string.password_reminder_dialog_message))
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, (dialog1, which) -> {
showBiometricPrompt();
})
Expand Down Expand Up @@ -292,10 +293,11 @@ private void finish(MasterKey key, boolean isSlotRepaired) {
}

private void onInvalidPassword() {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(AuthActivity.this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(AuthActivity.this, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(getString(R.string.unlock_vault_error))
.setMessage(getString(R.string.unlock_vault_error_description))
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, (dialog, which) -> selectPassword())
.create());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;

import com.amulyakhare.textdrawable.TextDrawable;
import com.avito.android.krop.KropView;
Expand Down Expand Up @@ -755,9 +754,10 @@ private VaultEntry parseEntry() throws ParseException {
}

private void onSaveError(String msg) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(getString(R.string.saving_profile_error))
.setMessage(msg)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, null)
.create());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {

@Override
public void onRemoveGroup(VaultGroup group) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.remove_group)
.setMessage(R.string.remove_group_description)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
_removedGroups.add(group.getUUID());
_adapter.removeGroup(group);
Expand All @@ -98,9 +99,10 @@ public void onRemoveGroup(VaultGroup group) {
}

public void onRemoveUnusedGroups() {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.remove_unused_groups)
.setMessage(R.string.remove_unused_groups_description)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
Set<VaultGroup> unusedGroups = new HashSet<>(_vaultManager.getVault().getGroups());
unusedGroups.removeAll(_vaultManager.getVault().getUsedGroups());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ private void startImport(DatabaseImporter.Definition importerDef, @Nullable File
if (importer.isInstalledAppVersionSupported()) {
startImportApp(importer);
} else {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.warning)
.setMessage(getString(R.string.app_version_error, importerDef.getName()))
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(R.string.yes, (dialog1, which) -> {
startImportApp(importer);
})
Expand Down Expand Up @@ -215,7 +216,7 @@ private void importDatabase(DatabaseImporter.State state) {
List<DatabaseImporterEntryException> errors = result.getErrors();
if (errors.size() > 0) {
String message = getResources().getQuantityString(R.plurals.import_error_dialog, errors.size(), errors.size());
Dialogs.showMultiErrorDialog(this, R.string.import_error_title, message, errors, null);
Dialogs.showMultiExceptionDialog(this, R.string.import_error_title, message, errors, null);
}

findDuplicates(importEntries);
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private void startDecodeQrCodeImages(List<Uri> uris) {
boolean isSingleBatch = GoogleAuthInfo.Export.isSingleBatch(googleAuthExports);
if (!isSingleBatch && errors.size() > 0) {
errors.add(getString(R.string.unrelated_google_auth_batches_error));
Dialogs.showMultiMessageDialog(this, R.string.import_error_title, getString(R.string.no_tokens_can_be_imported), errors, null);
Dialogs.showMultiErrorDialog(this, R.string.import_error_title, getString(R.string.no_tokens_can_be_imported), errors, null);
return;
} else if (!isSingleBatch) {
Dialogs.showErrorDialog(this, R.string.import_google_auth_failure, getString(R.string.unrelated_google_auth_batches_error));
Expand All @@ -468,7 +468,7 @@ private void startDecodeQrCodeImages(List<Uri> uris) {
}

if ((errors.size() > 0 && results.size() > 1) || errors.size() > 1) {
Dialogs.showMultiMessageDialog(this, R.string.import_error_title, getString(R.string.unable_to_read_qrcode_files, uris.size() - errors.size(), uris.size()), errors, dialogDismissHandler);
Dialogs.showMultiErrorDialog(this, R.string.import_error_title, getString(R.string.unable_to_read_qrcode_files, uris.size() - errors.size(), uris.size()), errors, dialogDismissHandler);
} else if (errors.size() > 0) {
Dialogs.showErrorDialog(this, getString(R.string.unable_to_read_qrcode_file, results.get(0).getFileName()), errors.get(0), dialogDismissHandler);
} else {
Expand Down Expand Up @@ -865,10 +865,10 @@ private void updateErrorCard() {
text = getString(R.string.backup_reminder_bar_message);
}
info = new ErrorCardInfo(text, view -> {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(R.string.backup_reminder_bar_dialog_title)
.setMessage(R.string.backup_reminder_bar_dialog_summary)
.setIcon(R.drawable.ic_info_outline_black_24dp)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(R.string.backup_reminder_bar_dialog_accept, (dialog, whichButton) -> {
startPreferencesActivity(BackupsPreferencesFragment.class, "pref_backups");
})
Expand All @@ -885,9 +885,10 @@ private void updateErrorCard() {
private void showPlaintextExportWarningOptions() {
View view = LayoutInflater.from(this).inflate(R.layout.dialog_plaintext_warning, null);

AlertDialog dialog = new MaterialAlertDialogBuilder(this)
AlertDialog dialog = new MaterialAlertDialogBuilder(this, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.backup_plaintext_export_warning)
.setView(view)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, null)
.setNegativeButton(android.R.string.cancel, null)
.create();
Expand Down
31 changes: 19 additions & 12 deletions app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public static void showDeleteEntriesDialog(Context context, List<VaultEntry> ser
}
textMessage.setText(message);

showSecureDialog(new MaterialAlertDialogBuilder(context)
showSecureDialog(new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(title)
.setView(view)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.yes, onDelete)
.setNegativeButton(android.R.string.no, null)
.create());
Expand All @@ -109,9 +110,10 @@ private static String getVaultEntryName(Context context, VaultEntry entry) {
}

public static void showDiscardDialog(Context context, DialogInterface.OnClickListener onSave, DialogInterface.OnClickListener onDiscard) {
showSecureDialog(new MaterialAlertDialogBuilder(context)
showSecureDialog(new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(context.getString(R.string.discard_changes))
.setMessage(context.getString(R.string.discard_changes_description))
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(R.string.save, onSave)
.setNegativeButton(R.string.discard, onDiscard)
.create());
Expand Down Expand Up @@ -373,10 +375,11 @@ public static void showErrorDialog(Context context, String message, CharSequence
TextView textMessage = view.findViewById(R.id.error_message);
textMessage.setText(message);

AlertDialog dialog = new MaterialAlertDialogBuilder(context)
AlertDialog dialog = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(R.string.error_occurred)
.setView(view)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, (dialog1, which) -> {
if (listener != null) {
listener.onClick(dialog1, which);
Expand Down Expand Up @@ -413,45 +416,47 @@ public static void showBackupErrorDialog(Context context, Preferences.BackupResu
Dialogs.showErrorDialog(context, message, backupRes.getError(), listener);
}

public static void showMultiMessageDialog(
public static void showMultiErrorDialog(
Context context, @StringRes int title, String message, List<CharSequence> messages, DialogInterface.OnClickListener listener) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(context)
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (listener != null) {
listener.onClick(dialog, which);
}
})
.setNeutralButton(context.getString(R.string.details), (dialog, which) -> {
showDetailedMultiMessageDialog(context, title, messages, listener);
showDetailedMultiErrorDialog(context, title, messages, listener);
})
.create());
}

public static <T extends Throwable> void showMultiErrorDialog(
public static <T extends Throwable> void showMultiExceptionDialog(
Context context, @StringRes int title, String message, List<T> errors, DialogInterface.OnClickListener listener) {
List<CharSequence> messages = new ArrayList<>();
for (Throwable e : errors) {
messages.add(e.toString());
}

showMultiMessageDialog(context, title, message, messages, listener);
showMultiErrorDialog(context, title, message, messages, listener);
}

private static void showDetailedMultiMessageDialog(
private static void showDetailedMultiErrorDialog(
Context context, @StringRes int title, List<CharSequence> messages, DialogInterface.OnClickListener listener) {
SpannableStringBuilder builder = new SpannableStringBuilder();
for (CharSequence message : messages) {
builder.append(message);
builder.append("\n\n");
}

AlertDialog dialog = new MaterialAlertDialogBuilder(context)
AlertDialog dialog = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(title)
.setMessage(builder)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, (dialog1, which) -> {
if (listener != null) {
listener.onClick(dialog1, which);
Expand All @@ -478,10 +483,11 @@ public static void showTimeSyncWarningDialog(Context context, Dialog.OnClickList
View view = LayoutInflater.from(context).inflate(R.layout.dialog_time_sync, null);
CheckBox checkBox = view.findViewById(R.id.check_warning_disable);

showSecureDialog(new MaterialAlertDialogBuilder(context)
showSecureDialog(new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.time_sync_warning_title)
.setView(view)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(R.string.yes, (dialog, which) -> {
if (checkBox.isChecked()) {
prefs.setIsTimeSyncWarningEnabled(false);
Expand Down Expand Up @@ -537,11 +543,12 @@ public static void showPartialGoogleAuthImportWarningDialog(Context context, Lis
errorDetails.append("\n\n");
}

MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context)
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.partial_google_auth_import)
.setMessage(context.getString(R.string.partial_google_auth_import_warning, missingIndexesAsString))
.setView(view)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(context.getString(R.string.import_partial_export_anyway, entries), (dialog, which) -> {
dismissHandler.onClick(dialog, which);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void updateBackupStatus(Preference pref, Preferences.BackupResult res) {

// TODO: Find out why setting the tint of the icon doesn't work
if (backupFailed) {
pref.setIcon(R.drawable.ic_info_outline_black_24dp);
pref.setIcon(R.drawable.ic_outline_error_24);
} else if (res != null) {
pref.setIcon(R.drawable.ic_check_black_24dp);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {

@Override
public void onRemoveIconPack(IconPack pack) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext())
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.remove_icon_pack)
.setMessage(R.string.remove_icon_pack_description)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
try {
_iconPackManager.removeIconPack(pack);
Expand All @@ -124,9 +125,10 @@ private void importIconPack(Uri uri) {
ImportIconPackTask task = new ImportIconPackTask(requireContext(), result -> {
Exception e = result.getException();
if (e instanceof IconPackExistsException) {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext())
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(R.string.error_occurred)
.setMessage(R.string.icon_pack_import_exists_error)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(R.string.yes, (dialog, which) -> {
if (removeIconPack(((IconPackExistsException) e).getIconPack())) {
importIconPack(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (!_vaultManager.getVault().isEncryptionEnabled()) {
Dialogs.showSetPasswordDialog(requireActivity(), new EnableEncryptionListener());
} else {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext())
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(R.string.disable_encryption)
.setMessage(getText(R.string.disable_encryption_description))
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
try {
_vaultManager.disableEncryption();
Expand Down Expand Up @@ -170,9 +171,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
task.execute(getLifecycle(), params);
} else {
_pinKeyboardPreference.setChecked(false);
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext())
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(R.string.pin_keyboard_error)
.setMessage(R.string.pin_keyboard_error_description)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, null)
.create());
Expand Down Expand Up @@ -460,9 +462,10 @@ public void onTaskFinished(PasswordSlotDecryptTask.Result result) {
if (result != null) {
_pinKeyboardPreference.setChecked(true);
} else {
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext())
Dialogs.showSecureDialog(new MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Aegis_AlertDialog_Error)
.setTitle(R.string.pin_keyboard_error)
.setMessage(R.string.invalid_password)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, null)
.create());
Expand Down
Loading

0 comments on commit d856a63

Please sign in to comment.