2022-04-24 04:08:45 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-02-05 05:25:11 +02:00
|
|
|
import 'package:immich_mobile/modules/favorite/providers/favorite_provider.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/asset_selection.provider.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
class AlbumViewerThumbnail extends HookConsumerWidget {
|
2022-11-08 19:00:24 +02:00
|
|
|
final Asset asset;
|
|
|
|
final List<Asset> assetList;
|
2022-08-20 23:19:40 +02:00
|
|
|
final bool showStorageIndicator;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
const AlbumViewerThumbnail({
|
|
|
|
Key? key,
|
|
|
|
required this.asset,
|
|
|
|
required this.assetList,
|
2022-08-20 23:19:40 +02:00
|
|
|
this.showStorageIndicator = true,
|
2022-08-03 22:36:12 +02:00
|
|
|
}) : super(key: key);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-25 22:12:47 +02:00
|
|
|
final selectedAssetsInAlbumViewer =
|
|
|
|
ref.watch(assetSelectionProvider).selectedAssetsInAlbumViewer;
|
|
|
|
final isMultiSelectionEnable =
|
|
|
|
ref.watch(assetSelectionProvider).isMultiselectEnable;
|
2023-02-05 05:25:11 +02:00
|
|
|
final isFavorite = ref.watch(favoriteProvider).contains(asset.id);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
viewAsset() {
|
2022-08-03 22:36:12 +02:00
|
|
|
AutoRouter.of(context).push(
|
|
|
|
GalleryViewerRoute(
|
|
|
|
asset: asset,
|
|
|
|
assetList: assetList,
|
|
|
|
),
|
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BoxBorder drawBorderColor() {
|
|
|
|
if (selectedAssetsInAlbumViewer.contains(asset)) {
|
|
|
|
return Border.all(
|
|
|
|
color: Theme.of(context).primaryColorLight,
|
|
|
|
width: 10,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Border();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
enableMultiSelection() {
|
2022-04-24 04:08:45 +02:00
|
|
|
ref.watch(assetSelectionProvider.notifier).enableMultiselection();
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAssetsInAlbumViewer([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
disableMultiSelection() {
|
2022-04-24 04:08:45 +02:00
|
|
|
ref.watch(assetSelectionProvider.notifier).disableMultiselection();
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildVideoLabel() {
|
2022-07-01 03:08:49 +02:00
|
|
|
return Positioned(
|
|
|
|
top: 5,
|
|
|
|
right: 5,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
asset.duration.toString().substring(0, 7),
|
|
|
|
style: const TextStyle(
|
2022-04-24 04:08:45 +02:00
|
|
|
color: Colors.white,
|
2022-07-01 03:08:49 +02:00
|
|
|
fontSize: 10,
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
|
|
|
const Icon(
|
|
|
|
Icons.play_circle_outline_rounded,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildAssetStoreLocationIcon() {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Positioned(
|
|
|
|
right: 10,
|
|
|
|
bottom: 5,
|
|
|
|
child: Icon(
|
2023-02-04 22:42:42 +02:00
|
|
|
asset.isRemote
|
2023-03-04 00:38:30 +02:00
|
|
|
? (asset.isLocal
|
2023-02-04 22:42:42 +02:00
|
|
|
? Icons.cloud_done_outlined
|
|
|
|
: Icons.cloud_outlined)
|
|
|
|
: Icons.cloud_off_outlined,
|
2022-04-24 04:08:45 +02:00
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-05 05:25:11 +02:00
|
|
|
buildAssetFavoriteIcon() {
|
|
|
|
return const Positioned(
|
|
|
|
left: 10,
|
|
|
|
bottom: 5,
|
|
|
|
child: Icon(
|
|
|
|
Icons.star,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildAssetSelectionIcon() {
|
2022-04-24 04:08:45 +02:00
|
|
|
bool isSelected = selectedAssetsInAlbumViewer.contains(asset);
|
2022-07-01 03:08:49 +02:00
|
|
|
|
|
|
|
return Positioned(
|
|
|
|
left: 10,
|
|
|
|
top: 5,
|
|
|
|
child: isSelected
|
|
|
|
? Icon(
|
|
|
|
Icons.check_circle_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
: const Icon(
|
|
|
|
Icons.check_circle_outline_rounded,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildThumbnailImage() {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(border: drawBorderColor()),
|
2022-11-08 19:00:24 +02:00
|
|
|
child: ImmichImage(asset, width: 300, height: 300),
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
handleSelectionGesture() {
|
2022-04-24 04:08:45 +02:00
|
|
|
if (selectedAssetsInAlbumViewer.contains(asset)) {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeAssetsInAlbumViewer([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
if (selectedAssetsInAlbumViewer.isEmpty) {
|
2022-11-21 14:13:14 +02:00
|
|
|
disableMultiSelection();
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAssetsInAlbumViewer([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GestureDetector(
|
2022-11-21 14:13:14 +02:00
|
|
|
onTap: isMultiSelectionEnable ? handleSelectionGesture : viewAsset,
|
|
|
|
onLongPress: enableMultiSelection,
|
2022-07-13 14:23:48 +02:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
2022-11-21 14:13:14 +02:00
|
|
|
buildThumbnailImage(),
|
2023-02-05 05:25:11 +02:00
|
|
|
if (isFavorite) buildAssetFavoriteIcon(),
|
2022-11-21 14:13:14 +02:00
|
|
|
if (showStorageIndicator) buildAssetStoreLocationIcon(),
|
|
|
|
if (!asset.isImage) buildVideoLabel(),
|
|
|
|
if (isMultiSelectionEnable) buildAssetSelectionIcon(),
|
2022-07-13 14:23:48 +02:00
|
|
|
],
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|