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: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-12-22 22:10:21 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/delete_diaglog.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-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-12-22 22:10:21 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class GalleryViewerPage extends HookConsumerWidget {
|
2022-11-08 19:00:24 +02:00
|
|
|
late List<Asset> assetList;
|
|
|
|
final Asset 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);
|
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
Asset? 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-12-02 22:55:10 +02:00
|
|
|
final settings = ref.watch(appSettingsServiceProvider);
|
|
|
|
final isLoadPreview = useState(AppSettingsEnum.loadPreview.defaultValue);
|
|
|
|
final isLoadOriginal = useState(AppSettingsEnum.loadOriginal.defaultValue);
|
2022-08-13 22:51:09 +02:00
|
|
|
final isZoomed = useState<bool>(false);
|
2022-11-08 19:00:24 +02:00
|
|
|
final indexOfAsset = useState(assetList.indexOf(asset));
|
2022-11-19 07:12:54 +02:00
|
|
|
final isPlayingMotionVideo = useState(false);
|
|
|
|
ValueNotifier<bool> isZoomedListener = ValueNotifier<bool>(false);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
|
|
|
PageController controller =
|
|
|
|
PageController(initialPage: assetList.indexOf(asset));
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
2022-12-02 22:55:10 +02:00
|
|
|
isLoadPreview.value =
|
|
|
|
settings.getSetting<bool>(AppSettingsEnum.loadPreview);
|
|
|
|
isLoadOriginal.value =
|
|
|
|
settings.getSetting<bool>(AppSettingsEnum.loadOriginal);
|
2022-11-19 07:12:54 +02:00
|
|
|
isPlayingMotionVideo.value = false;
|
2022-08-13 22:51:09 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
getAssetExif() async {
|
2022-11-08 19:00:24 +02:00
|
|
|
if (assetList[indexOfAsset.value].isRemote) {
|
|
|
|
assetDetail = await ref
|
|
|
|
.watch(assetServiceProvider)
|
|
|
|
.getAssetById(assetList[indexOfAsset.value].id);
|
|
|
|
} else {
|
|
|
|
// TODO local exif parsing?
|
|
|
|
assetDetail = assetList[indexOfAsset.value];
|
|
|
|
}
|
2022-08-03 22:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void showInfo() {
|
|
|
|
showModalBottomSheet(
|
2023-01-11 22:54:12 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
2022-08-03 22:36:12 +02:00
|
|
|
barrierColor: Colors.transparent,
|
2023-01-11 22:54:12 +02:00
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
isScrollControlled: true,
|
2022-08-03 22:36:12 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-22 22:10:21 +02:00
|
|
|
void handleDelete(Asset deleteAsset) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
|
|
|
return DeleteDialog(
|
|
|
|
onDelete: () {
|
|
|
|
ref.watch(assetProvider.notifier).deleteAssets({deleteAsset});
|
|
|
|
AutoRouter.of(context).pop(null);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
appBar: TopControlAppBar(
|
2022-11-19 07:12:54 +02:00
|
|
|
isPlayingMotionVideo: isPlayingMotionVideo.value,
|
2022-11-08 19:00:24 +02:00
|
|
|
asset: assetList[indexOfAsset.value],
|
2022-08-03 22:36:12 +02:00
|
|
|
onMoreInfoPressed: () {
|
|
|
|
showInfo();
|
|
|
|
},
|
2022-11-08 19:00:24 +02:00
|
|
|
onDownloadPressed: assetList[indexOfAsset.value].isLocal
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
ref.watch(imageViewerStateProvider.notifier).downloadAsset(
|
2022-11-19 07:12:54 +02:00
|
|
|
assetList[indexOfAsset.value].remote!,
|
|
|
|
context,
|
|
|
|
);
|
2022-11-08 19:00:24 +02:00
|
|
|
},
|
2022-08-13 22:51:09 +02:00
|
|
|
onSharePressed: () {
|
2022-08-08 17:46:12 +02:00
|
|
|
ref
|
|
|
|
.watch(imageViewerStateProvider.notifier)
|
2022-11-08 19:00:24 +02:00
|
|
|
.shareAsset(assetList[indexOfAsset.value], context);
|
2022-08-03 22:36:12 +02:00
|
|
|
},
|
2022-11-19 07:12:54 +02:00
|
|
|
onToggleMotionVideo: (() {
|
|
|
|
isPlayingMotionVideo.value = !isPlayingMotionVideo.value;
|
|
|
|
}),
|
2022-12-22 22:10:21 +02:00
|
|
|
onDeletePressed: () => handleDelete((assetList[indexOfAsset.value])),
|
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) {
|
2022-11-08 19:00:24 +02:00
|
|
|
indexOfAsset.value = value;
|
2022-10-14 18:26:10 +02:00
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
},
|
2022-08-03 22:36:12 +02:00
|
|
|
itemBuilder: (context, index) {
|
|
|
|
getAssetExif();
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
if (assetList[index].isImage) {
|
2022-11-19 07:12:54 +02:00
|
|
|
if (isPlayingMotionVideo.value) {
|
|
|
|
return VideoViewerPage(
|
|
|
|
asset: assetList[index],
|
|
|
|
isMotionVideo: true,
|
|
|
|
onVideoEnded: () {
|
|
|
|
isPlayingMotionVideo.value = false;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return ImageViewerPage(
|
|
|
|
authToken: 'Bearer ${box.get(accessTokenKey)}',
|
|
|
|
isZoomedFunction: isZoomedMethod,
|
|
|
|
isZoomedListener: isZoomedListener,
|
|
|
|
asset: assetList[index],
|
|
|
|
heroTag: assetList[index].id,
|
2022-12-02 22:55:10 +02:00
|
|
|
loadPreview: isLoadPreview.value,
|
|
|
|
loadOriginal: isLoadOriginal.value,
|
2023-01-11 22:54:12 +02:00
|
|
|
showExifSheet: showInfo,
|
2022-11-19 07:12:54 +02:00
|
|
|
);
|
|
|
|
}
|
2022-08-03 22:36:12 +02:00
|
|
|
} else {
|
2022-11-11 19:52:02 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onVerticalDragUpdate: (details) {
|
2022-11-19 07:12:54 +02:00
|
|
|
const int sensitivity = 15;
|
2022-11-11 19:52:02 +02:00
|
|
|
if (details.delta.dy > sensitivity) {
|
|
|
|
// swipe down
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
} else if (details.delta.dy < -sensitivity) {
|
|
|
|
// swipe up
|
|
|
|
showInfo();
|
|
|
|
}
|
2022-08-03 22:36:12 +02:00
|
|
|
},
|
|
|
|
child: Hero(
|
|
|
|
tag: assetList[index].id,
|
2022-11-19 07:12:54 +02:00
|
|
|
child: VideoViewerPage(
|
|
|
|
asset: assetList[index],
|
|
|
|
isMotionVideo: false,
|
|
|
|
onVideoEnded: () {},
|
|
|
|
),
|
2022-08-03 22:36:12 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|