diff --git a/lib/android/android_alert_dialog.dart b/lib/android/android_alert_dialog.dart index 29ecc76e..f7e96405 100644 --- a/lib/android/android_alert_dialog.dart +++ b/lib/android/android_alert_dialog.dart @@ -15,30 +15,76 @@ */ import 'package:flutter/material.dart'; +import 'package:material_symbols_icons/symbols.dart'; import '../app/state.dart'; import 'tap_request_dialog.dart'; -void showAlertDialog(ref, String title, String message) => +void showAlertDialog(ref, String title, String message, String description, + [Function()? onClosed]) => ref.read(withContextProvider)((context) async { ref.read(androidDialogProvider).closeDialog(); - final l10n = ref.read(l10nProvider); Navigator.of(context).popUntil((route) { return route.isFirst; }); await showDialog( routeSettings: const RouteSettings(name: 'android_alert_dialog'), + useSafeArea: true, context: context, - builder: (dialogContext) { - return AlertDialog( - title: Text(title), - actions: [ - TextButton( - onPressed: () async { - Navigator.of(dialogContext).pop(); - }, - child: Text(l10n.s_close)) - ], - content: Text(message)); - }); + builder: (dialogContext) => + _AndroidAlertDialog(title, message, description)); + if (onClosed != null) { + onClosed(); + } }); + +class _AndroidAlertDialog extends StatelessWidget { + final String title; + final String message; + final String description; + + const _AndroidAlertDialog(this.title, this.message, this.description); + + @override + Widget build(BuildContext context) { + return Dialog( + child: Stack(fit: StackFit.loose, children: [ + Positioned( + top: 5, + right: 5, + child: IconButton( + autofocus: true, + onPressed: () => Navigator.of(context).pop(), + icon: const Icon(Symbols.close, fill: 1, size: 24), + ), + ), + Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: Theme.of(context).textTheme.headlineMedium, + ), + const SizedBox( + height: 32, + ), + Text( + message, + style: Theme.of(context).textTheme.bodyLarge, + ), + const SizedBox( + height: 32, + ), + Text( + description, + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ), + ) + ])); + } +} diff --git a/lib/android/oath/state.dart b/lib/android/oath/state.dart index 3f2ed797..6f485955 100755 --- a/lib/android/oath/state.dart +++ b/lib/android/oath/state.dart @@ -143,23 +143,39 @@ Exception handlePlatformException(PlatformException platformException, ref) { switch (decoded) { case ApduException apduException: if (apduException.sw == 0x6985) { - showAlertDialog(ref, l10n.l_account_add_failure_title, - l10n.p_account_add_failure_6985); + showAlertDialog( + ref, + l10n.l_operation_failed, + l10n.l_add_account_no_password, + l10n.p_add_account_no_password_desc, + ); return CancellationException(); } if (apduException.sw == 0x6982) { - showAlertDialog(ref, l10n.l_account_add_failure_title, - l10n.p_account_add_failure_6982); + showAlertDialog( + ref, + l10n.l_operation_failed, + l10n.l_add_account_key_locked, + l10n.p_add_account_key_locked_desc, + ); return CancellationException(); } case PlatformException pe: if (pe.code == 'JobCancellationException') { - showAlertDialog(ref, l10n.l_account_add_failure_title, - l10n.p_account_add_failure_application_not_available); + showAlertDialog( + ref, + l10n.l_operation_failed, + l10n.l_add_account_no_oath, + l10n.p_add_account_no_oath_desc, + ); return CancellationException(); } else if (pe.code == 'IllegalArgumentException') { - showAlertDialog(ref, l10n.l_account_add_failure_title, - l10n.p_account_add_failure_exists); + showAlertDialog( + ref, + l10n.l_operation_failed, + l10n.l_add_account_already_exists, + l10n.p_add_account_already_exists_desc, + ); return CancellationException(); } } diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 26175d05..8a0c55f6 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": null, "l_account_add_failure_title": null, - "p_account_add_failure_6985": null, - "p_account_add_failure_6982": null, - "p_account_add_failure_exists": null, - "p_account_add_failure_application_not_available": null, + "l_add_account_no_password": null, + "p_add_account_no_password_desc": null, + "l_add_account_key_locked": null, + "p_add_account_key_locked_desc": null, + "l_add_account_already_exists": null, + "p_add_account_already_exists_desc": null, + "l_add_account_no_oath": null, + "p_add_account_no_oath_desc": null, "l_account_name_required": "Ihr Konto muss einen Namen haben", "l_name_already_exists": "Für diesen Aussteller existiert dieser Name bereits", "l_account_already_exists": "Dieses Konto existiert bereits auf dem YubiKey", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index a8b70c0d..4e4c9d4c 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": "Operation failed", "l_account_add_failure_title": "Add account failed", - "p_account_add_failure_6985": "The account could not be added to YubiKey. Please, set password first.", - "p_account_add_failure_6982": "The account could not be added to YubiKey. Please, unlock the key first.", - "p_account_add_failure_exists": "Account already exists on the key.", - "p_account_add_failure_application_not_available": "This YubiKey does not support OATH accounts.", + "l_add_account_no_password": "Set password first", + "p_add_account_no_password_desc": "Your YubiKey needs password to be set before accounts can be added to it.", + "l_add_account_key_locked": "Unlock the key", + "p_add_account_key_locked_desc": "Your YubiKey is password protected. Unlock it before adding accounts.", + "l_add_account_already_exists": "Account already exists on the key", + "p_add_account_already_exists_desc": "The YubiKey already contains account with the same name. Change the account details to add it.", + "l_add_account_no_oath": "This YubiKey does not support accounts", + "p_add_account_no_oath_desc": "Only YubiKey 5 with enabled OATH application can store accounts.", "l_account_name_required": "Your account must have a name", "l_name_already_exists": "This name already exists for the issuer", "l_account_already_exists": "This account already exists on the YubiKey", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 3c0035a6..ce0d04d8 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": null, "l_account_add_failure_title": null, - "p_account_add_failure_6985": null, - "p_account_add_failure_6982": null, - "p_account_add_failure_exists": null, - "p_account_add_failure_application_not_available": null, + "l_add_account_no_password": null, + "p_add_account_no_password_desc": null, + "l_add_account_key_locked": null, + "p_add_account_key_locked_desc": null, + "l_add_account_already_exists": null, + "p_add_account_already_exists_desc": null, + "l_add_account_no_oath": null, + "p_add_account_no_oath_desc": null, "l_account_name_required": "Votre compte doit avoir un nom", "l_name_already_exists": "Ce nom existe déjà pour l'émetteur", "l_account_already_exists": "Ce compte existe déjà sur la YubiKey", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 407cee68..87a6b09b 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": null, "l_account_add_failure_title": null, - "p_account_add_failure_6985": null, - "p_account_add_failure_6982": null, - "p_account_add_failure_exists": null, - "p_account_add_failure_application_not_available": null, + "l_add_account_no_password": null, + "p_add_account_no_password_desc": null, + "l_add_account_key_locked": null, + "p_add_account_key_locked_desc": null, + "l_add_account_already_exists": null, + "p_add_account_already_exists_desc": null, + "l_add_account_no_oath": null, + "p_add_account_no_oath_desc": null, "l_account_name_required": "アカウントには名前が必要です", "l_name_already_exists": "この名前は発行者にすでに存在します", "l_account_already_exists": "このアカウントはYubiKeyにすでに存在します", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 5762fb88..5085e4ba 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": null, "l_account_add_failure_title": null, - "p_account_add_failure_6985": null, - "p_account_add_failure_6982": null, - "p_account_add_failure_exists": null, - "p_account_add_failure_application_not_available": null, + "l_add_account_no_password": null, + "p_add_account_no_password_desc": null, + "l_add_account_key_locked": null, + "p_add_account_key_locked_desc": null, + "l_add_account_already_exists": null, + "p_add_account_already_exists_desc": null, + "l_add_account_no_oath": null, + "p_add_account_no_oath_desc": null, "l_account_name_required": "Twoje konto musi mieć nazwę", "l_name_already_exists": "Ta nazwa już istnieje dla tego wydawcy", "l_account_already_exists": "To konto już istnieje w YubiKey", diff --git a/lib/l10n/app_vi.arb b/lib/l10n/app_vi.arb index 53db7455..79d3926c 100644 --- a/lib/l10n/app_vi.arb +++ b/lib/l10n/app_vi.arb @@ -427,11 +427,16 @@ "message": {} } }, + "l_operation_failed": null, "l_account_add_failure_title": null, - "p_account_add_failure_6985": null, - "p_account_add_failure_6982": null, - "p_account_add_failure_exists": null, - "p_account_add_failure_application_not_available": null, + "l_add_account_no_password": null, + "p_add_account_no_password_desc": null, + "l_add_account_key_locked": null, + "p_add_account_key_locked_desc": null, + "l_add_account_already_exists": null, + "p_add_account_already_exists_desc": null, + "l_add_account_no_oath": null, + "p_add_account_no_oath_desc": null, "l_account_name_required": "Tài khoản của bạn phải có tên", "l_name_already_exists": "Tên này đã tồn tại cho nhà phát hành", "l_account_already_exists": "Tài khoản này đã tồn tại trên YubiKey",