π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Refractor code
Aman Raj Singh Mourya2a0c7d1e56f8
diff --git a/mobile/lib/ui/tabs/shared/empty_state.dart b/mobile/lib/ui/tabs/shared/empty_state.dartindex 97f88b88f5..b69d64b96d 100644--- a/mobile/lib/ui/tabs/shared/empty_state.dart+++ b/mobile/lib/ui/tabs/shared/empty_state.dart@@ -1,66 +1,19 @@import "package:flutter/material.dart";-import "package:intl/intl.dart";-import "package:logging/logging.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/tab_changed_event.dart";import "package:photos/generated/l10n.dart";-import "package:photos/models/collection/collection.dart";-import "package:photos/models/collection/collection_items.dart";-import "package:photos/services/collections_service.dart";import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/collections/collection_action_sheet.dart';import 'package:photos/ui/components/buttons/button_widget.dart';import "package:photos/ui/components/empty_state_item_widget.dart";import "package:photos/ui/components/models/button_type.dart";-import "package:photos/ui/viewer/gallery/collection_page.dart";-import "package:photos/utils/dialog_util.dart";-import "package:photos/utils/navigation_util.dart";+import "package:photos/utils/collection_util.dart";import "package:photos/utils/share_util.dart";import "package:photos/utils/toast_util.dart";class SharedEmptyStateWidget extends StatelessWidget {const SharedEmptyStateWidget({super.key});- Future<void> _onTapCollectEventPhotos(BuildContext context) async {- final String currentDate =- DateFormat('MMMM d, yyyy').format(DateTime.now());- final result = await showTextInputDialog(- context,- title: "Name the album",- submitButtonLabel: S.of(context).create,- hintText: S.of(context).enterAlbumName,- alwaysShowSuccessState: false,- initialValue: currentDate,- textCapitalization: TextCapitalization.words,- onSubmit: (String text) async {- // indicates user cancelled the rename request- if (text.trim() == "") {- return;- }-- try {- final Collection c =- await CollectionsService.instance.createAlbum(text);- // ignore: unawaited_futures- routeToPage(- context,- CollectionPage(- isFromCollectPhotos: true,- CollectionWithThumbnail(c, null),- ),- );- } catch (e, s) {- Logger("Collect event photos from CollectPhotosCardWidget")- .severe("Failed to rename album", e, s);- rethrow;- }- },- );- if (result is Exception) {- await showGenericErrorDialog(context: context, error: result);- }- }-@overrideWidget build(BuildContext context) {final textTheme = getEnteTextTheme(context);@@ -128,7 +81,7 @@ class SharedEmptyStateWidget extends StatelessWidget {labelText: S.of(context).collectEventPhotos,icon: Icons.add_photo_alternate_outlined,onTap: () async {- await _onTapCollectEventPhotos(context);+ await onTapCollectEventPhotos(context);},),const SizedBox(height: 6),diff --git a/mobile/lib/ui/viewer/gallery/collect_photos_card_widget.dart b/mobile/lib/ui/viewer/gallery/collect_photos_card_widget.dartindex 888b18da5b..46e816b407 100644--- a/mobile/lib/ui/viewer/gallery/collect_photos_card_widget.dart+++ b/mobile/lib/ui/viewer/gallery/collect_photos_card_widget.dart@@ -1,17 +1,9 @@import "package:figma_squircle/figma_squircle.dart";import 'package:flutter/material.dart';-import "package:intl/intl.dart";-import "package:logging/logging.dart";-import "package:photos/generated/l10n.dart";-import "package:photos/models/collection/collection.dart";-import "package:photos/models/collection/collection_items.dart";-import "package:photos/services/collections_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/buttons/button_widget.dart";import "package:photos/ui/components/models/button_type.dart";-import "package:photos/ui/viewer/gallery/collection_page.dart";-import "package:photos/utils/dialog_util.dart";-import "package:photos/utils/navigation_util.dart";+import "package:photos/utils/collection_util.dart";class CollectPhotosCardWidget extends StatefulWidget {const CollectPhotosCardWidget({super.key});@@ -22,46 +14,6 @@ class CollectPhotosCardWidget extends StatefulWidget {}class _CollectPhotosCardWidgetState extends State<CollectPhotosCardWidget> {- Future<void> _onTapCreateAlbum() async {- final String currentDate =- DateFormat('MMMM d, yyyy').format(DateTime.now());- final result = await showTextInputDialog(- context,- title: "Name the album",- submitButtonLabel: S.of(context).create,- hintText: S.of(context).enterAlbumName,- alwaysShowSuccessState: false,- initialValue: currentDate,- textCapitalization: TextCapitalization.words,- onSubmit: (String text) async {- // indicates user cancelled the rename request- if (text.trim() == "") {- return;- }-- try {- final Collection c =- await CollectionsService.instance.createAlbum(text);- // ignore: unawaited_futures- routeToPage(- context,- CollectionPage(- isFromCollectPhotos: true,- CollectionWithThumbnail(c, null),- ),- );- } catch (e, s) {- Logger("CollectPhotosCardWidget")- .severe("Failed to rename album", e, s);- rethrow;- }- },- );- if (result is Exception) {- await showGenericErrorDialog(context: context, error: result);- }- }-@overrideWidget build(BuildContext context) {final textTheme = getEnteTextTheme(context);@@ -94,7 +46,7 @@ class _CollectPhotosCardWidgetState extends State<CollectPhotosCardWidget> {),),GestureDetector(- onTap: () => _onTapCreateAlbum(),+ onTap: () => onTapCollectEventPhotos(context),child: Padding(padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),child: Container(@@ -144,7 +96,7 @@ class _CollectPhotosCardWidgetState extends State<CollectPhotosCardWidget> {icon: Icons.add_photo_alternate_outlined,shouldShowSuccessConfirmation: false,shouldSurfaceExecutionStates: false,- onTap: () => _onTapCreateAlbum(),+ onTap: () => onTapCollectEventPhotos(context),),],),diff --git a/mobile/lib/utils/collection_util.dart b/mobile/lib/utils/collection_util.dartnew file mode 100644index 0000000000..0190c10624--- /dev/null+++ b/mobile/lib/utils/collection_util.dart@@ -0,0 +1,49 @@+import "package:flutter/material.dart";+import "package:intl/intl.dart";+import "package:logging/logging.dart";+import "package:photos/generated/l10n.dart";+import "package:photos/models/collection/collection.dart";+import "package:photos/models/collection/collection_items.dart";+import "package:photos/services/collections_service.dart";+import "package:photos/ui/viewer/gallery/collection_page.dart";+import "package:photos/utils/dialog_util.dart";+import "package:photos/utils/navigation_util.dart";++Future<void> onTapCollectEventPhotos(BuildContext context) async {+ final String currentDate = DateFormat('MMMM d, yyyy').format(DateTime.now());+ final result = await showTextInputDialog(+ context,+ title: "Name the album",+ submitButtonLabel: S.of(context).create,+ hintText: S.of(context).enterAlbumName,+ alwaysShowSuccessState: false,+ initialValue: currentDate,+ textCapitalization: TextCapitalization.words,+ onSubmit: (String text) async {+ // indicates user cancelled the rename request+ if (text.trim() == "") {+ return;+ }++ try {+ final Collection c =+ await CollectionsService.instance.createAlbum(text);+ // ignore: unawaited_futures+ routeToPage(+ context,+ CollectionPage(+ isFromCollectPhotos: true,+ CollectionWithThumbnail(c, null),+ ),+ );+ } catch (e, s) {+ Logger("Collect event photos from CollectPhotosCardWidget")+ .severe("Failed to rename album", e, s);+ rethrow;+ }+ },+ );+ if (result is Exception) {+ await showGenericErrorDialog(context: context, error: result);+ }+}