Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[auth] Show sorting menu on home screen

Neeraj Guptac99a465c85a7
diff --git a/auth/lib/services/preference_service.dart b/auth/lib/services/preference_service.dart
index 46c46787c8..218eb4ffa3 100644
--- a/auth/lib/services/preference_service.dart
+++ b/auth/lib/services/preference_service.dart
@@ -6,7 +6,7 @@ enum CodeSortKey {
issuerName,
accountName,
mostFrequentlyUsed,
- leastRecentlyUsed,
+ recentlyUsed,
manual,
}
@@ -36,6 +36,15 @@ class PreferenceService {
}
}
+ CodeSortKey codeSortKey() {
+ return CodeSortKey
+ .values[_prefs.getInt("codeSortKey") ?? CodeSortKey.manual.index];
+ }
+
+ Future<void> setCodeSortKey(CodeSortKey key) async {
+ await _prefs.setInt("codeSortKey", key.index);
+ }
+
Future<void> setHasShownCoachMark(bool value) {
return _prefs.setBool(kHasShownCoachMarkKey, value);
}
diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart
index a06f4a924f..445c8bb180 100644
--- a/auth/lib/ui/home_page.dart
+++ b/auth/lib/ui/home_page.dart
@@ -83,11 +83,13 @@ class _HomePageState extends State<HomePage> {
bool _isFavouriteOpen = false;
bool hasFavouriteCodes = false;
bool hasNonFavouriteCodes = false;
+ late CodeSortKey _codeSortKey;
@override
void initState() {
super.initState();
_textController.addListener(_applyFilteringAndRefresh);
+ _codeSortKey = PreferenceService.instance.codeSortKey();
_loadCodes();
_streamSubscription = Bus.instance.on<CodesUpdatedEvent>().listen((event) {
_loadCodes();
@@ -96,6 +98,7 @@ class _HomePageState extends State<HomePage> {
Bus.instance.on<TriggerLogoutEvent>().listen((event) async {
await autoLogoutAlert(context);
});
+
_initDeepLinks();
Future.delayed(
const Duration(seconds: 1),
@@ -220,8 +223,7 @@ class _HomePageState extends State<HomePage> {
[];
}
- _filteredCodes
- .sort((a, b) => a.display.position.compareTo(b.display.position));
+ sortFilteredCodes(_filteredCodes, _codeSortKey);
if (mounted) {
setState(() {});
@@ -240,6 +242,28 @@ class _HomePageState extends State<HomePage> {
super.dispose();
}
+ void sortFilteredCodes(List<Code> codes, CodeSortKey sortKey) {
+ switch (sortKey) {
+ case CodeSortKey.issuerName:
+ codes.sort((a, b) => a.issuer.compareTo(b.issuer));
+ break;
+ case CodeSortKey.accountName:
+ codes.sort((a, b) => a.account.compareTo(b.account));
+ break;
+ case CodeSortKey.mostFrequentlyUsed:
+ codes.sort((a, b) => b.display.tapCount.compareTo(a.display.tapCount));
+ break;
+ case CodeSortKey.recentlyUsed:
+ codes.sort(
+ (a, b) => b.display.lastUsedAt.compareTo(a.display.lastUsedAt));
+ break;
+ case CodeSortKey.manual:
+ default:
+ codes.sort((a, b) => a.display.position.compareTo(b.display.position));
+ break;
+ }
+ }
+
Future<void> _redirectToScannerPage() async {
final Code? code = await Navigator.of(context).push(
MaterialPageRoute(
@@ -360,16 +384,21 @@ class _HomePageState extends State<HomePage> {
centerTitle: PlatformUtil.isDesktop() ? false : true,
actions: <Widget>[
SortCodeMenuWidget(
- currentKey: CodeSortKey.accountName,
- onSelected: (p0) => {},
+ currentKey: PreferenceService.instance.codeSortKey(),
+ onSelected: (p0) async {
+ await PreferenceService.instance.setCodeSortKey(p0);
+
+ if (p0 == CodeSortKey.manual) {
+ await navigateToReorderPage(_allCodes!);
+ }
+ setState(() {
+ _codeSortKey = p0;
+ });
+ if (mounted) {
+ _applyFilteringAndRefresh();
+ }
+ },
),
- // 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/reorder_codes_page.dart b/auth/lib/ui/reorder_codes_page.dart
index 3ba6160a23..f7d35c401d 100644
--- a/auth/lib/ui/reorder_codes_page.dart
+++ b/auth/lib/ui/reorder_codes_page.dart
@@ -34,7 +34,7 @@ class _ReorderCodesPageState extends State<ReorderCodesPage> {
},
child: Scaffold(
appBar: AppBar(
- title: const Text("Edit Codes"),
+ title: const Text("Custom order"),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () async {
@@ -44,66 +44,6 @@ class _ReorderCodesPageState extends State<ReorderCodesPage> {
}
},
),
- actions: [
- PopupMenuButton(
- icon: const Icon(Icons.sort),
- onSelected: (int value) {
- selectedSortOption = value;
- switch (value) {
- case 0:
- sortByIssuer();
- break;
- case 1:
- sortByAccount();
- break;
- case 2:
- setState(() {});
- break;
- }
- },
- itemBuilder: (context) => [
- PopupMenuItem(
- value: 0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- selectedSortOption == 0
- ? const Icon(Icons.check)
- : const SizedBox.square(dimension: 24),
- const SizedBox(width: 10),
- const Text("Issuer"),
- ],
- ),
- ),
- PopupMenuItem(
- value: 1,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- selectedSortOption == 1
- ? const Icon(Icons.check)
- : const SizedBox.square(dimension: 24),
- const SizedBox(width: 10),
- const Text("Account"),
- ],
- ),
- ),
- PopupMenuItem(
- value: 2,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- selectedSortOption == 2
- ? const Icon(Icons.check)
- : const SizedBox.square(dimension: 24),
- const SizedBox(width: 10),
- const Text("Manual"),
- ],
- ),
- ),
- ],
- ),
- ],
),
body: ReorderableListView(
buildDefaultDragHandles: false,
@@ -158,14 +98,4 @@ class _ReorderCodesPageState extends State<ReorderCodesPage> {
widget.codes.insert(newIndex, code);
});
}
-
- void sortByIssuer() {
- widget.codes.sort((a, b) => a.issuer.compareTo(b.issuer));
- setState(() {});
- }
-
- void sortByAccount() {
- widget.codes.sort((a, b) => a.account.compareTo(b.account));
- setState(() {});
- }
}
diff --git a/auth/lib/ui/sort_option_menu.dart b/auth/lib/ui/sort_option_menu.dart
index 1cdc8515a2..afc57515eb 100644
--- a/auth/lib/ui/sort_option_menu.dart
+++ b/auth/lib/ui/sort_option_menu.dart
@@ -1,7 +1,5 @@
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';
@@ -28,7 +26,7 @@ class SortCodeMenuWidget extends StatelessWidget {
case CodeSortKey.mostFrequentlyUsed:
text = context.l10n.mostFrequentlyUsed;
break;
- case CodeSortKey.leastRecentlyUsed:
+ case CodeSortKey.recentlyUsed:
text = context.l10n.mostRecentlyUsed;
break;
case CodeSortKey.manual: