From 621eef0edc66ac742e9ddf001465ae5831e47919 Mon Sep 17 00:00:00 2001 From: waclaw66 Date: Fri, 3 Nov 2023 22:00:55 +0100 Subject: [PATCH] feat(mobile): share assets from album (#4821) * share from album * fix case * enhance conditional array items --- mobile/assets/i18n/en-US.json | 1 + .../modules/album/ui/album_viewer_appbar.dart | 69 +++++++++++++++---- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/mobile/assets/i18n/en-US.json b/mobile/assets/i18n/en-US.json index 4a77aac1c2..69700269ce 100644 --- a/mobile/assets/i18n/en-US.json +++ b/mobile/assets/i18n/en-US.json @@ -23,6 +23,7 @@ "album_viewer_appbar_share_err_title": "Failed to change album title", "album_viewer_appbar_share_leave": "Leave album", "album_viewer_appbar_share_remove": "Remove from album", + "album_viewer_appbar_share_to": "Share To", "album_viewer_page_share_add_users": "Add users", "all_people_page_title": "People", "all_videos_page_title": "Videos", diff --git a/mobile/lib/modules/album/ui/album_viewer_appbar.dart b/mobile/lib/modules/album/ui/album_viewer_appbar.dart index f369a35d13..221603ed90 100644 --- a/mobile/lib/modules/album/ui/album_viewer_appbar.dart +++ b/mobile/lib/modules/album/ui/album_viewer_appbar.dart @@ -7,6 +7,8 @@ import 'package:immich_mobile/modules/album/providers/album.provider.dart'; import 'package:immich_mobile/modules/album/providers/album_detail.provider.dart'; import 'package:immich_mobile/modules/album/providers/album_viewer.provider.dart'; import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart'; +import 'package:immich_mobile/shared/ui/share_dialog.dart'; +import 'package:immich_mobile/shared/services/share.service.dart'; import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/shared/models/album.dart'; import 'package:immich_mobile/shared/models/asset.dart'; @@ -160,40 +162,77 @@ class AlbumViewerAppbar extends HookConsumerWidget ImmichLoadingOverlayController.appLoader.hide(); } - buildBottomSheetActionButton() { + void handleShareAssets( + WidgetRef ref, + BuildContext context, + Set selection, + ) { + showDialog( + context: context, + builder: (BuildContext buildContext) { + ref.watch(shareServiceProvider).shareAssets(selection.toList()).then( + (bool status) { + if (!status) { + ImmichToast.show( + context: context, + msg: 'image_viewer_page_state_provider_share_error'.tr(), + toastType: ToastType.error, + gravity: ToastGravity.BOTTOM, + ); + } + Navigator.of(buildContext).pop(); + }, + ); + return const ShareDialog(); + }, + barrierDismissible: false, + ); + } + + void onShareAssetsTo() async { + ImmichLoadingOverlayController.appLoader.show(); + handleShareAssets(ref, context, selected); + ImmichLoadingOverlayController.appLoader.hide(); + } + + buildBottomSheetActions() { if (selected.isNotEmpty) { - if (album.ownerId == userId) { - return ListTile( + return [ + ListTile( + leading: const Icon(Icons.ios_share_rounded), + title: const Text( + 'album_viewer_appbar_share_to', + style: TextStyle(fontWeight: FontWeight.bold), + ).tr(), + onTap: () => onShareAssetsTo(), + ), + album.ownerId == userId ? ListTile( leading: const Icon(Icons.delete_sweep_rounded), title: const Text( 'album_viewer_appbar_share_remove', style: TextStyle(fontWeight: FontWeight.bold), ).tr(), onTap: () => onRemoveFromAlbumPressed(), - ); - } else { - return const SizedBox(); - } + ) : const SizedBox(), + ]; } else { - if (album.ownerId == userId) { - return ListTile( + return [ + album.ownerId == userId ? ListTile( leading: const Icon(Icons.delete_forever_rounded), title: const Text( 'album_viewer_appbar_share_delete', style: TextStyle(fontWeight: FontWeight.bold), ).tr(), onTap: () => onDeleteAlbumPressed(), - ); - } else { - return ListTile( + ) : ListTile( leading: const Icon(Icons.person_remove_rounded), title: const Text( 'album_viewer_appbar_share_leave', style: TextStyle(fontWeight: FontWeight.bold), ).tr(), onTap: () => onLeaveAlbumPressed(), - ); - } + ), + ]; } } @@ -257,7 +296,7 @@ class AlbumViewerAppbar extends HookConsumerWidget child: Column( mainAxisSize: MainAxisSize.min, children: [ - buildBottomSheetActionButton(), + ...buildBottomSheetActions(), if (selected.isEmpty && onAddPhotos != null) ...commonActions, if (selected.isEmpty && onAddPhotos != null &&