2022-02-03 18:06:44 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-02-06 08:07:56 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
2022-02-13 23:10:42 +02:00
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-08-08 02:43:09 +02:00
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2022-02-08 19:24:49 +02:00
|
|
|
class ThumbnailImage extends HookConsumerWidget {
|
2022-07-13 14:23:48 +02:00
|
|
|
final AssetResponseDto asset;
|
2022-08-03 22:36:12 +02:00
|
|
|
final List<AssetResponseDto> assetList;
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
const ThumbnailImage({Key? key, required this.asset, required this.assetList})
|
|
|
|
: super(key: key);
|
2022-02-03 18:06:44 +02:00
|
|
|
|
|
|
|
@override
|
2022-02-08 19:24:49 +02:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-02-06 08:07:56 +02:00
|
|
|
final cacheKey = useState(1);
|
|
|
|
|
2022-02-03 18:06:44 +02:00
|
|
|
var box = Hive.box(userInfoBox);
|
2022-08-08 02:43:09 +02:00
|
|
|
var thumbnailRequestUrl = getThumbnailUrl(asset);
|
2022-02-08 19:24:49 +02:00
|
|
|
var selectedAsset = ref.watch(homePageStateProvider).selectedItems;
|
2022-06-25 22:12:47 +02:00
|
|
|
var isMultiSelectEnable =
|
|
|
|
ref.watch(homePageStateProvider).isMultiSelectEnable;
|
2022-02-13 23:10:42 +02:00
|
|
|
var deviceId = ref.watch(authenticationProvider).deviceId;
|
2022-02-08 19:24:49 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
Widget _buildSelectionIcon(AssetResponseDto asset) {
|
2022-02-08 19:24:49 +02:00
|
|
|
if (selectedAsset.contains(asset)) {
|
|
|
|
return Icon(
|
|
|
|
Icons.check_circle,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Icon(
|
|
|
|
Icons.circle_outlined,
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 18:06:44 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
2022-02-13 23:10:42 +02:00
|
|
|
debugPrint("View ${asset.id}");
|
2022-06-25 22:12:47 +02:00
|
|
|
if (isMultiSelectEnable &&
|
|
|
|
selectedAsset.contains(asset) &&
|
|
|
|
selectedAsset.length == 1) {
|
2022-02-08 19:24:49 +02:00
|
|
|
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
2022-06-25 22:12:47 +02:00
|
|
|
} else if (isMultiSelectEnable &&
|
|
|
|
selectedAsset.contains(asset) &&
|
|
|
|
selectedAsset.length > 1) {
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.removeSingleSelectedItem(asset);
|
2022-02-08 19:24:49 +02:00
|
|
|
} else if (isMultiSelectEnable && !selectedAsset.contains(asset)) {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.addSingleSelectedItem(asset);
|
2022-02-06 08:07:56 +02:00
|
|
|
} else {
|
2022-08-03 22:36:12 +02:00
|
|
|
AutoRouter.of(context).push(
|
|
|
|
GalleryViewerRoute(
|
|
|
|
assetList: assetList,
|
|
|
|
asset: asset,
|
|
|
|
),
|
|
|
|
);
|
2022-02-06 08:07:56 +02:00
|
|
|
}
|
2022-02-03 18:06:44 +02:00
|
|
|
},
|
2022-02-08 19:24:49 +02:00
|
|
|
onLongPress: () {
|
2022-08-03 22:36:12 +02:00
|
|
|
// Enable multi select function
|
2022-02-08 19:24:49 +02:00
|
|
|
ref.watch(homePageStateProvider.notifier).enableMultiSelect({asset});
|
|
|
|
HapticFeedback.heavyImpact();
|
|
|
|
},
|
2022-02-03 18:06:44 +02:00
|
|
|
child: Hero(
|
|
|
|
tag: asset.id,
|
2022-02-08 19:24:49 +02:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: isMultiSelectEnable && selectedAsset.contains(asset)
|
2022-06-25 22:12:47 +02:00
|
|
|
? Border.all(
|
2022-07-13 14:23:48 +02:00
|
|
|
color: Theme.of(context).primaryColorLight,
|
|
|
|
width: 10,
|
|
|
|
)
|
2022-02-08 19:24:49 +02:00
|
|
|
: const Border(),
|
|
|
|
),
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
cacheKey: "${asset.id}-${cacheKey.value}",
|
|
|
|
width: 300,
|
|
|
|
height: 300,
|
2022-07-13 14:23:48 +02:00
|
|
|
memCacheHeight: asset.type == AssetTypeEnum.IMAGE ? 250 : 400,
|
2022-02-08 19:24:49 +02:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
imageUrl: thumbnailRequestUrl,
|
2022-06-25 22:12:47 +02:00
|
|
|
httpHeaders: {
|
|
|
|
"Authorization": "Bearer ${box.get(accessTokenKey)}"
|
|
|
|
},
|
2022-02-08 19:24:49 +02:00
|
|
|
fadeInDuration: const Duration(milliseconds: 250),
|
2022-06-25 22:12:47 +02:00
|
|
|
progressIndicatorBuilder: (context, url, downloadProgress) =>
|
|
|
|
Transform.scale(
|
2022-02-08 19:24:49 +02:00
|
|
|
scale: 0.2,
|
2022-06-25 22:12:47 +02:00
|
|
|
child: CircularProgressIndicator(
|
2022-07-13 14:23:48 +02:00
|
|
|
value: downloadProgress.progress,
|
|
|
|
),
|
2022-02-08 19:24:49 +02:00
|
|
|
),
|
|
|
|
errorWidget: (context, url, error) {
|
2022-07-13 14:23:48 +02:00
|
|
|
debugPrint("Error getting thumbnail $url = $error");
|
2022-02-13 23:10:42 +02:00
|
|
|
return Icon(
|
|
|
|
Icons.image_not_supported_outlined,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
);
|
2022-02-08 19:24:49 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
if (isMultiSelectEnable)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(3.0),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: _buildSelectionIcon(asset),
|
|
|
|
),
|
|
|
|
),
|
2022-02-13 23:10:42 +02:00
|
|
|
Positioned(
|
|
|
|
right: 10,
|
|
|
|
bottom: 5,
|
|
|
|
child: Icon(
|
2022-06-25 22:12:47 +02:00
|
|
|
(deviceId != asset.deviceId)
|
|
|
|
? Icons.cloud_done_outlined
|
|
|
|
: Icons.photo_library_rounded,
|
2022-02-13 23:10:42 +02:00
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
)
|
2022-02-08 19:24:49 +02:00
|
|
|
],
|
2022-02-03 18:06:44 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|