2023-10-19 20:19:00 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-08-27 05:07:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-12-05 19:34:37 +00:00
|
|
|
import 'package:immich_mobile/extensions/asset_extensions.dart';
|
2023-11-09 16:19:53 +00:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-05-01 02:36:40 +00:00
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
2024-05-02 20:59:14 +00:00
|
|
|
import 'package:immich_mobile/providers/asset.provider.dart';
|
|
|
|
import 'package:immich_mobile/services/asset.service.dart';
|
|
|
|
import 'package:immich_mobile/services/share.service.dart';
|
2024-05-07 04:04:21 +00:00
|
|
|
import 'package:immich_mobile/widgets/common/date_time_picker.dart';
|
|
|
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
|
|
|
import 'package:immich_mobile/widgets/common/location_picker.dart';
|
|
|
|
import 'package:immich_mobile/widgets/common/share_dialog.dart';
|
2024-01-15 15:26:13 +00:00
|
|
|
import 'package:maplibre_gl/maplibre_gl.dart';
|
2023-08-27 05:07:35 +00:00
|
|
|
|
|
|
|
void handleShareAssets(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
2024-01-06 03:02:16 +00:00
|
|
|
Iterable<Asset> selection,
|
2023-08-27 05:07:35 +00:00
|
|
|
) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext buildContext) {
|
2024-07-26 13:43:59 +00:00
|
|
|
ref
|
|
|
|
.watch(shareServiceProvider)
|
|
|
|
.shareAssets(selection.toList(), context)
|
|
|
|
.then(
|
2023-10-19 20:19:00 +00:00
|
|
|
(bool status) {
|
|
|
|
if (!status) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: 'image_viewer_page_state_provider_share_error'.tr(),
|
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
2023-11-19 05:13:38 +00:00
|
|
|
buildContext.pop();
|
2023-10-19 20:19:00 +00:00
|
|
|
},
|
|
|
|
);
|
2023-08-27 05:07:35 +00:00
|
|
|
return const ShareDialog();
|
|
|
|
},
|
|
|
|
barrierDismissible: false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> handleArchiveAssets(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
|
|
|
List<Asset> selection, {
|
2023-12-07 15:38:22 +00:00
|
|
|
bool? shouldArchive,
|
2023-08-27 05:07:35 +00:00
|
|
|
ToastGravity toastGravity = ToastGravity.BOTTOM,
|
|
|
|
}) async {
|
|
|
|
if (selection.isNotEmpty) {
|
2023-12-07 15:38:22 +00:00
|
|
|
shouldArchive ??= !selection.every((a) => a.isArchived);
|
2023-08-27 05:07:35 +00:00
|
|
|
await ref
|
|
|
|
.read(assetProvider.notifier)
|
|
|
|
.toggleArchive(selection, shouldArchive);
|
|
|
|
|
|
|
|
final assetOrAssets = selection.length > 1 ? 'assets' : 'asset';
|
|
|
|
final archiveOrLibrary = shouldArchive ? 'archive' : 'library';
|
|
|
|
if (context.mounted) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: 'Moved ${selection.length} $assetOrAssets to $archiveOrLibrary',
|
|
|
|
gravity: toastGravity,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> handleFavoriteAssets(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
|
|
|
List<Asset> selection, {
|
2023-12-07 15:38:22 +00:00
|
|
|
bool? shouldFavorite,
|
2023-08-27 05:07:35 +00:00
|
|
|
ToastGravity toastGravity = ToastGravity.BOTTOM,
|
|
|
|
}) async {
|
|
|
|
if (selection.isNotEmpty) {
|
2023-12-07 15:38:22 +00:00
|
|
|
shouldFavorite ??= !selection.every((a) => a.isFavorite);
|
2023-08-27 05:07:35 +00:00
|
|
|
await ref
|
|
|
|
.watch(assetProvider.notifier)
|
|
|
|
.toggleFavorite(selection, shouldFavorite);
|
|
|
|
|
|
|
|
final assetOrAssets = selection.length > 1 ? 'assets' : 'asset';
|
|
|
|
final toastMessage = shouldFavorite
|
|
|
|
? 'Added ${selection.length} $assetOrAssets to favorites'
|
|
|
|
: 'Removed ${selection.length} $assetOrAssets from favorites';
|
|
|
|
if (context.mounted) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: toastMessage,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-05 19:34:37 +00:00
|
|
|
|
|
|
|
Future<void> handleEditDateTime(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
|
|
|
List<Asset> selection,
|
|
|
|
) async {
|
|
|
|
DateTime? initialDate;
|
|
|
|
String? timeZone;
|
|
|
|
Duration? offset;
|
|
|
|
if (selection.length == 1) {
|
|
|
|
final asset = selection.first;
|
|
|
|
final assetWithExif = await ref.watch(assetServiceProvider).loadExif(asset);
|
|
|
|
final (dt, oft) = assetWithExif.getTZAdjustedTimeAndOffset();
|
|
|
|
initialDate = dt;
|
|
|
|
offset = oft;
|
|
|
|
timeZone = assetWithExif.exifInfo?.timeZone;
|
|
|
|
}
|
|
|
|
final dateTime = await showDateTimePicker(
|
|
|
|
context: context,
|
|
|
|
initialDateTime: initialDate,
|
|
|
|
initialTZ: timeZone,
|
|
|
|
initialTZOffset: offset,
|
|
|
|
);
|
2024-08-09 13:43:47 +00:00
|
|
|
|
2023-12-05 19:34:37 +00:00
|
|
|
if (dateTime == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.read(assetServiceProvider).changeDateTime(selection.toList(), dateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> handleEditLocation(
|
|
|
|
WidgetRef ref,
|
|
|
|
BuildContext context,
|
|
|
|
List<Asset> selection,
|
|
|
|
) async {
|
|
|
|
LatLng? initialLatLng;
|
|
|
|
if (selection.length == 1) {
|
|
|
|
final asset = selection.first;
|
|
|
|
final assetWithExif = await ref.watch(assetServiceProvider).loadExif(asset);
|
|
|
|
if (assetWithExif.exifInfo?.latitude != null &&
|
|
|
|
assetWithExif.exifInfo?.longitude != null) {
|
|
|
|
initialLatLng = LatLng(
|
|
|
|
assetWithExif.exifInfo!.latitude!,
|
|
|
|
assetWithExif.exifInfo!.longitude!,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-08-09 13:43:47 +00:00
|
|
|
|
2023-12-05 19:34:37 +00:00
|
|
|
final location = await showLocationPicker(
|
|
|
|
context: context,
|
|
|
|
initialLatLng: initialLatLng,
|
|
|
|
);
|
2024-08-09 13:43:47 +00:00
|
|
|
|
2023-12-05 19:34:37 +00:00
|
|
|
if (location == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.read(assetServiceProvider).changeLocation(selection.toList(), location);
|
|
|
|
}
|