2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/asset_selection.provider.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 SelectionThumbnailImage extends HookConsumerWidget {
|
2022-11-08 19:00:24 +02:00
|
|
|
final Asset asset;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-06-25 22:12:47 +02:00
|
|
|
const SelectionThumbnailImage({Key? key, required this.asset})
|
|
|
|
: 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
|
|
|
var selectedAsset =
|
|
|
|
ref.watch(assetSelectionProvider).selectedNewAssetsForAlbum;
|
|
|
|
var newAssetsForAlbum =
|
|
|
|
ref.watch(assetSelectionProvider).selectedAdditionalAssetsForAlbum;
|
2022-04-24 04:08:45 +02:00
|
|
|
var isAlbumExist = ref.watch(assetSelectionProvider).isAlbumExist;
|
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
Widget _buildSelectionIcon(Asset asset) {
|
2022-07-16 06:18:17 +02:00
|
|
|
var isSelected = selectedAsset.map((item) => item.id).contains(asset.id);
|
|
|
|
var isNewlySelected =
|
|
|
|
newAssetsForAlbum.map((item) => item.id).contains(asset.id);
|
|
|
|
|
|
|
|
if (isSelected && !isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Icon(
|
|
|
|
Icons.check_circle,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
);
|
2022-07-16 06:18:17 +02:00
|
|
|
} else if (isSelected && isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return const Icon(
|
|
|
|
Icons.check_circle,
|
|
|
|
color: Color.fromARGB(255, 233, 233, 233),
|
|
|
|
);
|
2022-07-16 06:18:17 +02:00
|
|
|
} else if (isNewlySelected && isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Icon(
|
|
|
|
Icons.check_circle,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Icon(
|
|
|
|
Icons.circle_outlined,
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxBorder drawBorderColor() {
|
2022-07-16 06:18:17 +02:00
|
|
|
var isSelected = selectedAsset.map((item) => item.id).contains(asset.id);
|
|
|
|
var isNewlySelected =
|
|
|
|
newAssetsForAlbum.map((item) => item.id).contains(asset.id);
|
|
|
|
|
|
|
|
if (isSelected && !isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Border.all(
|
|
|
|
color: Theme.of(context).primaryColorLight,
|
|
|
|
width: 10,
|
|
|
|
);
|
2022-07-16 06:18:17 +02:00
|
|
|
} else if (isSelected && isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Border.all(
|
|
|
|
color: const Color.fromARGB(255, 190, 190, 190),
|
|
|
|
width: 10,
|
|
|
|
);
|
2022-07-16 06:18:17 +02:00
|
|
|
} else if (isNewlySelected && isAlbumExist) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return Border.all(
|
|
|
|
color: Theme.of(context).primaryColorLight,
|
|
|
|
width: 10,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return const Border();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
2022-07-16 06:18:17 +02:00
|
|
|
var isSelected =
|
|
|
|
selectedAsset.map((item) => item.id).contains(asset.id);
|
|
|
|
var isNewlySelected =
|
|
|
|
newAssetsForAlbum.map((item) => item.id).contains(asset.id);
|
|
|
|
|
2022-04-24 04:08:45 +02:00
|
|
|
if (isAlbumExist) {
|
|
|
|
// Operation for existing album
|
2022-07-16 06:18:17 +02:00
|
|
|
if (!isSelected) {
|
|
|
|
if (isNewlySelected) {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeSelectedAdditionalAssets([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAdditionalAssets([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Operation for new album
|
2022-07-16 06:18:17 +02:00
|
|
|
if (isSelected) {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeSelectedNewAssets([asset]);
|
2022-04-24 04:08:45 +02:00
|
|
|
} else {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).addNewAssets([asset]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-06-18 17:56:36 +02:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(border: drawBorderColor()),
|
2022-11-08 19:00:24 +02:00
|
|
|
child: ImmichImage(asset, width: 150, height: 150),
|
2022-06-18 17:56:36 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(3.0),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: _buildSelectionIcon(asset),
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
2022-06-18 17:56:36 +02:00
|
|
|
),
|
2022-11-08 19:00:24 +02:00
|
|
|
if (!asset.isImage)
|
2022-07-01 03:08:49 +02:00
|
|
|
Positioned(
|
|
|
|
bottom: 5,
|
|
|
|
right: 5,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-07-13 14:23:48 +02:00
|
|
|
asset.duration.substring(0, 7),
|
2022-07-01 03:08:49 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 10,
|
|
|
|
),
|
2022-06-18 17:56:36 +02:00
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
const Icon(
|
|
|
|
Icons.play_circle_outline_rounded,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-06-18 17:56:36 +02:00
|
|
|
],
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|