2023-02-01 18:59:34 +02:00
|
|
|
import 'dart:io';
|
2023-05-09 15:58:27 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-14 18:26:10 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-01-27 23:05:08 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/add_to_album_bottom_sheet.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/image_viewer_page_state.provider.dart';
|
2023-04-11 19:21:00 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/advanced_bottom_sheet.dart';
|
2022-08-03 22:36:12 +02:00
|
|
|
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/video_viewer_page.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-02-11 22:23:32 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/delete_dialog.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';
|
2023-03-15 23:29:07 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/photo_view_gallery.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/photo_view_computed_scale.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/photo_view_scale_state.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/photo_view/src/utils/photo_view_hero_attributes.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';
|
2023-02-01 18:59:34 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
import 'package:openapi/api.dart' as api;
|
2022-08-03 22:36:12 +02:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class GalleryViewerPage extends HookConsumerWidget {
|
2023-05-17 19:36:02 +02:00
|
|
|
final Asset Function(int index) loadAsset;
|
|
|
|
final int totalAssets;
|
|
|
|
final int initialIndex;
|
2022-08-08 02:43:09 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
GalleryViewerPage({
|
2023-02-18 04:47:28 +02:00
|
|
|
super.key,
|
2023-05-17 19:36:02 +02:00
|
|
|
required this.initialIndex,
|
|
|
|
required this.loadAsset,
|
|
|
|
required this.totalAssets,
|
|
|
|
}) : controller = PageController(initialPage: initialIndex);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2023-02-23 04:50:13 +02:00
|
|
|
final PageController controller;
|
2023-02-18 04:47:28 +02:00
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
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);
|
2023-02-03 18:26:05 +02:00
|
|
|
final showAppBar = useState<bool>(true);
|
2022-11-19 07:12:54 +02:00
|
|
|
final isPlayingMotionVideo = useState(false);
|
2023-02-05 14:57:07 +02:00
|
|
|
final isPlayingVideo = useState(false);
|
2023-02-01 18:59:34 +02:00
|
|
|
late Offset localPosition;
|
2023-03-23 03:36:44 +02:00
|
|
|
final authToken = 'Bearer ${Store.get(StoreKey.accessToken)}';
|
2023-05-17 19:36:02 +02:00
|
|
|
final currentIndex = useState(initialIndex);
|
|
|
|
final currentAsset = loadAsset(currentIndex.value);
|
|
|
|
final watchedAsset = ref.watch(assetDetailProvider(currentAsset));
|
|
|
|
|
|
|
|
Asset asset() => watchedAsset.value ?? currentAsset;
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2023-03-11 14:42:35 +02:00
|
|
|
showAppBar.addListener(() {
|
|
|
|
// Change to and from immersive mode, hiding navigation and app bar
|
|
|
|
if (showAppBar.value) {
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
|
|
} else {
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-13 22:51:09 +02:00
|
|
|
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
|
|
|
|
2023-05-17 19:36:02 +02:00
|
|
|
void toggleFavorite(Asset asset) => ref
|
|
|
|
.watch(assetProvider.notifier)
|
|
|
|
.toggleFavorite([asset], !asset.isFavorite);
|
2022-08-03 22:36:12 +02:00
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
/// Thumbnail image of a remote asset. Required asset.isRemote
|
|
|
|
ImageProvider remoteThumbnailImageProvider(
|
|
|
|
Asset asset,
|
|
|
|
api.ThumbnailFormat type,
|
|
|
|
) {
|
2023-02-01 18:59:34 +02:00
|
|
|
return CachedNetworkImageProvider(
|
|
|
|
getThumbnailUrl(
|
2023-02-04 22:42:42 +02:00
|
|
|
asset,
|
2023-02-01 18:59:34 +02:00
|
|
|
type: type,
|
2023-01-11 22:54:12 +02:00
|
|
|
),
|
2023-02-01 18:59:34 +02:00
|
|
|
cacheKey: getThumbnailCacheKey(
|
2023-02-04 22:42:42 +02:00
|
|
|
asset,
|
2023-02-01 18:59:34 +02:00
|
|
|
type: type,
|
|
|
|
),
|
|
|
|
headers: {"Authorization": authToken},
|
2022-08-03 22:36:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
/// Original (large) image of a remote asset. Required asset.isRemote
|
2023-02-01 18:59:34 +02:00
|
|
|
ImageProvider originalImageProvider(Asset asset) {
|
|
|
|
return CachedNetworkImageProvider(
|
2023-02-04 22:42:42 +02:00
|
|
|
getImageUrl(asset),
|
|
|
|
cacheKey: getImageCacheKey(asset),
|
2023-02-01 18:59:34 +02:00
|
|
|
headers: {"Authorization": authToken},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
/// Thumbnail image of a local asset. Required asset.isLocal
|
2023-02-01 18:59:34 +02:00
|
|
|
ImageProvider localThumbnailImageProvider(Asset asset) {
|
|
|
|
return AssetEntityImageProvider(
|
|
|
|
asset.local!,
|
|
|
|
isOriginal: false,
|
2023-02-02 21:29:52 +02:00
|
|
|
thumbnailSize: ThumbnailSize(
|
|
|
|
MediaQuery.of(context).size.width.floor(),
|
|
|
|
MediaQuery.of(context).size.height.floor(),
|
|
|
|
),
|
2023-02-01 18:59:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
/// Original (large) image of a local asset. Required asset.isLocal
|
2023-02-01 18:59:34 +02:00
|
|
|
ImageProvider localImageProvider(Asset asset) {
|
2023-03-04 00:49:40 +02:00
|
|
|
return AssetEntityImageProvider(
|
|
|
|
isOriginal: true,
|
|
|
|
asset.local!,
|
|
|
|
);
|
2023-02-01 18:59:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void precacheNextImage(int index) {
|
2023-05-17 19:36:02 +02:00
|
|
|
if (index < totalAssets && index >= 0) {
|
|
|
|
final asset = loadAsset(index);
|
2023-03-15 23:29:07 +02:00
|
|
|
|
2023-02-01 18:59:34 +02:00
|
|
|
if (asset.isLocal) {
|
|
|
|
// Preload the local asset
|
|
|
|
precacheImage(localImageProvider(asset), context);
|
|
|
|
} else {
|
2023-03-15 23:29:07 +02:00
|
|
|
onError(Object exception, StackTrace? stackTrace) {
|
|
|
|
// swallow error silently
|
|
|
|
}
|
2023-02-01 18:59:34 +02:00
|
|
|
// Probably load WEBP either way
|
|
|
|
precacheImage(
|
|
|
|
remoteThumbnailImageProvider(
|
2023-02-04 22:42:42 +02:00
|
|
|
asset,
|
2023-02-01 18:59:34 +02:00
|
|
|
api.ThumbnailFormat.WEBP,
|
|
|
|
),
|
|
|
|
context,
|
2023-03-15 23:29:07 +02:00
|
|
|
onError: onError,
|
2023-02-01 18:59:34 +02:00
|
|
|
);
|
|
|
|
if (isLoadPreview.value) {
|
|
|
|
// Precache the JPEG thumbnail
|
|
|
|
precacheImage(
|
|
|
|
remoteThumbnailImageProvider(
|
|
|
|
asset,
|
|
|
|
api.ThumbnailFormat.JPEG,
|
|
|
|
),
|
|
|
|
context,
|
2023-03-15 23:29:07 +02:00
|
|
|
onError: onError,
|
2023-02-01 18:59:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (isLoadOriginal.value) {
|
|
|
|
// Preload the original asset
|
|
|
|
precacheImage(
|
|
|
|
originalImageProvider(asset),
|
|
|
|
context,
|
2023-03-15 23:29:07 +02:00
|
|
|
onError: onError,
|
2023-02-01 18:59:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void showInfo() {
|
2023-02-04 22:42:42 +02:00
|
|
|
showModalBottomSheet(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
2023-04-11 19:21:00 +02:00
|
|
|
if (ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.getSetting<bool>(AppSettingsEnum.advancedTroubleshooting)) {
|
2023-05-17 19:36:02 +02:00
|
|
|
return AdvancedBottomSheet(assetDetail: asset());
|
2023-04-11 19:21:00 +02:00
|
|
|
}
|
2023-04-13 17:22:06 +02:00
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
child: ExifBottomSheet(asset: asset()),
|
2023-04-13 17:22:06 +02:00
|
|
|
);
|
2023-02-04 22:42:42 +02:00
|
|
|
},
|
|
|
|
);
|
2022-08-03 22:36:12 +02:00
|
|
|
}
|
|
|
|
|
2022-12-22 22:10:21 +02:00
|
|
|
void handleDelete(Asset deleteAsset) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
|
|
|
return DeleteDialog(
|
|
|
|
onDelete: () {
|
2023-05-17 19:36:02 +02:00
|
|
|
if (totalAssets == 1) {
|
2023-02-18 04:47:28 +02:00
|
|
|
// Handle only one asset
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
} else {
|
|
|
|
// Go to next page otherwise
|
|
|
|
controller.nextPage(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
curve: Curves.fastLinearToSlowEaseIn,
|
|
|
|
);
|
|
|
|
}
|
2022-12-22 22:10:21 +02:00
|
|
|
ref.watch(assetProvider.notifier).deleteAssets({deleteAsset});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-27 07:16:28 +02:00
|
|
|
void addToAlbum(Asset addToAlbumAsset) {
|
|
|
|
showModalBottomSheet(
|
2023-04-17 07:02:07 +02:00
|
|
|
elevation: 0,
|
2023-01-27 07:16:28 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext _) {
|
2023-01-27 23:05:08 +02:00
|
|
|
return AddToAlbumBottomSheet(
|
|
|
|
assets: [addToAlbumAsset],
|
2023-01-27 07:16:28 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-01 18:59:34 +02:00
|
|
|
void handleSwipeUpDown(DragUpdateDetails details) {
|
|
|
|
int sensitivity = 15;
|
2023-02-11 22:23:32 +02:00
|
|
|
int dxThreshold = 50;
|
2023-02-01 18:59:34 +02:00
|
|
|
|
|
|
|
if (isZoomed.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for delta from initial down point
|
|
|
|
final d = details.localPosition - localPosition;
|
|
|
|
// If the magnitude of the dx swipe is large, we probably didn't mean to go down
|
2023-02-11 22:23:32 +02:00
|
|
|
if (d.dx.abs() > dxThreshold) {
|
2023-02-01 18:59:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (details.delta.dy > sensitivity) {
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
} else if (details.delta.dy < -sensitivity) {
|
|
|
|
showInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 07:02:07 +02:00
|
|
|
shareAsset() {
|
2023-05-17 19:36:02 +02:00
|
|
|
ref.watch(imageViewerStateProvider.notifier).shareAsset(asset(), context);
|
2023-04-17 07:02:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleArchive(Asset asset) {
|
|
|
|
ref
|
|
|
|
.watch(assetProvider.notifier)
|
|
|
|
.toggleArchive([asset], !asset.isArchived);
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:26:05 +02:00
|
|
|
buildAppBar() {
|
2023-02-05 14:57:07 +02:00
|
|
|
final show = (showAppBar.value || // onTap has the final say
|
|
|
|
(showAppBar.value && !isZoomed.value)) &&
|
|
|
|
!isPlayingVideo.value;
|
|
|
|
|
2023-02-03 18:26:05 +02:00
|
|
|
return AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
2023-02-05 14:57:07 +02:00
|
|
|
opacity: show ? 1.0 : 0.0,
|
2023-02-03 18:26:05 +02:00
|
|
|
child: Container(
|
|
|
|
color: Colors.black.withOpacity(0.4),
|
|
|
|
child: TopControlAppBar(
|
|
|
|
isPlayingMotionVideo: isPlayingMotionVideo.value,
|
2023-05-17 19:36:02 +02:00
|
|
|
asset: asset(),
|
|
|
|
isFavorite: asset().isFavorite,
|
|
|
|
onMoreInfoPressed: showInfo,
|
|
|
|
onFavorite: asset().isRemote ? () => toggleFavorite(asset()) : null,
|
|
|
|
onDownloadPressed: asset().storage == AssetState.local
|
2023-02-03 18:26:05 +02:00
|
|
|
? null
|
2023-05-17 19:36:02 +02:00
|
|
|
: () =>
|
2023-02-03 18:26:05 +02:00
|
|
|
ref.watch(imageViewerStateProvider.notifier).downloadAsset(
|
2023-05-17 19:36:02 +02:00
|
|
|
asset(),
|
2023-02-03 18:26:05 +02:00
|
|
|
context,
|
2023-05-17 19:36:02 +02:00
|
|
|
),
|
2023-02-03 18:26:05 +02:00
|
|
|
onToggleMotionVideo: (() {
|
|
|
|
isPlayingMotionVideo.value = !isPlayingMotionVideo.value;
|
|
|
|
}),
|
2023-05-17 19:36:02 +02:00
|
|
|
onAddToAlbumPressed: () => addToAlbum(asset()),
|
2023-02-03 18:26:05 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-04-17 07:02:07 +02:00
|
|
|
buildBottomBar() {
|
|
|
|
final show = (showAppBar.value || // onTap has the final say
|
|
|
|
(showAppBar.value && !isZoomed.value)) &&
|
|
|
|
!isPlayingVideo.value;
|
|
|
|
return AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
opacity: show ? 1.0 : 0.0,
|
|
|
|
child: BottomNavigationBar(
|
|
|
|
backgroundColor: Colors.black.withOpacity(0.4),
|
|
|
|
unselectedIconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
selectedIconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
unselectedLabelStyle: const TextStyle(color: Colors.black),
|
|
|
|
selectedLabelStyle: const TextStyle(color: Colors.black),
|
|
|
|
showSelectedLabels: false,
|
|
|
|
showUnselectedLabels: false,
|
|
|
|
items: [
|
|
|
|
BottomNavigationBarItem(
|
2023-05-09 15:58:27 +02:00
|
|
|
icon: const Icon(Icons.ios_share_rounded),
|
|
|
|
label: 'control_bottom_app_bar_share'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_share'.tr(),
|
2023-04-17 07:02:07 +02:00
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
asset().isArchived
|
2023-05-09 15:58:27 +02:00
|
|
|
? BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.unarchive_rounded),
|
|
|
|
label: 'control_bottom_app_bar_unarchive'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_unarchive'.tr(),
|
|
|
|
)
|
|
|
|
: BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.archive_outlined),
|
|
|
|
label: 'control_bottom_app_bar_archive'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_archive'.tr(),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: const Icon(Icons.delete_outline),
|
|
|
|
label: 'control_bottom_app_bar_delete'.tr(),
|
|
|
|
tooltip: 'control_bottom_app_bar_delete'.tr(),
|
2023-04-17 07:02:07 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
onTap: (index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
shareAsset();
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-05-17 19:36:02 +02:00
|
|
|
handleArchive(asset());
|
2023-04-17 07:02:07 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-05-17 19:36:02 +02:00
|
|
|
handleDelete(asset());
|
2023-04-17 07:02:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-03 22:36:12 +02:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
2023-03-06 06:51:18 +02:00
|
|
|
body: WillPopScope(
|
|
|
|
onWillPop: () async {
|
|
|
|
// Change immersive mode back to normal "edgeToEdge" mode
|
|
|
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
PhotoViewGallery.builder(
|
|
|
|
scaleStateChangedCallback: (state) {
|
|
|
|
isZoomed.value = state != PhotoViewScaleState.initial;
|
|
|
|
showAppBar.value = !isZoomed.value;
|
|
|
|
},
|
|
|
|
pageController: controller,
|
|
|
|
scrollPhysics: isZoomed.value
|
|
|
|
? const NeverScrollableScrollPhysics() // Don't allow paging while scrolled in
|
|
|
|
: (Platform.isIOS
|
2023-04-18 18:23:56 +02:00
|
|
|
? const ScrollPhysics() // Use bouncing physics for iOS
|
2023-03-06 06:51:18 +02:00
|
|
|
: const ClampingScrollPhysics() // Use heavy physics for Android
|
|
|
|
),
|
2023-05-17 19:36:02 +02:00
|
|
|
itemCount: totalAssets,
|
2023-03-06 06:51:18 +02:00
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
onPageChanged: (value) {
|
|
|
|
// Precache image
|
2023-05-17 19:36:02 +02:00
|
|
|
if (currentIndex.value < value) {
|
2023-03-06 06:51:18 +02:00
|
|
|
// Moving forwards, so precache the next asset
|
|
|
|
precacheNextImage(value + 1);
|
|
|
|
} else {
|
|
|
|
// Moving backwards, so precache previous asset
|
|
|
|
precacheNextImage(value - 1);
|
|
|
|
}
|
2023-05-17 19:36:02 +02:00
|
|
|
currentIndex.value = value;
|
2023-03-06 06:51:18 +02:00
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
},
|
|
|
|
loadingBuilder: isLoadPreview.value
|
|
|
|
? (context, event) {
|
2023-05-17 19:36:02 +02:00
|
|
|
final a = asset();
|
|
|
|
if (!a.isLocal) {
|
2023-03-06 06:51:18 +02:00
|
|
|
// Use the WEBP Thumbnail as a placeholder for the JPEG thumbnail to achieve
|
|
|
|
// Three-Stage Loading (WEBP -> JPEG -> Original)
|
|
|
|
final webPThumbnail = CachedNetworkImage(
|
|
|
|
imageUrl: getThumbnailUrl(
|
2023-05-17 19:36:02 +02:00
|
|
|
a,
|
2023-03-06 06:51:18 +02:00
|
|
|
type: api.ThumbnailFormat.WEBP,
|
|
|
|
),
|
|
|
|
cacheKey: getThumbnailCacheKey(
|
2023-05-17 19:36:02 +02:00
|
|
|
a,
|
2023-03-06 06:51:18 +02:00
|
|
|
type: api.ThumbnailFormat.WEBP,
|
|
|
|
),
|
|
|
|
httpHeaders: {'Authorization': authToken},
|
2023-03-15 23:29:07 +02:00
|
|
|
progressIndicatorBuilder: (_, __, ___) =>
|
|
|
|
const Center(
|
2023-03-06 06:51:18 +02:00
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
),
|
|
|
|
fadeInDuration: const Duration(milliseconds: 0),
|
|
|
|
fit: BoxFit.contain,
|
2023-03-15 23:29:07 +02:00
|
|
|
errorWidget: (context, url, error) =>
|
|
|
|
const Icon(Icons.image_not_supported_outlined),
|
2023-03-06 06:51:18 +02:00
|
|
|
);
|
2023-02-04 22:42:42 +02:00
|
|
|
|
2023-03-15 23:29:07 +02:00
|
|
|
if (isLoadOriginal.value) {
|
|
|
|
// loading the preview in the loadingBuilder only
|
|
|
|
// makes sense if the original is loaded in the builder
|
|
|
|
return CachedNetworkImage(
|
|
|
|
imageUrl: getThumbnailUrl(
|
2023-05-17 19:36:02 +02:00
|
|
|
a,
|
2023-03-15 23:29:07 +02:00
|
|
|
type: api.ThumbnailFormat.JPEG,
|
|
|
|
),
|
|
|
|
cacheKey: getThumbnailCacheKey(
|
2023-05-17 19:36:02 +02:00
|
|
|
a,
|
2023-03-15 23:29:07 +02:00
|
|
|
type: api.ThumbnailFormat.JPEG,
|
|
|
|
),
|
|
|
|
httpHeaders: {'Authorization': authToken},
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 0),
|
|
|
|
placeholder: (_, __) => webPThumbnail,
|
|
|
|
errorWidget: (_, __, ___) => webPThumbnail,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return webPThumbnail;
|
|
|
|
}
|
2023-03-06 06:51:18 +02:00
|
|
|
} else {
|
|
|
|
return Image(
|
2023-05-17 19:36:02 +02:00
|
|
|
image: localThumbnailImageProvider(a),
|
2023-03-06 06:51:18 +02:00
|
|
|
fit: BoxFit.contain,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
builder: (context, index) {
|
2023-05-17 19:36:02 +02:00
|
|
|
final asset = loadAsset(index);
|
|
|
|
if (asset.isImage && !isPlayingMotionVideo.value) {
|
2023-03-06 06:51:18 +02:00
|
|
|
// Show photo
|
|
|
|
final ImageProvider provider;
|
2023-05-17 19:36:02 +02:00
|
|
|
if (asset.isLocal) {
|
|
|
|
provider = localImageProvider(asset);
|
2023-03-06 06:51:18 +02:00
|
|
|
} else {
|
|
|
|
if (isLoadOriginal.value) {
|
2023-05-17 19:36:02 +02:00
|
|
|
provider = originalImageProvider(asset);
|
2023-03-15 23:29:07 +02:00
|
|
|
} else if (isLoadPreview.value) {
|
2023-03-06 06:51:18 +02:00
|
|
|
provider = remoteThumbnailImageProvider(
|
2023-05-17 19:36:02 +02:00
|
|
|
asset,
|
2023-03-06 06:51:18 +02:00
|
|
|
api.ThumbnailFormat.JPEG,
|
2023-02-04 22:42:42 +02:00
|
|
|
);
|
2023-03-15 23:29:07 +02:00
|
|
|
} else {
|
|
|
|
provider = remoteThumbnailImageProvider(
|
2023-05-17 19:36:02 +02:00
|
|
|
asset,
|
2023-03-15 23:29:07 +02:00
|
|
|
api.ThumbnailFormat.WEBP,
|
|
|
|
);
|
2023-02-04 22:42:42 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-06 06:51:18 +02:00
|
|
|
return PhotoViewGalleryPageOptions(
|
|
|
|
onDragStart: (_, details, __) =>
|
|
|
|
localPosition = details.localPosition,
|
2023-03-15 23:29:07 +02:00
|
|
|
onDragUpdate: (_, details, __) =>
|
|
|
|
handleSwipeUpDown(details),
|
2023-03-06 06:51:18 +02:00
|
|
|
onTapDown: (_, __, ___) =>
|
|
|
|
showAppBar.value = !showAppBar.value,
|
|
|
|
imageProvider: provider,
|
|
|
|
heroAttributes: PhotoViewHeroAttributes(
|
2023-05-17 19:36:02 +02:00
|
|
|
tag: asset.id,
|
2023-03-06 06:51:18 +02:00
|
|
|
),
|
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
tightMode: true,
|
|
|
|
minScale: PhotoViewComputedScale.contained,
|
2023-03-15 23:29:07 +02:00
|
|
|
errorBuilder: (context, error, stackTrace) => ImmichImage(
|
2023-05-17 19:36:02 +02:00
|
|
|
asset,
|
2023-03-15 23:29:07 +02:00
|
|
|
fit: BoxFit.contain,
|
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
);
|
2023-02-01 18:59:34 +02:00
|
|
|
} else {
|
2023-03-06 06:51:18 +02:00
|
|
|
return PhotoViewGalleryPageOptions.customChild(
|
|
|
|
onDragStart: (_, details, __) =>
|
|
|
|
localPosition = details.localPosition,
|
2023-03-15 23:29:07 +02:00
|
|
|
onDragUpdate: (_, details, __) =>
|
|
|
|
handleSwipeUpDown(details),
|
2023-03-06 06:51:18 +02:00
|
|
|
heroAttributes: PhotoViewHeroAttributes(
|
2023-05-17 19:36:02 +02:00
|
|
|
tag: asset.id,
|
2023-02-04 22:42:42 +02:00
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
maxScale: 1.0,
|
|
|
|
minScale: 1.0,
|
2023-04-18 18:23:56 +02:00
|
|
|
basePosition: Alignment.bottomCenter,
|
2023-03-06 06:51:18 +02:00
|
|
|
child: SafeArea(
|
|
|
|
child: VideoViewerPage(
|
|
|
|
onPlaying: () => isPlayingVideo.value = true,
|
|
|
|
onPaused: () => isPlayingVideo.value = false,
|
2023-05-17 19:36:02 +02:00
|
|
|
asset: asset,
|
2023-03-06 06:51:18 +02:00
|
|
|
isMotionVideo: isPlayingMotionVideo.value,
|
|
|
|
onVideoEnded: () {
|
|
|
|
if (isPlayingMotionVideo.value) {
|
|
|
|
isPlayingMotionVideo.value = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: buildAppBar(),
|
|
|
|
),
|
2023-04-17 07:02:07 +02:00
|
|
|
Positioned(
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: buildBottomBar(),
|
|
|
|
),
|
2023-03-06 06:51:18 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-03 22:36:12 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|