From b01c3a9abe8a1b538e0428bc8ac628677e3299d9 Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Mon, 22 Jan 2024 11:15:10 +0100 Subject: [PATCH] move customize action to picker menu --- lib/app/views/device_picker.dart | 70 +++++++++++++++++++++++++------- lib/app/views/navigation.dart | 14 ------- lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_fr.arb | 1 + lib/l10n/app_ja.arb | 1 + lib/l10n/app_pl.arb | 1 + 7 files changed, 61 insertions(+), 28 deletions(-) diff --git a/lib/app/views/device_picker.dart b/lib/app/views/device_picker.dart index 3086ee2a..eeff2ebc 100644 --- a/lib/app/views/device_picker.dart +++ b/lib/app/views/device_picker.dart @@ -24,6 +24,7 @@ import '../../core/state.dart'; import '../../management/models.dart'; import '../key_customization.dart'; import '../models.dart'; +import '../shortcuts.dart'; import '../state.dart'; import 'device_avatar.dart'; import 'keys.dart' as keys; @@ -192,6 +193,7 @@ class _DeviceRow extends StatelessWidget { final bool extended; final bool selected; final Color? background; + final Widget? trailing; final void Function() onTap; const _DeviceRow({ @@ -202,6 +204,7 @@ class _DeviceRow extends StatelessWidget { required this.extended, required this.selected, this.background, + this.trailing, required this.onTap, }); @@ -238,6 +241,7 @@ class _DeviceRow extends StatelessWidget { const EdgeInsets.symmetric(horizontal: 8, vertical: 0), horizontalTitleGap: 8, leading: leading, + trailing: trailing, title: Text( title, overflow: TextOverflow.fade, @@ -326,6 +330,33 @@ _DeviceRow _buildDeviceRow( ); } +Future _showDeviceRowMenu( + BuildContext context, TapDownDetails details, String serialNumber) async { + final l10n = AppLocalizations.of(context)!; + await showMenu( + context: context, + position: RelativeRect.fromLTRB( + details.globalPosition.dx, + details.globalPosition.dy, + details.globalPosition.dx, + 0, + ), + items: [ + PopupMenuItem( + enabled: true, + onTap: () { + Actions.maybeInvoke(context, const KeyCustomizationIntent()); + }, + child: ListTile( + title: Text(l10n.s_customize_key_action), + dense: true, + contentPadding: EdgeInsets.zero, + enabled: true), + ), + ], + ); +} + _DeviceRow _buildCurrentDeviceRow( BuildContext context, WidgetRef ref, @@ -340,23 +371,20 @@ _DeviceRow _buildCurrentDeviceRow( } final title = messages.removeAt(0); final subtitle = messages.join('\n'); + final serialNumber = data.value?.info.serial?.toString(); String displayName = title; Color? displayColor; - if (node is UsbYubiKeyNode) { - if (node.info?.serial != null) { - final properties = ref - .read(keyCustomizationManagerProvider) - .get(node.info?.serial.toString()) - ?.properties; - var customName = properties?['display_name']; - if (customName != null && customName != '') { - displayName = customName; - } - var customColor = properties?['display_color']; - if (customColor != null) { - displayColor = Color(int.parse(customColor, radix: 16)); - } + if (serialNumber != null && serialNumber.isNotEmpty) { + final properties = + ref.read(keyCustomizationManagerProvider).get(serialNumber)?.properties; + var customName = properties?['display_name']; + if (customName != null && customName != '') { + displayName = customName; + } + var customColor = properties?['display_color']; + if (customColor != null) { + displayColor = Color(int.parse(customColor, radix: 16)); } } @@ -374,6 +402,20 @@ _DeviceRow _buildCurrentDeviceRow( background: displayColor, selected: true, onTap: () {}, + trailing: (serialNumber != null && serialNumber.isNotEmpty) + ? GestureDetector( + onTapDown: (TapDownDetails details) async { + await _showDeviceRowMenu(context, details, serialNumber); + }, + onSecondaryTapDown: (TapDownDetails details) async { + await _showDeviceRowMenu(context, details, serialNumber); + }, + child: IconButton( + icon: const Icon(Icons.more_vert_outlined), + onPressed: () {}, + ), + ) + : null, ); } diff --git a/lib/app/views/navigation.dart b/lib/app/views/navigation.dart index 0dabc4f6..b13d6f44 100644 --- a/lib/app/views/navigation.dart +++ b/lib/app/views/navigation.dart @@ -182,20 +182,6 @@ class NavigationContent extends ConsumerWidget { }, ), ], - if (data.info.serial != null) ...[ - NavigationItem( - leading: const Icon(Icons.settings_applications_sharp), - title: 'Customize', - collapsed: !extended, - onTap: () { - if (shouldPop) { - Navigator.of(context).pop(); - } - Actions.maybeInvoke( - context, const KeyCustomizationIntent()); - }, - ) - ], const SizedBox(height: 32), ], ], diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index b2843a3c..dd9bebe5 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -725,6 +725,7 @@ "p_ndef_set_clip_failure": null, "@_key_customization": {}, + "s_customize_key_action": null, "s_custom_key_name": null, "s_custom_key_color": null, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index c378357f..5063ab92 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -725,6 +725,7 @@ "p_ndef_set_clip_failure": "Failed to access clipboard when trying to copy OTP code from YubiKey.", "@_key_customization": {}, + "s_customize_key_action": "Customize key", "s_custom_key_name": "Custom key name", "s_custom_key_color": "Color for YubiKey", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 06c6dd7d..e8b6845d 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -725,6 +725,7 @@ "p_ndef_set_clip_failure": null, "@_key_customization": {}, + "s_customize_key_action": null, "s_custom_key_name": null, "s_custom_key_color": null, diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 8d455c67..c240c55d 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -725,6 +725,7 @@ "p_ndef_set_clip_failure": null, "@_key_customization": {}, + "s_customize_key_action": null, "s_custom_key_name": null, "s_custom_key_color": null, diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 2fb5a4a7..d15a417d 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -725,6 +725,7 @@ "p_ndef_set_clip_failure": "Błąd kopiowania OTP do schowka.", "@_key_customization": {}, + "s_customize_key_action": null, "s_custom_key_name": null, "s_custom_key_color": null,