2024-01-05 06:20:55 +01:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-02-20 18:22:35 +01:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-01-27 22:05:08 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
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';
|
|
|
|
import 'package:immich_mobile/services/album.service.dart';
|
2024-05-07 06:04:21 +02:00
|
|
|
import 'package:immich_mobile/widgets/album/add_to_album_sliverlist.dart';
|
2023-01-27 22:05:08 +01:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
2024-05-07 06:04:21 +02:00
|
|
|
import 'package:immich_mobile/widgets/common/drag_sheet.dart';
|
|
|
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
2023-01-27 22:05:08 +01:00
|
|
|
|
|
|
|
class AddToAlbumBottomSheet extends HookConsumerWidget {
|
|
|
|
/// The asset to add to an album
|
|
|
|
final List<Asset> assets;
|
|
|
|
|
|
|
|
const AddToAlbumBottomSheet({
|
2024-01-27 17:14:32 +01:00
|
|
|
super.key,
|
2023-01-27 22:05:08 +01:00
|
|
|
required this.assets,
|
2024-01-27 17:14:32 +01:00
|
|
|
});
|
2023-01-27 22:05:08 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-03-03 23:38:30 +01:00
|
|
|
final albums = ref.watch(albumProvider).where((a) => a.isRemote).toList();
|
2023-01-27 22:05:08 +01:00
|
|
|
final albumService = ref.watch(albumServiceProvider);
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
// Fetch album updates, e.g., cover image
|
2024-10-10 10:44:14 +02:00
|
|
|
ref.read(albumProvider.notifier).refreshRemoteAlbums();
|
2023-01-27 22:05:08 +01:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2023-01-27 23:20:45 +01:00
|
|
|
[],
|
2023-01-27 22:05:08 +01:00
|
|
|
);
|
|
|
|
|
2023-02-06 08:13:32 +01:00
|
|
|
void addToAlbum(Album album) async {
|
2024-10-10 10:44:14 +02:00
|
|
|
final result = await albumService.addAssets(
|
2023-02-06 08:13:32 +01:00
|
|
|
album,
|
2024-10-10 10:44:14 +02:00
|
|
|
assets,
|
2023-01-27 22:05:08 +01:00
|
|
|
);
|
2023-01-27 23:20:45 +01:00
|
|
|
|
2023-01-27 22:05:08 +01:00
|
|
|
if (result != null) {
|
|
|
|
if (result.alreadyInAlbum.isNotEmpty) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2023-02-20 18:22:35 +01:00
|
|
|
msg: 'add_to_album_bottom_sheet_already_exists'.tr(
|
2023-04-17 07:02:07 +02:00
|
|
|
namedArgs: {"album": album.name},
|
2023-02-20 18:22:35 +01:00
|
|
|
),
|
2023-01-27 22:05:08 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2023-02-20 18:22:35 +01:00
|
|
|
msg: 'add_to_album_bottom_sheet_added'.tr(
|
2023-04-17 07:02:07 +02:00
|
|
|
namedArgs: {"album": album.name},
|
2023-02-20 18:22:35 +01:00
|
|
|
),
|
2023-01-27 22:05:08 +01:00
|
|
|
);
|
|
|
|
}
|
2023-01-27 23:20:45 +01:00
|
|
|
}
|
2023-11-28 23:05:13 +01:00
|
|
|
context.pop();
|
2023-01-27 22:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Card(
|
2023-04-17 07:02:07 +02:00
|
|
|
elevation: 0,
|
2023-01-27 22:05:08 +01:00
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(15),
|
|
|
|
topRight: Radius.circular(15),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
sliver: SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2023-01-28 22:05:28 +01:00
|
|
|
const SizedBox(height: 12),
|
2023-01-27 22:05:08 +01:00
|
|
|
const Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: CustomDraggingHandle(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-01-27 23:20:45 +01:00
|
|
|
Text(
|
2023-02-20 18:22:35 +01:00
|
|
|
'common_add_to_album'.tr(),
|
2023-11-09 17:19:53 +01:00
|
|
|
style: context.textTheme.displayMedium,
|
2023-01-27 22:05:08 +01:00
|
|
|
),
|
|
|
|
TextButton.icon(
|
2023-04-17 07:02:07 +02:00
|
|
|
icon: Icon(
|
|
|
|
Icons.add,
|
2023-11-09 17:19:53 +01:00
|
|
|
color: context.primaryColor,
|
2023-04-17 07:02:07 +02:00
|
|
|
),
|
|
|
|
label: Text(
|
|
|
|
'common_create_new_album'.tr(),
|
2023-11-09 17:19:53 +01:00
|
|
|
style: TextStyle(color: context.primaryColor),
|
2023-04-17 07:02:07 +02:00
|
|
|
),
|
2023-01-27 22:05:08 +01:00
|
|
|
onPressed: () {
|
2024-01-05 06:20:55 +01:00
|
|
|
context.pushRoute(
|
2023-01-27 22:05:08 +01:00
|
|
|
CreateAlbumRoute(
|
2024-10-10 10:44:14 +02:00
|
|
|
assets: assets,
|
2023-01-27 22:05:08 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
sliver: AddToAlbumSliverList(
|
|
|
|
albums: albums,
|
2024-10-10 10:44:14 +02:00
|
|
|
sharedAlbums: albums.where((a) => a.shared).toList(),
|
2023-01-27 22:05:08 +01:00
|
|
|
onAddToAlbum: addToAlbum,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|