2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-09 19:41:02 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-19 15:31:56 +01:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2022-08-08 17:46:12 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 17:19:53 +01:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/album/album.provider.dart';
|
2024-05-07 06:04:21 +02:00
|
|
|
import 'package:immich_mobile/widgets/album/add_to_album_sliverlist.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/models/asset_selection_state.dart';
|
2024-05-07 06:04:21 +02:00
|
|
|
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
|
|
|
|
import 'package:immich_mobile/widgets/asset_grid/upload_dialog.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
2024-05-07 06:04:21 +02:00
|
|
|
import 'package:immich_mobile/widgets/common/drag_sheet.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
2024-03-19 15:31:56 +01:00
|
|
|
import 'package:immich_mobile/utils/draggable_scroll_controller.dart';
|
2022-02-09 19:41:02 +01:00
|
|
|
|
2024-03-19 15:31:56 +01:00
|
|
|
final controlBottomAppBarNotifier = ControlBottomAppBarNotifier();
|
|
|
|
|
|
|
|
class ControlBottomAppBarNotifier with ChangeNotifier {
|
|
|
|
void minimize() {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ControlBottomAppBar extends HookConsumerWidget {
|
2023-10-22 17:05:10 +02:00
|
|
|
final void Function(bool shareLocal) onShare;
|
2023-12-07 16:38:22 +01:00
|
|
|
final void Function()? onFavorite;
|
|
|
|
final void Function()? onArchive;
|
2024-01-17 04:28:23 +01:00
|
|
|
final void Function([bool force])? onDelete;
|
|
|
|
final void Function([bool force])? onDeleteServer;
|
|
|
|
final void Function(bool onlyBackedUp)? onDeleteLocal;
|
2023-02-06 08:13:32 +01:00
|
|
|
final Function(Album album) onAddToAlbum;
|
2022-11-06 02:21:55 +01:00
|
|
|
final void Function() onCreateNewAlbum;
|
2023-08-06 04:40:50 +02:00
|
|
|
final void Function() onUpload;
|
2023-12-07 16:38:22 +01:00
|
|
|
final void Function()? onStack;
|
|
|
|
final void Function()? onEditTime;
|
|
|
|
final void Function()? onEditLocation;
|
|
|
|
final void Function()? onRemoveFromAlbum;
|
2022-10-06 22:41:56 +02:00
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
final bool enabled;
|
2023-12-07 16:38:22 +01:00
|
|
|
final bool unfavorite;
|
|
|
|
final bool unarchive;
|
2024-05-01 04:36:40 +02:00
|
|
|
final AssetSelectionState selectionAssetState;
|
2022-11-06 02:21:55 +01:00
|
|
|
|
|
|
|
const ControlBottomAppBar({
|
2024-01-27 17:14:32 +01:00
|
|
|
super.key,
|
2022-11-06 02:21:55 +01:00
|
|
|
required this.onShare,
|
2023-12-07 16:38:22 +01:00
|
|
|
this.onFavorite,
|
|
|
|
this.onArchive,
|
|
|
|
this.onDelete,
|
2024-01-17 04:28:23 +01:00
|
|
|
this.onDeleteServer,
|
|
|
|
this.onDeleteLocal,
|
2022-11-06 02:21:55 +01:00
|
|
|
required this.onAddToAlbum,
|
|
|
|
required this.onCreateNewAlbum,
|
2023-08-06 04:40:50 +02:00
|
|
|
required this.onUpload,
|
2023-12-07 16:38:22 +01:00
|
|
|
this.onStack,
|
|
|
|
this.onEditTime,
|
|
|
|
this.onEditLocation,
|
|
|
|
this.onRemoveFromAlbum,
|
2024-05-01 04:36:40 +02:00
|
|
|
this.selectionAssetState = const AssetSelectionState(),
|
2023-05-17 19:36:02 +02:00
|
|
|
this.enabled = true,
|
2023-12-07 16:38:22 +01:00
|
|
|
this.unarchive = false,
|
|
|
|
this.unfavorite = false,
|
2024-01-27 17:14:32 +01:00
|
|
|
});
|
2022-02-09 19:41:02 +01:00
|
|
|
|
|
|
|
@override
|
2022-08-08 17:46:12 +02:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-01-17 04:28:23 +01:00
|
|
|
final hasRemote =
|
2023-10-22 04:38:07 +02:00
|
|
|
selectionAssetState.hasRemote || selectionAssetState.hasMerged;
|
2024-01-17 04:28:23 +01:00
|
|
|
final hasLocal =
|
|
|
|
selectionAssetState.hasLocal || selectionAssetState.hasMerged;
|
2023-10-06 09:01:14 +02:00
|
|
|
final trashEnabled =
|
|
|
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
2023-12-07 16:38:22 +01:00
|
|
|
final albums = ref.watch(albumProvider).where((a) => a.isRemote).toList();
|
2024-10-10 10:44:14 +02:00
|
|
|
final sharedAlbums =
|
|
|
|
ref.watch(albumProvider).where((a) => a.shared).toList();
|
2024-01-18 22:01:38 +01:00
|
|
|
const bottomPadding = 0.20;
|
2024-03-19 15:31:56 +01:00
|
|
|
final scrollController = useDraggableScrollController();
|
|
|
|
|
|
|
|
void minimize() {
|
|
|
|
scrollController.animateTo(
|
|
|
|
bottomPadding,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
controlBottomAppBarNotifier.addListener(minimize);
|
|
|
|
return () {
|
|
|
|
controlBottomAppBarNotifier.removeListener(minimize);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2023-02-11 21:23:32 +01:00
|
|
|
|
2024-01-18 22:01:38 +01:00
|
|
|
void showForceDeleteDialog(
|
2024-01-17 04:28:23 +01:00
|
|
|
Function(bool) deleteCb, {
|
|
|
|
String? alertMsg,
|
|
|
|
}) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return DeleteDialog(
|
|
|
|
alert: alertMsg,
|
2024-01-18 22:01:38 +01:00
|
|
|
onDelete: () => deleteCb(true),
|
2024-01-17 04:28:23 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-18 22:01:38 +01:00
|
|
|
void handleRemoteDelete(
|
|
|
|
bool force,
|
|
|
|
Function(bool) deleteCb, {
|
|
|
|
String? alertMsg,
|
|
|
|
}) {
|
|
|
|
if (!force) {
|
|
|
|
deleteCb(force);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return showForceDeleteDialog(deleteCb, alertMsg: alertMsg);
|
|
|
|
}
|
|
|
|
|
2023-10-22 17:05:10 +02:00
|
|
|
List<Widget> renderActionButtons() {
|
|
|
|
return [
|
|
|
|
if (hasRemote)
|
2022-11-07 03:41:10 +01:00
|
|
|
ControlBoxButton(
|
2023-10-22 17:05:10 +02:00
|
|
|
iconData: Icons.share_rounded,
|
2022-11-07 03:41:10 +01:00
|
|
|
label: "control_bottom_app_bar_share".tr(),
|
2023-10-22 17:05:10 +02:00
|
|
|
onPressed: enabled ? () => onShare(false) : null,
|
2022-11-07 03:41:10 +01:00
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.ios_share_rounded,
|
|
|
|
label: "control_bottom_app_bar_share_to".tr(),
|
|
|
|
onPressed: enabled ? () => onShare(true) : null,
|
|
|
|
),
|
2023-12-07 16:38:22 +01:00
|
|
|
if (hasRemote && onArchive != null)
|
2022-11-07 03:41:10 +01:00
|
|
|
ControlBoxButton(
|
2023-12-07 16:38:22 +01:00
|
|
|
iconData: unarchive ? Icons.unarchive : Icons.archive,
|
|
|
|
label: (unarchive
|
|
|
|
? "control_bottom_app_bar_unarchive"
|
|
|
|
: "control_bottom_app_bar_archive")
|
|
|
|
.tr(),
|
2023-10-22 17:05:10 +02:00
|
|
|
onPressed: enabled ? onArchive : null,
|
|
|
|
),
|
2023-12-07 16:38:22 +01:00
|
|
|
if (hasRemote && onFavorite != null)
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
2023-12-07 16:38:22 +01:00
|
|
|
iconData: unfavorite
|
|
|
|
? Icons.favorite_border_rounded
|
|
|
|
: Icons.favorite_rounded,
|
|
|
|
label: (unfavorite
|
|
|
|
? "control_bottom_app_bar_unfavorite"
|
|
|
|
: "control_bottom_app_bar_favorite")
|
|
|
|
.tr(),
|
2023-10-22 17:05:10 +02:00
|
|
|
onPressed: enabled ? onFavorite : null,
|
|
|
|
),
|
2024-02-14 03:17:21 +01:00
|
|
|
if (hasLocal && hasRemote && onDelete != null)
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 90),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.delete_sweep_outlined,
|
|
|
|
label: "control_bottom_app_bar_delete".tr(),
|
|
|
|
onPressed: enabled
|
|
|
|
? () => handleRemoteDelete(!trashEnabled, onDelete!)
|
|
|
|
: null,
|
|
|
|
onLongPressed:
|
|
|
|
enabled ? () => showForceDeleteDialog(onDelete!) : null,
|
|
|
|
),
|
|
|
|
),
|
2024-01-17 04:28:23 +01:00
|
|
|
if (hasRemote && onDeleteServer != null)
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 85),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.cloud_off_outlined,
|
2024-01-18 21:55:19 +01:00
|
|
|
label: trashEnabled
|
|
|
|
? "control_bottom_app_bar_trash_from_immich".tr()
|
|
|
|
: "control_bottom_app_bar_delete_from_immich".tr(),
|
2024-01-17 04:28:23 +01:00
|
|
|
onPressed: enabled
|
|
|
|
? () => handleRemoteDelete(
|
|
|
|
!trashEnabled,
|
|
|
|
onDeleteServer!,
|
|
|
|
alertMsg: "delete_dialog_alert_remote",
|
|
|
|
)
|
|
|
|
: null,
|
2024-01-18 22:01:38 +01:00
|
|
|
onLongPressed: enabled
|
|
|
|
? () => showForceDeleteDialog(
|
|
|
|
onDeleteServer!,
|
|
|
|
alertMsg: "delete_dialog_alert_remote",
|
|
|
|
)
|
|
|
|
: null,
|
2024-01-17 04:28:23 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
if (hasLocal && onDeleteLocal != null)
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 85),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.no_cell_rounded,
|
|
|
|
label: "control_bottom_app_bar_delete_from_local".tr(),
|
|
|
|
onPressed: enabled
|
|
|
|
? () {
|
|
|
|
if (!selectionAssetState.hasLocal) {
|
|
|
|
return onDeleteLocal?.call(true);
|
|
|
|
}
|
|
|
|
|
2023-12-07 16:38:22 +01:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2024-01-17 04:28:23 +01:00
|
|
|
return DeleteLocalOnlyDialog(
|
|
|
|
onDeleteLocal: onDeleteLocal!,
|
2023-12-07 16:38:22 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-01-17 04:28:23 +01:00
|
|
|
: null,
|
|
|
|
),
|
|
|
|
),
|
2023-12-11 19:53:11 +01:00
|
|
|
if (hasRemote && onEditTime != null)
|
2024-02-16 14:54:17 +01:00
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 95),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.edit_calendar_outlined,
|
|
|
|
label: "control_bottom_app_bar_edit_time".tr(),
|
|
|
|
onPressed: enabled ? onEditTime : null,
|
|
|
|
),
|
2023-12-11 19:53:11 +01:00
|
|
|
),
|
|
|
|
if (hasRemote && onEditLocation != null)
|
2024-02-16 14:54:17 +01:00
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 90),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.edit_location_alt_outlined,
|
|
|
|
label: "control_bottom_app_bar_edit_location".tr(),
|
|
|
|
onPressed: enabled ? onEditLocation : null,
|
|
|
|
),
|
2023-12-11 19:53:11 +01:00
|
|
|
),
|
2024-01-19 18:40:10 +01:00
|
|
|
if (!selectionAssetState.hasLocal &&
|
2023-12-07 16:38:22 +01:00
|
|
|
selectionAssetState.selectedCount > 1 &&
|
|
|
|
onStack != null)
|
2024-02-16 14:54:17 +01:00
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 90),
|
|
|
|
child: ControlBoxButton(
|
|
|
|
iconData: Icons.filter_none_rounded,
|
|
|
|
label: "control_bottom_app_bar_stack".tr(),
|
|
|
|
onPressed: enabled ? onStack : null,
|
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
),
|
2023-12-07 16:38:22 +01:00
|
|
|
if (onRemoveFromAlbum != null)
|
2024-02-16 14:54:17 +01:00
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 90),
|
|
|
|
child: ControlBoxButton(
|
2024-07-19 17:07:36 +02:00
|
|
|
iconData: Icons.remove_circle_outline,
|
2024-02-16 14:54:17 +01:00
|
|
|
label: 'album_viewer_appbar_share_remove'.tr(),
|
|
|
|
onPressed: enabled ? onRemoveFromAlbum : null,
|
|
|
|
),
|
2023-12-07 16:38:22 +01:00
|
|
|
),
|
2024-01-19 18:40:10 +01:00
|
|
|
if (selectionAssetState.hasLocal)
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.backup_outlined,
|
2024-03-01 18:24:55 +01:00
|
|
|
label: "control_bottom_app_bar_upload".tr(),
|
2023-10-22 17:05:10 +02:00
|
|
|
onPressed: enabled
|
|
|
|
? () => showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return UploadDialog(
|
|
|
|
onUpload: onUpload,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
2023-05-17 19:36:02 +02:00
|
|
|
: null,
|
2022-11-07 03:41:10 +01:00
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
];
|
2022-11-06 02:21:55 +01:00
|
|
|
}
|
|
|
|
|
2022-11-07 03:41:10 +01:00
|
|
|
return DraggableScrollableSheet(
|
2024-03-19 15:31:56 +01:00
|
|
|
controller: scrollController,
|
2024-02-16 14:54:17 +01:00
|
|
|
initialChildSize: hasRemote ? 0.35 : bottomPadding,
|
2024-01-18 22:01:38 +01:00
|
|
|
minChildSize: bottomPadding,
|
2024-02-16 14:54:17 +01:00
|
|
|
maxChildSize: hasRemote ? 0.65 : bottomPadding,
|
2022-11-07 03:41:10 +01:00
|
|
|
snap: true,
|
|
|
|
builder: (
|
|
|
|
BuildContext context,
|
|
|
|
ScrollController scrollController,
|
|
|
|
) {
|
2023-01-27 22:05:08 +01:00
|
|
|
return Card(
|
2024-08-06 16:20:27 +02:00
|
|
|
color: context.colorScheme.surfaceContainerLow,
|
2023-02-11 21:23:32 +01:00
|
|
|
surfaceTintColor: Colors.transparent,
|
|
|
|
elevation: 18.0,
|
2023-01-27 22:05:08 +01:00
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(12),
|
|
|
|
topRight: Radius.circular(12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.all(0),
|
2023-02-11 21:23:32 +01:00
|
|
|
child: CustomScrollView(
|
|
|
|
controller: scrollController,
|
|
|
|
slivers: [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
const CustomDraggingHandle(),
|
2024-02-16 14:54:17 +01:00
|
|
|
const SizedBox(height: 12),
|
2023-10-22 17:05:10 +02:00
|
|
|
SizedBox(
|
2024-02-16 14:54:17 +01:00
|
|
|
height: 100,
|
2023-10-22 17:05:10 +02:00
|
|
|
child: ListView(
|
2023-11-13 17:19:51 +01:00
|
|
|
shrinkWrap: true,
|
2023-10-22 17:05:10 +02:00
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
children: renderActionButtons(),
|
|
|
|
),
|
|
|
|
),
|
2023-08-06 04:40:50 +02:00
|
|
|
if (hasRemote)
|
|
|
|
const Divider(
|
|
|
|
indent: 16,
|
|
|
|
endIndent: 16,
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
if (hasRemote)
|
2024-01-17 04:28:23 +01:00
|
|
|
_AddToAlbumTitleRow(
|
2023-08-06 04:40:50 +02:00
|
|
|
onCreateNewAlbum: enabled ? onCreateNewAlbum : null,
|
|
|
|
),
|
2023-02-11 21:23:32 +01:00
|
|
|
],
|
2023-01-27 22:05:08 +01:00
|
|
|
),
|
2023-02-11 21:23:32 +01:00
|
|
|
),
|
2023-08-06 04:40:50 +02:00
|
|
|
if (hasRemote)
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
sliver: AddToAlbumSliverList(
|
|
|
|
albums: albums,
|
|
|
|
sharedAlbums: sharedAlbums,
|
|
|
|
onAddToAlbum: onAddToAlbum,
|
|
|
|
enabled: enabled,
|
|
|
|
),
|
2023-01-27 22:05:08 +01:00
|
|
|
),
|
2023-02-11 21:23:32 +01:00
|
|
|
],
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-11-07 03:41:10 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-17 04:28:23 +01:00
|
|
|
class _AddToAlbumTitleRow extends StatelessWidget {
|
|
|
|
const _AddToAlbumTitleRow({
|
2022-11-07 03:41:10 +01:00
|
|
|
required this.onCreateNewAlbum,
|
|
|
|
});
|
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
final VoidCallback? onCreateNewAlbum;
|
2022-11-07 03:41:10 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
const Text(
|
2023-02-20 18:22:35 +01:00
|
|
|
"common_add_to_album",
|
2022-11-07 03:41:10 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
2022-11-06 02:21:55 +01:00
|
|
|
),
|
2022-11-07 03:41:10 +01:00
|
|
|
).tr(),
|
2023-01-27 22:05:08 +01:00
|
|
|
TextButton.icon(
|
2022-11-07 03:41:10 +01:00
|
|
|
onPressed: onCreateNewAlbum,
|
2023-10-22 17:05:10 +02:00
|
|
|
icon: Icon(
|
|
|
|
Icons.add,
|
2023-11-09 17:19:53 +01:00
|
|
|
color: context.primaryColor,
|
2023-10-22 17:05:10 +02:00
|
|
|
),
|
2023-01-27 22:05:08 +01:00
|
|
|
label: Text(
|
2023-02-20 18:22:35 +01:00
|
|
|
"common_create_new_album",
|
2022-11-07 03:41:10 +01:00
|
|
|
style: TextStyle(
|
2023-11-09 17:19:53 +01:00
|
|
|
color: context.primaryColor,
|
2022-11-07 03:41:10 +01:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|