2023-07-15 18:11:51 -07:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-09 11:41:02 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-08 08:46:12 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-01-27 14:05:08 -07:00
|
|
|
import 'package:immich_mobile/modules/album/ui/add_to_album_sliverlist.dart';
|
2023-02-11 13:23:32 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
|
2023-08-05 19:40:50 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/upload_dialog.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2023-01-11 13:54:12 -07:00
|
|
|
import 'package:immich_mobile/shared/ui/drag_sheet.dart';
|
2023-02-06 00:13:32 -07:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2022-02-09 11:41:02 -07:00
|
|
|
|
2022-08-08 08:46:12 -07:00
|
|
|
class ControlBottomAppBar extends ConsumerWidget {
|
2023-05-17 10:36:02 -07:00
|
|
|
final void Function() onShare;
|
|
|
|
final void Function() onFavorite;
|
|
|
|
final void Function() onArchive;
|
|
|
|
final void Function() onDelete;
|
2023-02-06 00:13:32 -07:00
|
|
|
final Function(Album album) onAddToAlbum;
|
2022-11-05 18:21:55 -07:00
|
|
|
final void Function() onCreateNewAlbum;
|
2023-08-05 19:40:50 -07:00
|
|
|
final void Function() onUpload;
|
2022-10-06 13:41:56 -07:00
|
|
|
|
2023-02-06 00:13:32 -07:00
|
|
|
final List<Album> albums;
|
|
|
|
final List<Album> sharedAlbums;
|
2023-05-17 10:36:02 -07:00
|
|
|
final bool enabled;
|
2023-08-05 19:40:50 -07:00
|
|
|
final AssetState selectionAssetState;
|
2022-11-05 18:21:55 -07:00
|
|
|
|
|
|
|
const ControlBottomAppBar({
|
|
|
|
Key? key,
|
|
|
|
required this.onShare,
|
2023-02-06 05:59:56 -07:00
|
|
|
required this.onFavorite,
|
2023-04-16 22:02:07 -07:00
|
|
|
required this.onArchive,
|
2022-11-05 18:21:55 -07:00
|
|
|
required this.onDelete,
|
2023-01-27 14:05:08 -07:00
|
|
|
required this.sharedAlbums,
|
2022-11-05 18:21:55 -07:00
|
|
|
required this.albums,
|
|
|
|
required this.onAddToAlbum,
|
|
|
|
required this.onCreateNewAlbum,
|
2023-08-05 19:40:50 -07:00
|
|
|
required this.onUpload,
|
|
|
|
this.selectionAssetState = AssetState.remote,
|
2023-05-17 10:36:02 -07:00
|
|
|
this.enabled = true,
|
2022-11-05 18:21:55 -07:00
|
|
|
}) : super(key: key);
|
2022-02-09 11:41:02 -07:00
|
|
|
|
|
|
|
@override
|
2022-08-08 08:46:12 -07:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-02-11 13:23:32 -07:00
|
|
|
var isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
2023-08-05 19:40:50 -07:00
|
|
|
var hasRemote = selectionAssetState == AssetState.remote;
|
2023-02-11 13:23:32 -07:00
|
|
|
|
2022-11-05 18:21:55 -07:00
|
|
|
Widget renderActionButtons() {
|
2022-11-06 19:41:10 -07:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
ControlBoxButton(
|
2023-07-15 18:11:51 -07:00
|
|
|
iconData: Platform.isAndroid
|
|
|
|
? Icons.share_rounded
|
|
|
|
: Icons.ios_share_rounded,
|
2022-11-06 19:41:10 -07:00
|
|
|
label: "control_bottom_app_bar_share".tr(),
|
2023-05-17 10:36:02 -07:00
|
|
|
onPressed: enabled ? onShare : null,
|
2022-11-06 19:41:10 -07:00
|
|
|
),
|
2023-08-09 19:05:52 -07:00
|
|
|
if (hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.archive,
|
|
|
|
label: "control_bottom_app_bar_archive".tr(),
|
|
|
|
onPressed: enabled ? onArchive : null,
|
|
|
|
),
|
2023-08-05 19:40:50 -07:00
|
|
|
if (hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.favorite_border_rounded,
|
|
|
|
label: "control_bottom_app_bar_favorite".tr(),
|
|
|
|
onPressed: enabled ? onFavorite : null,
|
|
|
|
),
|
2022-11-06 19:41:10 -07:00
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.delete_outline_rounded,
|
|
|
|
label: "control_bottom_app_bar_delete".tr(),
|
2023-05-17 10:36:02 -07:00
|
|
|
onPressed: enabled
|
|
|
|
? () => showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return DeleteDialog(
|
|
|
|
onDelete: onDelete,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: null,
|
2022-11-06 19:41:10 -07:00
|
|
|
),
|
2023-08-05 19:40:50 -07:00
|
|
|
if (!hasRemote)
|
|
|
|
ControlBoxButton(
|
|
|
|
iconData: Icons.backup_outlined,
|
|
|
|
label: "Upload",
|
|
|
|
onPressed: enabled
|
|
|
|
? () => showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return UploadDialog(
|
|
|
|
onUpload: onUpload,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
2022-11-06 19:41:10 -07:00
|
|
|
],
|
2022-11-05 18:21:55 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-06 19:41:10 -07:00
|
|
|
return DraggableScrollableSheet(
|
2023-08-05 19:40:50 -07:00
|
|
|
initialChildSize: hasRemote ? 0.30 : 0.18,
|
|
|
|
minChildSize: 0.18,
|
|
|
|
maxChildSize: hasRemote ? 0.57 : 0.18,
|
2022-11-06 19:41:10 -07:00
|
|
|
snap: true,
|
|
|
|
builder: (
|
|
|
|
BuildContext context,
|
|
|
|
ScrollController scrollController,
|
|
|
|
) {
|
2023-01-27 14:05:08 -07:00
|
|
|
return Card(
|
2023-02-11 13:23:32 -07:00
|
|
|
color: isDarkMode ? Colors.grey[900] : Colors.grey[100],
|
|
|
|
surfaceTintColor: Colors.transparent,
|
|
|
|
elevation: 18.0,
|
2023-01-27 14:05:08 -07:00
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(12),
|
|
|
|
topRight: Radius.circular(12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.all(0),
|
2023-02-11 13:23:32 -07:00
|
|
|
child: CustomScrollView(
|
|
|
|
controller: scrollController,
|
|
|
|
slivers: [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
const CustomDraggingHandle(),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
renderActionButtons(),
|
2023-08-05 19:40:50 -07:00
|
|
|
if (hasRemote)
|
|
|
|
const Divider(
|
|
|
|
indent: 16,
|
|
|
|
endIndent: 16,
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
if (hasRemote)
|
|
|
|
AddToAlbumTitleRow(
|
|
|
|
onCreateNewAlbum: enabled ? onCreateNewAlbum : null,
|
|
|
|
),
|
2023-02-11 13:23:32 -07:00
|
|
|
],
|
2023-01-27 14:05:08 -07:00
|
|
|
),
|
2023-02-11 13:23:32 -07:00
|
|
|
),
|
2023-08-05 19:40:50 -07:00
|
|
|
if (hasRemote)
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
sliver: AddToAlbumSliverList(
|
|
|
|
albums: albums,
|
|
|
|
sharedAlbums: sharedAlbums,
|
|
|
|
onAddToAlbum: onAddToAlbum,
|
|
|
|
enabled: enabled,
|
|
|
|
),
|
2023-01-27 14:05:08 -07:00
|
|
|
),
|
2023-08-05 19:40:50 -07:00
|
|
|
if (hasRemote)
|
|
|
|
const SliverToBoxAdapter(
|
|
|
|
child: SizedBox(height: 200),
|
|
|
|
)
|
2023-02-11 13:23:32 -07:00
|
|
|
],
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
2022-11-06 19:41:10 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AddToAlbumTitleRow extends StatelessWidget {
|
|
|
|
const AddToAlbumTitleRow({
|
|
|
|
super.key,
|
|
|
|
required this.onCreateNewAlbum,
|
|
|
|
});
|
|
|
|
|
2023-05-17 10:36:02 -07:00
|
|
|
final VoidCallback? onCreateNewAlbum;
|
2022-11-06 19:41:10 -07: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 10:22:35 -07:00
|
|
|
"common_add_to_album",
|
2022-11-06 19:41:10 -07:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
2022-11-05 18:21:55 -07:00
|
|
|
),
|
2022-11-06 19:41:10 -07:00
|
|
|
).tr(),
|
2023-01-27 14:05:08 -07:00
|
|
|
TextButton.icon(
|
2022-11-06 19:41:10 -07:00
|
|
|
onPressed: onCreateNewAlbum,
|
2023-01-27 14:05:08 -07:00
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
label: Text(
|
2023-02-20 10:22:35 -07:00
|
|
|
"common_create_new_album",
|
2022-11-06 19:41:10 -07:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|