2022-04-24 04:08:45 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-06 17:46:26 +02:00
|
|
|
import 'package:immich_mobile/modules/activities/providers/activity.provider.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
2023-08-02 03:29:14 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album_detail.provider.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album_viewer.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
2023-11-03 23:00:55 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/share_dialog.dart';
|
|
|
|
import 'package:immich_mobile/shared/services/share.service.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2023-05-17 19:36:02 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
|
|
|
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
|
|
|
|
|
2023-05-12 16:21:13 +02:00
|
|
|
class AlbumViewerAppbar extends HookConsumerWidget
|
|
|
|
implements PreferredSizeWidget {
|
2022-04-24 04:08:45 +02:00
|
|
|
const AlbumViewerAppbar({
|
|
|
|
Key? key,
|
2023-02-06 09:13:32 +02:00
|
|
|
required this.album,
|
2022-04-24 04:08:45 +02:00
|
|
|
required this.userId,
|
2023-05-17 19:36:02 +02:00
|
|
|
required this.selected,
|
|
|
|
required this.selectionDisabled,
|
|
|
|
required this.titleFocusNode,
|
2023-06-29 23:11:56 +02:00
|
|
|
this.onAddPhotos,
|
|
|
|
this.onAddUsers,
|
2023-11-06 17:46:26 +02:00
|
|
|
required this.onActivities,
|
2022-08-03 07:04:34 +02:00
|
|
|
}) : super(key: key);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
final Album album;
|
2022-04-24 04:08:45 +02:00
|
|
|
final String userId;
|
2023-05-17 19:36:02 +02:00
|
|
|
final Set<Asset> selected;
|
|
|
|
final void Function() selectionDisabled;
|
|
|
|
final FocusNode titleFocusNode;
|
2023-06-29 23:11:56 +02:00
|
|
|
final Function(Album album)? onAddPhotos;
|
|
|
|
final Function(Album album)? onAddUsers;
|
2023-11-06 17:46:26 +02:00
|
|
|
final Function(Album album) onActivities;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-04-29 06:46:37 +02:00
|
|
|
final newAlbumTitle = ref.watch(albumViewerProvider).editTitleText;
|
|
|
|
final isEditAlbum = ref.watch(albumViewerProvider).isEditAlbum;
|
2023-11-06 17:46:26 +02:00
|
|
|
final comments = album.shared
|
|
|
|
? ref.watch(
|
|
|
|
activityStatisticsStateProvider(
|
|
|
|
(albumId: album.remoteId!, assetId: null),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: 0;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2023-08-18 06:26:12 +02:00
|
|
|
deleteAlbum() async {
|
2022-04-24 04:08:45 +02:00
|
|
|
ImmichLoadingOverlayController.appLoader.show();
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
final bool success;
|
|
|
|
if (album.shared) {
|
|
|
|
success =
|
|
|
|
await ref.watch(sharedAlbumProvider.notifier).deleteAlbum(album);
|
|
|
|
AutoRouter.of(context)
|
|
|
|
.navigate(const TabControllerRoute(children: [SharingRoute()]));
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
2023-03-04 00:38:30 +02:00
|
|
|
success = await ref.watch(albumProvider.notifier).deleteAlbum(album);
|
|
|
|
AutoRouter.of(context)
|
|
|
|
.navigate(const TabControllerRoute(children: [LibraryRoute()]));
|
|
|
|
}
|
|
|
|
if (!success) {
|
2022-04-24 04:08:45 +02:00
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2022-07-07 20:40:54 +02:00
|
|
|
msg: "album_viewer_appbar_share_err_delete".tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmichLoadingOverlayController.appLoader.hide();
|
|
|
|
}
|
|
|
|
|
2023-08-18 06:26:12 +02:00
|
|
|
Future<void> showConfirmationDialog() async {
|
|
|
|
return showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false, // user must tap button!
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: const Text('Delete album'),
|
|
|
|
content: const Text(
|
|
|
|
'Are you sure you want to delete this album from your account?',
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context, 'Cancel'),
|
|
|
|
child: Text(
|
|
|
|
'Cancel',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, 'Confirm');
|
|
|
|
deleteAlbum();
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'Confirm',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
|
|
|
? Colors.red
|
|
|
|
: Colors.red[300],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDeleteAlbumPressed() async {
|
|
|
|
showConfirmationDialog();
|
|
|
|
}
|
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
void onLeaveAlbumPressed() async {
|
2022-04-24 04:08:45 +02:00
|
|
|
ImmichLoadingOverlayController.appLoader.show();
|
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
bool isSuccess =
|
2023-02-06 09:13:32 +02:00
|
|
|
await ref.watch(sharedAlbumProvider.notifier).leaveAlbum(album);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
if (isSuccess) {
|
2022-06-22 07:23:35 +02:00
|
|
|
AutoRouter.of(context)
|
|
|
|
.navigate(const TabControllerRoute(children: [SharingRoute()]));
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
|
|
|
Navigator.pop(context);
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2022-07-07 20:40:54 +02:00
|
|
|
msg: "album_viewer_appbar_share_err_leave".tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmichLoadingOverlayController.appLoader.hide();
|
|
|
|
}
|
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
void onRemoveFromAlbumPressed() async {
|
2022-04-24 04:08:45 +02:00
|
|
|
ImmichLoadingOverlayController.appLoader.show();
|
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
bool isSuccess =
|
|
|
|
await ref.watch(sharedAlbumProvider.notifier).removeAssetFromAlbum(
|
2023-02-06 09:13:32 +02:00
|
|
|
album,
|
2023-05-17 19:36:02 +02:00
|
|
|
selected,
|
2022-06-22 07:23:35 +02:00
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
Navigator.pop(context);
|
2023-05-17 19:36:02 +02:00
|
|
|
selectionDisabled();
|
2023-01-29 05:57:13 +02:00
|
|
|
ref.watch(albumProvider.notifier).getAllAlbums();
|
2023-08-02 03:29:14 +02:00
|
|
|
ref.invalidate(albumDetailProvider(album.id));
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
|
|
|
Navigator.pop(context);
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2022-07-07 20:40:54 +02:00
|
|
|
msg: "album_viewer_appbar_share_err_remove".tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmichLoadingOverlayController.appLoader.hide();
|
|
|
|
}
|
|
|
|
|
2023-11-03 23:00:55 +02:00
|
|
|
void handleShareAssets(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
|
|
|
Set<Asset> 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() {
|
2023-05-17 19:36:02 +02:00
|
|
|
if (selected.isNotEmpty) {
|
2023-11-03 23:00:55 +02:00
|
|
|
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(
|
2022-04-24 04:08:45 +02:00
|
|
|
leading: const Icon(Icons.delete_sweep_rounded),
|
|
|
|
title: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'album_viewer_appbar_share_remove',
|
2022-04-24 04:08:45 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2023-02-06 09:13:32 +02:00
|
|
|
onTap: () => onRemoveFromAlbumPressed(),
|
2023-11-03 23:00:55 +02:00
|
|
|
) : const SizedBox(),
|
|
|
|
];
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
2023-11-03 23:00:55 +02:00
|
|
|
return [
|
|
|
|
album.ownerId == userId ? ListTile(
|
2022-04-24 04:08:45 +02:00
|
|
|
leading: const Icon(Icons.delete_forever_rounded),
|
|
|
|
title: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'album_viewer_appbar_share_delete',
|
2022-04-24 04:08:45 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2023-02-06 09:13:32 +02:00
|
|
|
onTap: () => onDeleteAlbumPressed(),
|
2023-11-03 23:00:55 +02:00
|
|
|
) : ListTile(
|
2022-04-24 04:08:45 +02:00
|
|
|
leading: const Icon(Icons.person_remove_rounded),
|
|
|
|
title: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'album_viewer_appbar_share_leave',
|
2022-04-24 04:08:45 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2023-02-06 09:13:32 +02:00
|
|
|
onTap: () => onLeaveAlbumPressed(),
|
2023-11-03 23:00:55 +02:00
|
|
|
),
|
|
|
|
];
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
void buildBottomSheet() {
|
2023-08-18 06:26:12 +02:00
|
|
|
final ownerActions = [
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.person_add_alt_rounded),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
onAddUsers!(album);
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"album_viewer_page_share_add_users",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.share_rounded),
|
|
|
|
onTap: () {
|
|
|
|
AutoRouter.of(context)
|
|
|
|
.push(SharedLinkEditRoute(albumId: album.remoteId));
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"control_bottom_app_bar_share",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
2023-08-18 06:26:12 +02:00
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.settings_rounded),
|
|
|
|
onTap: () =>
|
|
|
|
AutoRouter.of(context).navigate(AlbumOptionsRoute(album: album)),
|
|
|
|
title: const Text(
|
|
|
|
"translated_text_options",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
final commonActions = [
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.add_photo_alternate_outlined),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
onAddPhotos!(album);
|
|
|
|
},
|
|
|
|
title: const Text(
|
|
|
|
"share_add_photos",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
];
|
2022-04-24 04:08:45 +02:00
|
|
|
showModalBottomSheet(
|
2022-08-16 01:53:30 +02:00
|
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
2022-04-24 04:08:45 +02:00
|
|
|
isScrollControlled: false,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
2022-04-30 17:55:27 +02:00
|
|
|
return SafeArea(
|
2023-08-18 06:26:12 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2023-11-03 23:00:55 +02:00
|
|
|
...buildBottomSheetActions(),
|
2023-08-18 06:26:12 +02:00
|
|
|
if (selected.isEmpty && onAddPhotos != null) ...commonActions,
|
|
|
|
if (selected.isEmpty &&
|
|
|
|
onAddPhotos != null &&
|
|
|
|
userId == album.ownerId)
|
2023-08-19 00:52:40 +02:00
|
|
|
...ownerActions,
|
2023-08-18 06:26:12 +02:00
|
|
|
],
|
|
|
|
),
|
2022-04-30 17:55:27 +02:00
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-06 17:46:26 +02:00
|
|
|
Widget buildActivitiesButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onActivities(album);
|
|
|
|
},
|
|
|
|
icon: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(
|
|
|
|
Icons.mode_comment_outlined,
|
|
|
|
),
|
|
|
|
if (comments != 0)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 5),
|
|
|
|
child: Text(
|
|
|
|
comments.toString(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildLeadingButton() {
|
2023-05-17 19:36:02 +02:00
|
|
|
if (selected.isNotEmpty) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return IconButton(
|
2023-05-17 19:36:02 +02:00
|
|
|
onPressed: selectionDisabled,
|
2022-04-24 04:08:45 +02:00
|
|
|
icon: const Icon(Icons.close_rounded),
|
|
|
|
splashRadius: 25,
|
|
|
|
);
|
2022-04-29 06:46:37 +02:00
|
|
|
} else if (isEditAlbum) {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () async {
|
2022-06-22 07:23:35 +02:00
|
|
|
bool isSuccess = await ref
|
|
|
|
.watch(albumViewerProvider.notifier)
|
2023-02-06 09:13:32 +02:00
|
|
|
.changeAlbumTitle(album, newAlbumTitle);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
if (!isSuccess) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2022-07-07 20:40:54 +02:00
|
|
|
msg: "album_viewer_appbar_share_err_title".tr(),
|
2022-04-29 06:46:37 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
toastType: ToastType.error,
|
|
|
|
);
|
|
|
|
}
|
2023-08-18 06:26:12 +02:00
|
|
|
|
|
|
|
titleFocusNode.unfocus();
|
2022-04-29 06:46:37 +02:00
|
|
|
},
|
|
|
|
icon: const Icon(Icons.check_rounded),
|
|
|
|
splashRadius: 25,
|
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () async => await AutoRouter.of(context).pop(),
|
|
|
|
icon: const Icon(Icons.arrow_back_ios_rounded),
|
|
|
|
splashRadius: 25,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppBar(
|
|
|
|
elevation: 0,
|
2022-11-21 14:13:14 +02:00
|
|
|
leading: buildLeadingButton(),
|
2023-05-17 19:36:02 +02:00
|
|
|
title: selected.isNotEmpty ? Text('${selected.length}') : null,
|
2022-04-24 04:08:45 +02:00
|
|
|
centerTitle: false,
|
|
|
|
actions: [
|
2023-11-06 17:46:26 +02:00
|
|
|
if (album.shared) buildActivitiesButton(),
|
2023-03-04 00:38:30 +02:00
|
|
|
if (album.isRemote)
|
|
|
|
IconButton(
|
|
|
|
splashRadius: 25,
|
|
|
|
onPressed: buildBottomSheet,
|
|
|
|
icon: const Icon(Icons.more_horiz_rounded),
|
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
}
|