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:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/models/asset_selection_page_result.model.dart';
|
2023-05-17 19:36:02 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/immich_asset_grid.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/user.provider.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
class AssetSelectionPage extends HookConsumerWidget {
|
2023-05-17 19:36:02 +02:00
|
|
|
const AssetSelectionPage({
|
|
|
|
Key? key,
|
|
|
|
required this.existingAssets,
|
|
|
|
this.isNewAlbum = false,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final Set<Asset> existingAssets;
|
|
|
|
final bool isNewAlbum;
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2022-04-24 04:08:45 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-05-25 05:52:43 +02:00
|
|
|
final currentUser = ref.watch(currentUserProvider);
|
|
|
|
final renderList = ref.watch(remoteAssetsProvider(currentUser?.isarId));
|
2023-05-17 19:36:02 +02:00
|
|
|
final selected = useState<Set<Asset>>(existingAssets);
|
|
|
|
final selectionEnabledHook = useState(true);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
String buildAssetCountText() {
|
2023-05-17 19:36:02 +02:00
|
|
|
return selected.value.length.toString();
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
Widget buildBody(RenderList renderList) {
|
|
|
|
return ImmichAssetGrid(
|
|
|
|
renderList: renderList,
|
|
|
|
listener: (active, assets) {
|
|
|
|
selectionEnabledHook.value = active;
|
|
|
|
selected.value = assets;
|
|
|
|
},
|
|
|
|
selectionActive: true,
|
|
|
|
preselectedAssets: isNewAlbum ? selected.value : existingAssets,
|
|
|
|
canDeselect: isNewAlbum,
|
|
|
|
showMultiSelectIndicator: false,
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.close_rounded),
|
|
|
|
onPressed: () {
|
2023-05-17 19:36:02 +02:00
|
|
|
AutoRouter.of(context).popForced(null);
|
2022-04-24 04:08:45 +02:00
|
|
|
},
|
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
title: selected.value.isEmpty
|
2022-04-24 04:08:45 +02:00
|
|
|
? const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'share_add_photos',
|
2022-04-24 04:08:45 +02:00
|
|
|
style: TextStyle(fontSize: 18),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr()
|
2022-04-24 04:08:45 +02:00
|
|
|
: Text(
|
2022-11-21 14:13:14 +02:00
|
|
|
buildAssetCountText(),
|
2022-04-24 04:08:45 +02:00
|
|
|
style: const TextStyle(fontSize: 18),
|
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
actions: [
|
2023-05-17 19:36:02 +02:00
|
|
|
if (selected.value.isNotEmpty)
|
2022-07-01 03:08:49 +02:00
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
2023-05-17 19:36:02 +02:00
|
|
|
var payload =
|
|
|
|
AssetSelectionPageResult(selectedAssets: selected.value);
|
|
|
|
AutoRouter.of(context)
|
|
|
|
.popForced<AssetSelectionPageResult>(payload);
|
2022-07-01 03:08:49 +02:00
|
|
|
},
|
|
|
|
child: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"share_add",
|
2022-07-01 03:08:49 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
],
|
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
body: renderList.when(
|
|
|
|
data: (data) => buildBody(data),
|
|
|
|
error: (error, stackTrace) => Center(
|
|
|
|
child: Text(error.toString()),
|
|
|
|
),
|
|
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|