π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] Add "Newest first" sort option (#13168)
Hehbveh5a5ce00ee1ae
diff --git a/mobile/apps/auth/changes/newest-first-sort.md b/mobile/apps/auth/changes/newest-first-sort.mdnew file mode 100644index 0000000000..887e6a6518--- /dev/null+++ b/mobile/apps/auth/changes/newest-first-sort.md@@ -0,0 +1 @@+- Added a newest-first sort option (@hehbveh).diff --git a/mobile/apps/auth/lib/models/authenticator/entity_result.dart b/mobile/apps/auth/lib/models/authenticator/entity_result.dartindex 3e7e04c8b2..5c6c8957e8 100644--- a/mobile/apps/auth/lib/models/authenticator/entity_result.dart+++ b/mobile/apps/auth/lib/models/authenticator/entity_result.dart@@ -2,6 +2,7 @@ class EntityResult {final int generatedID;final String rawData;final bool hasSynced;+ final int createdAt;- EntityResult(this.generatedID, this.rawData, this.hasSynced);+ EntityResult(this.generatedID, this.rawData, this.hasSynced, this.createdAt);}diff --git a/mobile/apps/auth/lib/models/code.dart b/mobile/apps/auth/lib/models/code.dartindex 2c060d7900..4c9ec140d3 100644--- a/mobile/apps/auth/lib/models/code.dart+++ b/mobile/apps/auth/lib/models/code.dart@@ -22,6 +22,7 @@ class Code {final String rawData;final int counter;bool? hasSynced;+ int? createdAt;final CodeDisplay display;@@ -106,7 +107,7 @@ class Code {"&period=$updatePeriod&secret=$updatedSecret${updatedType == Type.hotp ? "&counter=$updatedCounter" : ""}",generatedID: generatedID,display: updatedDisplay,- );+ )..createdAt = createdAt;}static Code fromAccountAndSecret(diff --git a/mobile/apps/auth/lib/services/authenticator_service.dart b/mobile/apps/auth/lib/services/authenticator_service.dartindex 7373770472..3def449d44 100644--- a/mobile/apps/auth/lib/services/authenticator_service.dart+++ b/mobile/apps/auth/lib/services/authenticator_service.dart@@ -82,7 +82,12 @@ class AuthenticatorService {);final hasSynced = !(e.id == null || e.shouldSync);entities.add(- EntityResult(e.generatedID, utf8.decode(decryptedValue), hasSynced),+ EntityResult(+ e.generatedID,+ utf8.decode(decryptedValue),+ hasSynced,+ e.createdAt,+ ),);} catch (e, s) {_logger.severe(e, s);diff --git a/mobile/apps/auth/lib/services/preference_service.dart b/mobile/apps/auth/lib/services/preference_service.dartindex 42cb24c7f3..d4325cc894 100644--- a/mobile/apps/auth/lib/services/preference_service.dart+++ b/mobile/apps/auth/lib/services/preference_service.dart@@ -9,6 +9,7 @@ enum CodeSortKey {mostFrequentlyUsed,recentlyUsed,manual,+ newestFirst,}class PreferenceService {diff --git a/mobile/apps/auth/lib/store/code_store.dart b/mobile/apps/auth/lib/store/code_store.dartindex 76e8a72e14..3ab510fe9b 100644--- a/mobile/apps/auth/lib/store/code_store.dart+++ b/mobile/apps/auth/lib/store/code_store.dart@@ -97,6 +97,7 @@ class CodeStore {}code.generatedID = entity.generatedID;code.hasSynced = entity.hasSynced;+ code.createdAt = entity.createdAt;codes.add(code);_cacheCodes[code.generatedID!] = code;}diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dartindex b5b2165d35..a2e9904282 100644--- a/mobile/apps/auth/lib/ui/home_page.dart+++ b/mobile/apps/auth/lib/ui/home_page.dart@@ -1233,6 +1233,9 @@ class _HomePageState extends State<HomePage> {case CodeSortKey.manual:codes.sort((a, b) => a.display.position.compareTo(b.display.position));break;+ case CodeSortKey.newestFirst:+ codes.sort(_compareNewestFirst);+ break;}if (sortKey != CodeSortKey.manual) {int insertIndex = 0;@@ -1246,6 +1249,14 @@ class _HomePageState extends State<HomePage> {}}+ static int _compareNewestFirst(Code a, Code b) {+ final byCreatedAt = b.createdAt!.compareTo(a.createdAt!);+ if (byCreatedAt != 0) {+ return byCreatedAt;+ }+ return b.generatedID!.compareTo(a.generatedID!);+ }+bool get _shouldFocusAddedCode {if ((_showSearchBox && _searchText.isNotEmpty) ||selectedTag.isNotEmpty ||diff --git a/mobile/apps/auth/lib/ui/sort_option_menu.dart b/mobile/apps/auth/lib/ui/sort_option_menu.dartindex ad04e3302a..127c63066e 100644--- a/mobile/apps/auth/lib/ui/sort_option_menu.dart+++ b/mobile/apps/auth/lib/ui/sort_option_menu.dart@@ -16,6 +16,11 @@ class SortCodeMenuWidget extends StatelessWidget {final void Function(CodeSortKey) onSelected;final Color? iconColor;+ static final List<CodeSortKey> _menuOrder = [+ ...CodeSortKey.values.where((key) => key != CodeSortKey.manual),+ CodeSortKey.manual,+ ];+@overrideWidget build(BuildContext context) {final l10n = context.strings;@@ -53,7 +58,7 @@ class SortCodeMenuWidget extends StatelessWidget {content: MenuGroupComponent(showDividers: true,items: [- for (final key in CodeSortKey.values)+ for (final key in _menuOrder)MenuComponent(title: _labelFor(l10n, key),selected: key == currentKey,@@ -82,6 +87,7 @@ class SortCodeMenuWidget extends StatelessWidget {CodeSortKey.mostFrequentlyUsed => l10n.mostFrequentlyUsed,CodeSortKey.recentlyUsed => l10n.mostRecentlyUsed,CodeSortKey.manual => l10n.manualSort,+ CodeSortKey.newestFirst => l10n.sortNewestFirst,};}}