From 5cc25c6ef79460c9f5f572825c78a5ef498ba6e5 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Fri, 26 Apr 2024 15:23:05 +0530 Subject: [PATCH] fix: sort codes correctly based on pinning status --- auth/lib/l10n/arb/app_en.arb | 3 +- auth/lib/models/code.dart | 11 +++++- auth/lib/ui/code_widget.dart | 72 +++++++++++++++++++++++------------- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/auth/lib/l10n/arb/app_en.arb b/auth/lib/l10n/arb/app_en.arb index c7c8cac068..c0894a5477 100644 --- a/auth/lib/l10n/arb/app_en.arb +++ b/auth/lib/l10n/arb/app_en.arb @@ -423,5 +423,6 @@ "invalidEndpointMessage": "Sorry, the endpoint you entered is invalid. Please enter a valid endpoint and try again.", "endpointUpdatedMessage": "Endpoint updated successfully", "customEndpoint": "Connected to {endpoint}", - "pinText": "Pin" + "pinText": "Pin", + "unpinText": "Unpin" } \ No newline at end of file diff --git a/auth/lib/models/code.dart b/auth/lib/models/code.dart index 2610b62da3..6abbb61ea2 100644 --- a/auth/lib/models/code.dart +++ b/auth/lib/models/code.dart @@ -105,6 +105,7 @@ class Code { _getType(uri), _getCounter(uri), rawData, + display: display, ); } catch (e) { // if account name contains # without encoding, @@ -150,7 +151,7 @@ class Code { Map toExportJson() { return { 'rawData': rawData, - 'display': display?.toJson(), + if (display != null) 'display': display?.toJson(), }; } @@ -236,7 +237,8 @@ class Code { other.secret == secret && other.counter == counter && other.type == type && - other.rawData == rawData; + other.rawData == rawData && + other.display == display; } @override @@ -251,6 +253,11 @@ class Code { rawData.hashCode ^ display.hashCode; } + + @override + String toString() { + return 'Code(account: $account, issuer: $issuer, digits: $digits, period: $period, secret: $secret, algorithm: $algorithm, type: $type, counter: $counter, rawData: $rawData, display: $display)'; + } } enum Type { diff --git a/auth/lib/ui/code_widget.dart b/auth/lib/ui/code_widget.dart index b1a6a3f052..ad4f134569 100644 --- a/auth/lib/ui/code_widget.dart +++ b/auth/lib/ui/code_widget.dart @@ -99,7 +99,7 @@ class _CodeWidgetState extends State { onSelected: () => _onShowQrPressed(null), ), MenuItem( - label: l10n.pinText, + label: widget.code.isPinned ? l10n.unpinText : l10n.pinText, icon: widget.code.isPinned ? Icons.push_pin : Icons.push_pin_outlined, @@ -156,7 +156,7 @@ class _CodeWidgetState extends State { icon: widget.code.isPinned ? Icons.push_pin : Icons.push_pin_outlined, - label: l10n.pinText, + label: widget.code.isPinned ? l10n.unpinText : l10n.pinText, padding: const EdgeInsets.only(left: 4, right: 0), spacing: 8, ), @@ -202,7 +202,16 @@ class _CodeWidgetState extends State { return ClipRRect( borderRadius: BorderRadius.circular(8), child: Container( - color: Theme.of(context).colorScheme.codeCardBackgroundColor, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.codeCardBackgroundColor, + boxShadow: [ + BoxShadow( + color: Theme.of(context).colorScheme.shadow, + blurRadius: 8, + offset: const Offset(0, 4), + ), + ], + ), child: Material( color: Colors.transparent, child: InkWell( @@ -233,34 +242,47 @@ class _CodeWidgetState extends State { Widget _getCardContents(AppLocalizations l10n) { return SizedBox( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, + child: Stack( children: [ - if (widget.code.type == Type.totp) - CodeTimerProgress( - period: widget.code.period, - ), - const SizedBox( - height: 16, - ), - Row( + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, children: [ - _shouldShowLargeIcon ? _getIcon() : const SizedBox.shrink(), - Expanded( - child: Column( - children: [ - _getTopRow(), - const SizedBox(height: 4), - _getBottomRow(l10n), - ], + if (widget.code.type == Type.totp) + CodeTimerProgress( + period: widget.code.period, ), + const SizedBox( + height: 16, + ), + Row( + children: [ + _shouldShowLargeIcon ? _getIcon() : const SizedBox.shrink(), + Expanded( + child: Column( + children: [ + _getTopRow(), + const SizedBox(height: 4), + _getBottomRow(l10n), + ], + ), + ), + ], + ), + const SizedBox( + height: 20, ), ], ), - const SizedBox( - height: 20, - ), + if (widget.code.isPinned) + const Positioned( + right: 4, + top: 4, + child: Icon( + Icons.push_pin, + size: 12, + ), + ), ], ), );