Skip to content

armgit / ente

Public Imported from GitHub
0

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

Extract openLegacyPage to reusable utility

ashilkn6f53bbef29e0
diff --git a/mobile/apps/locker/lib/ui/components/legacy_collections_trash_widget.dart b/mobile/apps/locker/lib/ui/components/legacy_collections_trash_widget.dart
index 1dac46eaa1..046ac752a5 100644
--- a/mobile/apps/locker/lib/ui/components/legacy_collections_trash_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/legacy_collections_trash_widget.dart
@@ -1,14 +1,11 @@
-import "package:ente_legacy/pages/emergency_page.dart";
-import "package:ente_lock_screen/local_authentication_service.dart";
import "package:ente_ui/theme/ente_theme.dart";
-import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:locker/l10n/l10n.dart";
-import "package:locker/services/configuration.dart";
import "package:locker/services/trash/trash_service.dart";
import "package:locker/ui/pages/all_collections_page.dart";
import "package:locker/ui/pages/trash_page.dart";
+import "package:locker/ui/utils/legacy_utils.dart";
class LegacyCollectionsTrashWidget extends StatelessWidget {
const LegacyCollectionsTrashWidget({super.key});
@@ -153,7 +150,7 @@ class LegacyCollectionsTrashWidget extends StatelessWidget {
final borderRadius = BorderRadius.circular(20);
return InkWell(
- onTap: () => _openLegacy(context),
+ onTap: () => openLegacyPage(context),
borderRadius: borderRadius,
child: Container(
decoration: BoxDecoration(
@@ -203,21 +200,4 @@ class LegacyCollectionsTrashWidget extends StatelessWidget {
),
);
}
-
- Future<void> _openLegacy(BuildContext context) async {
- final hasAuthenticated = kDebugMode ||
- await LocalAuthenticationService.instance.requestLocalAuthentication(
- context,
- "Authenticate to manage legacy contacts",
- );
- if (hasAuthenticated && context.mounted) {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return EmergencyPage(config: Configuration.instance);
- },
- ),
- );
- }
- }
}
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index 963b03d367..2a9bab4879 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -20,6 +20,7 @@ import 'package:locker/ui/mixins/search_mixin.dart';
import 'package:locker/ui/pages/save_page.dart';
import "package:locker/ui/pages/settings_page.dart";
import 'package:locker/ui/pages/uploader_page.dart';
+import "package:locker/ui/utils/legacy_utils.dart";
import 'package:locker/utils/collection_sort_util.dart';
import 'package:logging/logging.dart';
@@ -88,7 +89,26 @@ class CustomLockerAppBar extends StatelessWidget
'assets/locker-logo.png',
height: 28,
),
- const SizedBox(width: 48),
+ Align(
+ alignment: Alignment.centerRight,
+ child: InkWell(
+ onTap: () => openLegacyPage(context),
+ borderRadius: BorderRadius.circular(8),
+ child: Container(
+ width: 32,
+ height: 32,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(8),
+ color: Colors.white,
+ ),
+ child: Icon(
+ Icons.favorite_rounded,
+ color: colorScheme.primary700,
+ size: 20,
+ ),
+ ),
+ ),
+ ),
],
),
),
diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
new file mode 100644
index 0000000000..e3b2db1555
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
@@ -0,0 +1,27 @@
+// ignore_for_file: use_build_context_synchronously
+
+import "package:ente_legacy/pages/emergency_page.dart";
+import "package:ente_lock_screen/local_authentication_service.dart";
+import "package:flutter/foundation.dart";
+import "package:flutter/material.dart";
+import "package:locker/services/configuration.dart";
+
+/// Opens the Legacy (Emergency contacts) page after authenticating the user.
+///
+/// In debug mode, authentication is bypassed.
+Future<void> openLegacyPage(BuildContext context) async {
+ final hasAuthenticated = kDebugMode ||
+ await LocalAuthenticationService.instance.requestLocalAuthentication(
+ context,
+ "Authenticate to manage legacy contacts",
+ );
+ if (hasAuthenticated && context.mounted) {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return EmergencyPage(config: Configuration.instance);
+ },
+ ),
+ );
+ }
+}