2022-08-03 22:36:12 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-10-14 18:26:10 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:flutter_swipe_detector/flutter_swipe_detector.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/image_viewer_page_state.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/exif_bottom_sheet.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/top_control_app_bar.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/views/image_viewer_page.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/views/video_viewer_page.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
2022-08-16 01:53:30 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class GalleryViewerPage extends HookConsumerWidget {
|
|
|
|
late List<AssetResponseDto> assetList;
|
|
|
|
final AssetResponseDto asset;
|
2022-08-08 02:43:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
GalleryViewerPage({
|
|
|
|
Key? key,
|
|
|
|
required this.assetList,
|
|
|
|
required this.asset,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
AssetResponseDto? assetDetail;
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final Box<dynamic> box = Hive.box(userInfoBox);
|
2022-08-13 22:51:09 +02:00
|
|
|
final appSettingService = ref.watch(appSettingsServiceProvider);
|
|
|
|
final threeStageLoading = useState(false);
|
|
|
|
final loading = useState(false);
|
|
|
|
final isZoomed = useState<bool>(false);
|
|
|
|
ValueNotifier<bool> isZoomedListener = ValueNotifier<bool>(false);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
int indexOfAsset = assetList.indexOf(asset);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
|
|
|
PageController controller =
|
|
|
|
PageController(initialPage: assetList.indexOf(asset));
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
threeStageLoading.value = appSettingService
|
|
|
|
.getSetting<bool>(AppSettingsEnum.threeStageLoading);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
@override
|
2022-08-13 22:51:09 +02:00
|
|
|
initState(int index) {
|
2022-08-03 22:36:12 +02:00
|
|
|
indexOfAsset = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAssetExif() async {
|
|
|
|
assetDetail = await ref
|
|
|
|
.watch(assetServiceProvider)
|
|
|
|
.getAssetById(assetList[indexOfAsset].id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showInfo() {
|
|
|
|
showModalBottomSheet(
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
isScrollControlled: false,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return ExifBottomSheet(assetDetail: assetDetail!);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//make isZoomed listener call instead
|
|
|
|
void isZoomedMethod() {
|
|
|
|
if (isZoomedListener.value) {
|
|
|
|
isZoomed.value = true;
|
|
|
|
} else {
|
|
|
|
isZoomed.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
appBar: TopControlAppBar(
|
2022-08-08 02:43:09 +02:00
|
|
|
loading: loading.value,
|
2022-08-03 22:36:12 +02:00
|
|
|
asset: assetList[indexOfAsset],
|
|
|
|
onMoreInfoPressed: () {
|
|
|
|
showInfo();
|
|
|
|
},
|
|
|
|
onDownloadPressed: () {
|
|
|
|
ref
|
|
|
|
.watch(imageViewerStateProvider.notifier)
|
|
|
|
.downloadAsset(assetList[indexOfAsset], context);
|
2022-08-13 22:51:09 +02:00
|
|
|
},
|
|
|
|
onSharePressed: () {
|
2022-08-08 17:46:12 +02:00
|
|
|
ref
|
|
|
|
.watch(imageViewerStateProvider.notifier)
|
|
|
|
.shareAsset(assetList[indexOfAsset], context);
|
2022-08-03 22:36:12 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
body: SafeArea(
|
|
|
|
child: PageView.builder(
|
|
|
|
controller: controller,
|
|
|
|
pageSnapping: true,
|
|
|
|
physics: isZoomed.value
|
|
|
|
? const NeverScrollableScrollPhysics()
|
|
|
|
: const BouncingScrollPhysics(),
|
|
|
|
itemCount: assetList.length,
|
|
|
|
scrollDirection: Axis.horizontal,
|
2022-10-14 18:26:10 +02:00
|
|
|
onPageChanged: (value) {
|
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
},
|
2022-08-03 22:36:12 +02:00
|
|
|
itemBuilder: (context, index) {
|
|
|
|
initState(index);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
getAssetExif();
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
if (assetList[index].type == AssetTypeEnum.IMAGE) {
|
|
|
|
return ImageViewerPage(
|
|
|
|
authToken: 'Bearer ${box.get(accessTokenKey)}',
|
|
|
|
isZoomedFunction: isZoomedMethod,
|
|
|
|
isZoomedListener: isZoomedListener,
|
|
|
|
asset: assetList[index],
|
|
|
|
heroTag: assetList[index].id,
|
2022-08-13 22:51:09 +02:00
|
|
|
threeStageLoading: threeStageLoading.value,
|
2022-08-03 22:36:12 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return SwipeDetector(
|
|
|
|
onSwipeDown: (_) {
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
},
|
|
|
|
onSwipeUp: (_) {
|
|
|
|
showInfo();
|
|
|
|
},
|
|
|
|
child: Hero(
|
|
|
|
tag: assetList[index].id,
|
|
|
|
child: VideoViewerPage(
|
|
|
|
asset: assetList[index],
|
|
|
|
videoUrl:
|
|
|
|
'${box.get(serverEndpointKey)}/asset/file?aid=${assetList[index].deviceAssetId}&did=${assetList[index].deviceId}',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|