π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update save page
AmanRajSinghMouryaadb9943d8739
diff --git a/mobile/apps/locker/lib/ui/pages/save_page.dart b/mobile/apps/locker/lib/ui/pages/save_page.dartindex 7745e882a0..21f80c17fd 100644--- a/mobile/apps/locker/lib/ui/pages/save_page.dart+++ b/mobile/apps/locker/lib/ui/pages/save_page.dart@@ -4,15 +4,100 @@ import "package:ente_components/ente_components.dart";import 'package:flutter/material.dart';import 'package:hugeicons/hugeicons.dart';import 'package:locker/l10n/l10n.dart';-import 'package:locker/models/info/info_item.dart';import 'package:locker/ui/pages/account_credentials_page.dart';import 'package:locker/ui/pages/personal_note_page.dart';import 'package:locker/ui/pages/physical_records_page.dart';-import 'package:locker/utils/file_icon_utils.dart';-import 'package:locker/utils/info_item_utils.dart';enum SaveOptionType { document, note, physicalRecord, credentials }+class SaveOption {+ const SaveOption({+ required this.type,+ required this.icon,+ required this.title,+ required this.description,+ });++ final SaveOptionType type;+ final List<List<dynamic>> icon;+ final String title;+ final String description;+}++List<SaveOption> saveOptions(BuildContext context) {+ final l10n = context.l10n;+ return [+ SaveOption(+ type: SaveOptionType.document,+ icon: HugeIcons.strokeRoundedFile01,+ title: l10n.saveDocumentTitle,+ description: l10n.saveDocumentDescription,+ ),+ SaveOption(+ type: SaveOptionType.note,+ icon: HugeIcons.strokeRoundedNote,+ title: l10n.personalNote,+ description: l10n.personalNoteDescription,+ ),+ SaveOption(+ type: SaveOptionType.physicalRecord,+ icon: HugeIcons.strokeRoundedBriefcase04,+ title: l10n.physicalRecords,+ description: l10n.physicalRecordsDescription,+ ),+ SaveOption(+ type: SaveOptionType.credentials,+ icon: HugeIcons.strokeRoundedSquareLock01,+ title: l10n.accountCredentials,+ description: l10n.accountCredentialsDescription,+ ),+ ];+}++void handleSaveOption(+ BuildContext context,+ SaveOptionType type, {+ required Future<bool> Function() onUploadDocument,+ VoidCallback? onCancelWithoutSaving,+}) {+ switch (type) {+ case SaveOptionType.document:+ unawaited(+ onUploadDocument().then((didUpload) {+ if (!didUpload) {+ onCancelWithoutSaving?.call();+ }+ }),+ );+ return;+ case SaveOptionType.note:+ Navigator.of(context).push(+ MaterialPageRoute(+ builder: (context) =>+ PersonalNotePage(onCancelWithoutSaving: onCancelWithoutSaving),+ ),+ );+ break;+ case SaveOptionType.physicalRecord:+ Navigator.of(context).push(+ MaterialPageRoute(+ builder: (context) =>+ PhysicalRecordsPage(onCancelWithoutSaving: onCancelWithoutSaving),+ ),+ );+ break;+ case SaveOptionType.credentials:+ Navigator.of(context).push(+ MaterialPageRoute(+ builder: (context) => AccountCredentialsPage(+ onCancelWithoutSaving: onCancelWithoutSaving,+ ),+ ),+ );+ break;+ }+}+Future<void> showSaveBottomSheet(BuildContext context, {required Future<bool> Function() onUploadDocument,@@ -40,6 +125,7 @@ class SaveBottomSheet extends StatelessWidget {Widget build(BuildContext context) {final colors = context.componentColors;final maxHeight = MediaQuery.of(context).size.height * 0.75;+ final options = saveOptions(context);return BottomSheetComponent(title: context.l10n.saveToLocker,@@ -57,60 +143,14 @@ class SaveBottomSheet extends StatelessWidget {child: SingleChildScrollView(child: Column(children: [- _buildSaveOption(- context,- rootContext: rootContext,- icon: IconTile(- backgroundColor: colors.primaryLight,- icon: HugeIcon(- icon: HugeIcons.strokeRoundedFileUpload,- size: 20,- color: colors.primary,- ),- ),- title: context.l10n.saveDocumentTitle,- description: context.l10n.saveDocumentDescription,- type: SaveOptionType.document,- ),- const SizedBox(height: 16),- _buildSaveOption(- context,- rootContext: rootContext,- icon: InfoItemUtils.getInfoIcon(- context,- InfoType.note,- size: 20,- ),- title: context.l10n.personalNote,- description: context.l10n.personalNoteDescription,- type: SaveOptionType.note,- ),- const SizedBox(height: 16),- _buildSaveOption(- context,- rootContext: rootContext,- icon: InfoItemUtils.getInfoIcon(- context,- InfoType.physicalRecord,- size: 20,- ),- title: context.l10n.physicalRecords,- description: context.l10n.physicalRecordsDescription,- type: SaveOptionType.physicalRecord,- ),- const SizedBox(height: 16),- _buildSaveOption(- context,- rootContext: rootContext,- icon: InfoItemUtils.getInfoIcon(+ for (var i = 0; i < options.length; i++) ...[+ if (i > 0) const SizedBox(height: 16),+ _buildSaveOption(context,- InfoType.accountCredential,- size: 20,+ rootContext: rootContext,+ option: options[i],),- title: context.l10n.accountCredentials,- description: context.l10n.accountCredentialsDescription,- type: SaveOptionType.credentials,- ),+ ],],),),@@ -123,23 +163,20 @@ class SaveBottomSheet extends StatelessWidget {Widget _buildSaveOption(BuildContext sheetContext, {required BuildContext rootContext,- required Widget icon,- required String title,- required String description,- required SaveOptionType type,+ required SaveOption option,}) {final colors = sheetContext.componentColors;return MenuComponent(- title: title,- subtitle: description,+ title: option.title,+ subtitle: option.description,subtitleMaxLines: 2,- leading: icon,+ leading: HugeIcon(icon: option.icon, size: 20, color: colors.primary),trailing: Icon(Icons.chevron_right, color: colors.textBase),onTap: () {Navigator.of(sheetContext).pop();// Push the form route after the sheet has dismissed to avoid UI jank.WidgetsBinding.instance.addPostFrameCallback((_) {- _handleSaveOption(rootContext, type);+ _handleSaveOption(rootContext, option.type);});},);@@ -159,40 +196,11 @@ class SaveBottomSheet extends StatelessWidget {});}- switch (type) {- case SaveOptionType.document:- unawaited(- onUploadDocument().then((didUpload) {- if (!didUpload) {- reopenSheet();- }- }),- );- return;- case SaveOptionType.note:- Navigator.of(context).push(- MaterialPageRoute(- builder: (context) =>- PersonalNotePage(onCancelWithoutSaving: reopenSheet),- ),- );- break;- case SaveOptionType.physicalRecord:- Navigator.of(context).push(- MaterialPageRoute(- builder: (context) =>- PhysicalRecordsPage(onCancelWithoutSaving: reopenSheet),- ),- );- break;- case SaveOptionType.credentials:- Navigator.of(context).push(- MaterialPageRoute(- builder: (context) =>- AccountCredentialsPage(onCancelWithoutSaving: reopenSheet),- ),- );- break;- }+ handleSaveOption(+ context,+ type,+ onUploadDocument: onUploadDocument,+ onCancelWithoutSaving: reopenSheet,+ );}}