2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-09 20:41:02 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-08 17:46:12 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-01-27 23:05:08 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/add_to_album_sliverlist.dart';
|
2023-10-22 04:38:07 +02:00
|
|
|
import 'package:immich_mobile/modules/home/models/selection_state.dart';
|
2023-02-11 22:23:32 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
|
2023-08-06 04:40:50 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/upload_dialog.dart';
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2023-01-11 22:54:12 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/drag_sheet.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2022-02-09 20:41:02 +02:00
|
|
|
|
2022-08-08 17:46:12 +02:00
|
|
|
class ControlBottomAppBar extends ConsumerWidget {
|
2023-10-22 17:05:10 +02:00
|
|
|
final void Function(bool shareLocal) onShare;
|
2023-05-17 19:36:02 +02:00
|
|
|
final void Function() onFavorite;
|
|
|
|
final void Function() onArchive;
|
|
|
|
final void Function() onDelete;
|
2023-02-06 09:13:32 +02:00
|
|
|
final Function(Album album) onAddToAlbum;
|
2022-11-06 03:21:55 +02:00
|
|
|
final void Function() onCreateNewAlbum;
|
2023-08-06 04:40:50 +02:00
|
|
|
final void Function() onUpload;
|
2023-10-22 04:38:07 +02:00
|
|
|
final void Function() onStack;
|
2023-12-05 21:34:37 +02:00
|
|
|
final void Function() onEditTime;
|
|
|
|
final void Function() onEditLocation;
|
2022-10-06 22:41:56 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
final List<Album> albums;
|
|
|
|
final List<Album> sharedAlbums;
|
2023-05-17 19:36:02 +02:00
|
|
|
final bool enabled;
|
2023-10-22 04:38:07 +02:00
|
|
|
final SelectionAssetState selectionAssetState;
|
2022-11-06 03:21:55 +02:00
|
|
|
|
|
|
|
const ControlBottomAppBar({
|
|
|
|
Key? key,
|
|
|
|
required this.onShare,
|
2023-02-06 14:59:56 +02:00
|
|
|
required this.onFavorite,
|
2023-04-17 07:02:07 +02:00
|
|
|
required this.onArchive,
|
2022-11-06 03:21:55 +02:00
|
|
|
required this.onDelete,
|
2023-01-27 23:05:08 +02:00
|
|
|
required this.sharedAlbums,
|
2022-11-06 03:21:55 +02:00
|
|
|
required this.albums,
|
|
|
|
required this.onAddToAlbum,
|
|
|
|
required this.onCreateNewAlbum,
|
2023-08-06 04:40:50 +02:00
|
|
|
required this.onUpload,
|
2023-10-22 04:38:07 +02:00
|
|
|
required this.onStack,
|
2023-12-05 21:34:37 +02:00
|
|
|
required this.onEditTime,
|
|
|
|
required this.onEditLocation,
|
2023-10-22 04:38:07 +02:00
|
|
|
this.selectionAssetState = const SelectionAssetState(),
|
2023-05-17 19:36:02 +02:00
|
|
|
this.enabled = true,
|
2022-11-06 03:21:55 +02:00
|
|
|
}) : super(key: key);
|
2022-02-09 20:41:02 +02:00
|
|
|
|
|
|
|
@override
|
2022-08-08 17:46:12 +02:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-10-22 04:38:07 +02:00
|
|
|
var hasRemote =
|
|
|
|
selectionAssetState.hasRemote || selectionAssetState.hasMerged;
|
|
|
|
var hasLocal = selectionAssetState.hasLocal;
|
2023-10-06 09:01:14 +02:00
|
|
|
final trashEnabled =
|
|
|
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
2023-02-11 22:23:32 +02:00
|
|
|
|
2023-10-22 17:05:10 +02:00
|
|
|
List<Widget> renderActionButtons() {
|
|
|
|
return [
|
|
|
|
if (hasRemote)
|
2022-11-07 04:41:10 +02:00
|
|
|
ControlBoxButton(
|
2023-10-22 17:05:10 +02:00
|
|
|
iconData: Icons.share_rounded,
|
2022-11-07 04:41:10 +02:00
|
|
|
label: "control_bottom_app_bar_share".tr(),
|
2023-10-22 17:05:10 +02:00
|
|
|
onPressed: enabled ? () => onShare(false) : null,
|
2022-11-07 04:41:10 +02: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,
|
|
|
|
),
|
|
|
|
if (hasRemote)
|
2022-11-07 04:41:10 +02:00
|
|
|
ControlBoxButton(
|
2023-10-22 17:05:10 +02:00
|
|
|
iconData: Icons.archive,
|
|
|
|
label: "control_bottom_app_bar_archive".tr(),
|
|
|
|
onPressed: enabled ? onArchive : null,
|
|
|
|
),
|
|
|
|
if (hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.favorite_border_rounded,
|
|
|
|
label: "control_bottom_app_bar_favorite".tr(),
|
|
|
|
onPressed: enabled ? onFavorite : null,
|
|
|
|
),
|
2023-12-05 21:34:37 +02:00
|
|
|
if (hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.edit_calendar_outlined,
|
|
|
|
label: "control_bottom_app_bar_edit_time".tr(),
|
|
|
|
onPressed: enabled ? onEditTime : null,
|
|
|
|
),
|
|
|
|
if (hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.edit_location_alt_outlined,
|
|
|
|
label: "control_bottom_app_bar_edit_location".tr(),
|
|
|
|
onPressed: enabled ? onEditLocation : null,
|
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.delete_outline_rounded,
|
|
|
|
label: "control_bottom_app_bar_delete".tr(),
|
|
|
|
onPressed: enabled
|
|
|
|
? () {
|
|
|
|
if (!trashEnabled) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return DeleteDialog(
|
|
|
|
onDelete: onDelete,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
onDelete();
|
2023-10-06 09:01:14 +02:00
|
|
|
}
|
2023-10-22 17:05:10 +02:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
),
|
2023-10-22 22:07:27 +02:00
|
|
|
if (!hasLocal && selectionAssetState.selectedCount > 1)
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.filter_none_rounded,
|
|
|
|
label: "control_bottom_app_bar_stack".tr(),
|
|
|
|
onPressed: enabled ? onStack : null,
|
|
|
|
),
|
2023-11-03 16:03:01 +02:00
|
|
|
if (hasLocal)
|
2023-10-22 17:05:10 +02:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.backup_outlined,
|
|
|
|
label: "Upload",
|
|
|
|
onPressed: enabled
|
|
|
|
? () => showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return UploadDialog(
|
|
|
|
onUpload: onUpload,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
2023-05-17 19:36:02 +02:00
|
|
|
: null,
|
2022-11-07 04:41:10 +02:00
|
|
|
),
|
2023-10-22 17:05:10 +02:00
|
|
|
];
|
2022-11-06 03:21:55 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 04:41:10 +02:00
|
|
|
return DraggableScrollableSheet(
|
2023-08-06 04:40:50 +02:00
|
|
|
initialChildSize: hasRemote ? 0.30 : 0.18,
|
|
|
|
minChildSize: 0.18,
|
2023-10-22 04:38:07 +02:00
|
|
|
maxChildSize: hasRemote ? 0.60 : 0.18,
|
2022-11-07 04:41:10 +02:00
|
|
|
snap: true,
|
|
|
|
builder: (
|
|
|
|
BuildContext context,
|
|
|
|
ScrollController scrollController,
|
|
|
|
) {
|
2023-01-27 23:05:08 +02:00
|
|
|
return Card(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.isDarkTheme ? Colors.grey[900] : Colors.grey[100],
|
2023-02-11 22:23:32 +02:00
|
|
|
surfaceTintColor: Colors.transparent,
|
|
|
|
elevation: 18.0,
|
2023-01-27 23:05:08 +02:00
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(12),
|
|
|
|
topRight: Radius.circular(12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.all(0),
|
2023-02-11 22:23:32 +02:00
|
|
|
child: CustomScrollView(
|
|
|
|
controller: scrollController,
|
|
|
|
slivers: [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
const CustomDraggingHandle(),
|
|
|
|
const SizedBox(height: 12),
|
2023-10-22 17:05:10 +02:00
|
|
|
SizedBox(
|
|
|
|
height: 70,
|
|
|
|
child: ListView(
|
2023-11-13 18:19:51 +02: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)
|
|
|
|
AddToAlbumTitleRow(
|
|
|
|
onCreateNewAlbum: enabled ? onCreateNewAlbum : null,
|
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
],
|
2023-01-27 23:05:08 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02: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 23:05:08 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
],
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-11-07 04:41:10 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AddToAlbumTitleRow extends StatelessWidget {
|
|
|
|
const AddToAlbumTitleRow({
|
|
|
|
super.key,
|
|
|
|
required this.onCreateNewAlbum,
|
|
|
|
});
|
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
final VoidCallback? onCreateNewAlbum;
|
2022-11-07 04:41:10 +02: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 19:22:35 +02:00
|
|
|
"common_add_to_album",
|
2022-11-07 04:41:10 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
2022-11-06 03:21:55 +02:00
|
|
|
),
|
2022-11-07 04:41:10 +02:00
|
|
|
).tr(),
|
2023-01-27 23:05:08 +02:00
|
|
|
TextButton.icon(
|
2022-11-07 04:41:10 +02:00
|
|
|
onPressed: onCreateNewAlbum,
|
2023-10-22 17:05:10 +02:00
|
|
|
icon: Icon(
|
|
|
|
Icons.add,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-10-22 17:05:10 +02:00
|
|
|
),
|
2023-01-27 23:05:08 +02:00
|
|
|
label: Text(
|
2023-02-20 19:22:35 +02:00
|
|
|
"common_create_new_album",
|
2022-11-07 04:41:10 +02:00
|
|
|
style: TextStyle(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-11-07 04:41:10 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|