π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] Show sort option on home screen
Neeraj Gupta1644b1cd89d3
diff --git a/auth/lib/l10n/arb/app_en.arb b/auth/lib/l10n/arb/app_en.arbindex b5f7121ff6..c9776fc9f5 100644--- a/auth/lib/l10n/arb/app_en.arb+++ b/auth/lib/l10n/arb/app_en.arb@@ -328,6 +328,9 @@}}},+ "manualSort": "Custom",+ "mostFrequentlyUsed": "Frequently used",+ "mostRecentlyUsed": "Recently used","activeSessions": "Active sessions","somethingWentWrongPleaseTryAgain": "Something went wrong, please try again","thisWillLogYouOutOfThisDevice": "This will log you out of this device!",diff --git a/auth/lib/services/preference_service.dart b/auth/lib/services/preference_service.dartindex ba43e69be3..46c46787c8 100644--- a/auth/lib/services/preference_service.dart+++ b/auth/lib/services/preference_service.dart@@ -2,6 +2,14 @@ import 'package:ente_auth/core/event_bus.dart';import 'package:ente_auth/events/icons_changed_event.dart';import 'package:shared_preferences/shared_preferences.dart';+enum CodeSortKey {+ issuerName,+ accountName,+ mostFrequentlyUsed,+ leastRecentlyUsed,+ manual,+}+class PreferenceService {PreferenceService._privateConstructor();static final PreferenceService instance =diff --git a/auth/lib/ui/components/buttons/icon_button_widget.dart b/auth/lib/ui/components/buttons/icon_button_widget.dartindex eb5554318e..d57438ee61 100644--- a/auth/lib/ui/components/buttons/icon_button_widget.dart+++ b/auth/lib/ui/components/buttons/icon_button_widget.dart@@ -16,7 +16,7 @@ class IconButtonWidget extends StatefulWidget {final Color? defaultColor;final Color? pressedColor;final Color? iconColor;- const IconButtonWidget({+const IconButtonWidget({super.key,required this.icon,required this.iconButtonType,diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dartindex f091e67307..a06f4a924f 100644--- a/auth/lib/ui/home_page.dart+++ b/auth/lib/ui/home_page.dart@@ -31,6 +31,7 @@ import 'package:ente_auth/ui/home/speed_dial_label_widget.dart';import 'package:ente_auth/ui/reorder_codes_page.dart';import 'package:ente_auth/ui/scanner_page.dart';import 'package:ente_auth/ui/settings_page.dart';+import 'package:ente_auth/ui/sort_option_menu.dart';import 'package:ente_auth/ui/tools/app_lock.dart';import 'package:ente_auth/utils/dialog_util.dart';import 'package:ente_auth/utils/platform_util.dart';@@ -358,13 +359,17 @@ class _HomePageState extends State<HomePage> {),centerTitle: PlatformUtil.isDesktop() ? false : true,actions: <Widget>[- IconButton(- icon: const Icon(Icons.edit),- tooltip: l10n.edit,- onPressed: () {- navigateToReorderPage(_allCodes!);- },+ SortCodeMenuWidget(+ currentKey: CodeSortKey.accountName,+ onSelected: (p0) => {},),+ // IconButton(+ // icon: const Icon(Icons.edit),+ // tooltip: l10n.edit,+ // onPressed: () {+ // navigateToReorderPage(_allCodes!);+ // },+ // ),PlatformUtil.isDesktop()? IconButton(icon: const Icon(Icons.lock),diff --git a/auth/lib/ui/sort_option_menu.dart b/auth/lib/ui/sort_option_menu.dartnew file mode 100644index 0000000000..1cdc8515a2--- /dev/null+++ b/auth/lib/ui/sort_option_menu.dart@@ -0,0 +1,80 @@+import 'package:ente_auth/l10n/l10n.dart';+import 'package:ente_auth/services/preference_service.dart';+import 'package:ente_auth/theme/ente_theme.dart';+import 'package:ente_auth/ui/components/buttons/icon_button_widget.dart';+import 'package:flutter/material.dart';+import 'package:flutter/widgets.dart';++class SortCodeMenuWidget extends StatelessWidget {+ final CodeSortKey currentKey;+ final void Function(CodeSortKey) onSelected;+ const SortCodeMenuWidget({+ super.key,+ required this.currentKey,+ required this.onSelected,+ });++ @override+ Widget build(BuildContext context) {+ Text sortOptionText(CodeSortKey key) {+ String text = key.toString();+ switch (key) {+ case CodeSortKey.issuerName:+ text = context.l10n.codeIssuerHint;+ break;+ case CodeSortKey.accountName:+ text = context.l10n.account;+ break;+ case CodeSortKey.mostFrequentlyUsed:+ text = context.l10n.mostFrequentlyUsed;+ break;+ case CodeSortKey.leastRecentlyUsed:+ text = context.l10n.mostRecentlyUsed;+ break;+ case CodeSortKey.manual:+ text = context.l10n.manualSort;+ }+ return Text(+ text,+ style: Theme.of(context).textTheme.titleMedium!.copyWith(+ fontSize: 14,+ color: Theme.of(context).iconTheme.color!.withOpacity(0.7),+ ),+ );+ }++ return GestureDetector(+ onTapDown: (TapDownDetails details) async {+ final int? selectedValue = await showMenu<int>(+ context: context,+ position: RelativeRect.fromLTRB(+ details.globalPosition.dx,+ details.globalPosition.dy,+ details.globalPosition.dx,+ details.globalPosition.dy + 300,+ ),+ items: List.generate(CodeSortKey.values.length, (index) {+ return PopupMenuItem(+ value: index,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ sortOptionText(CodeSortKey.values[index]),+ if (CodeSortKey.values[index] == currentKey)+ Icon(+ Icons.check,+ color: Theme.of(context).iconTheme.color,+ ),+ ],+ ),+ );+ }),+ );+ if (selectedValue != null) {+ onSelected(CodeSortKey.values[selectedValue]);+ }+ },+ child: const Icon(Icons.sort_outlined),+ );+ }+}