2025-07-01 23:18:23 +08:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2025-07-01 03:38:15 +08:00
|
|
|
import 'package:immich_mobile/constants/enums.dart';
|
|
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
2025-06-30 12:21:09 -05:00
|
|
|
import 'package:immich_mobile/infrastructure/repositories/remote_asset.repository.dart';
|
2025-07-02 00:52:11 +08:00
|
|
|
import 'package:immich_mobile/providers/infrastructure/asset.provider.dart';
|
2025-06-30 12:21:09 -05:00
|
|
|
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
2025-07-01 23:18:23 +08:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2025-07-02 00:52:11 +08:00
|
|
|
import 'package:immich_mobile/widgets/common/location_picker.dart';
|
|
|
|
import 'package:maplibre_gl/maplibre_gl.dart';
|
2025-06-30 12:21:09 -05:00
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
|
|
final actionServiceProvider = Provider<ActionService>(
|
|
|
|
(ref) => ActionService(
|
|
|
|
ref.watch(assetApiRepositoryProvider),
|
2025-07-02 23:54:37 +05:30
|
|
|
ref.watch(remoteAssetRepositoryProvider),
|
2025-06-30 12:21:09 -05:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
class ActionService {
|
|
|
|
final AssetApiRepository _assetApiRepository;
|
2025-07-02 23:54:37 +05:30
|
|
|
final RemoteAssetRepository _remoteAssetRepository;
|
2025-06-30 12:21:09 -05:00
|
|
|
|
2025-07-02 00:52:11 +08:00
|
|
|
const ActionService(
|
|
|
|
this._assetApiRepository,
|
|
|
|
this._remoteAssetRepository,
|
|
|
|
);
|
2025-06-30 12:21:09 -05:00
|
|
|
|
2025-07-01 23:18:23 +08:00
|
|
|
Future<void> shareLink(List<String> remoteIds, BuildContext context) async {
|
|
|
|
context.pushRoute(
|
|
|
|
SharedLinkEditRoute(
|
|
|
|
assetsList: remoteIds,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-06-30 12:21:09 -05:00
|
|
|
Future<void> favorite(List<String> remoteIds) async {
|
2025-07-01 08:10:25 +05:30
|
|
|
await _assetApiRepository.updateFavorite(remoteIds, true);
|
|
|
|
await _remoteAssetRepository.updateFavorite(remoteIds, true);
|
2025-06-30 12:21:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> unFavorite(List<String> remoteIds) async {
|
2025-07-01 08:10:25 +05:30
|
|
|
await _assetApiRepository.updateFavorite(remoteIds, false);
|
|
|
|
await _remoteAssetRepository.updateFavorite(remoteIds, false);
|
2025-06-30 12:21:09 -05:00
|
|
|
}
|
2025-07-01 03:38:15 +08:00
|
|
|
|
|
|
|
Future<void> archive(List<String> remoteIds) async {
|
2025-07-01 08:10:25 +05:30
|
|
|
await _assetApiRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibilityEnum.archive,
|
|
|
|
);
|
|
|
|
await _remoteAssetRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibility.archive,
|
|
|
|
);
|
2025-07-01 03:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> unArchive(List<String> remoteIds) async {
|
2025-07-01 08:10:25 +05:30
|
|
|
await _assetApiRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibilityEnum.timeline,
|
|
|
|
);
|
|
|
|
await _remoteAssetRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibility.timeline,
|
|
|
|
);
|
2025-07-01 03:38:15 +08:00
|
|
|
}
|
2025-07-01 09:03:45 -05:00
|
|
|
|
|
|
|
Future<void> moveToLockFolder(List<String> remoteIds) async {
|
|
|
|
await _assetApiRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibilityEnum.locked,
|
|
|
|
);
|
|
|
|
await _remoteAssetRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibility.locked,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> removeFromLockFolder(List<String> remoteIds) async {
|
|
|
|
await _assetApiRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibilityEnum.timeline,
|
|
|
|
);
|
|
|
|
await _remoteAssetRepository.updateVisibility(
|
|
|
|
remoteIds,
|
|
|
|
AssetVisibility.timeline,
|
|
|
|
);
|
|
|
|
}
|
2025-07-02 00:52:11 +08:00
|
|
|
|
2025-07-03 01:26:07 +08:00
|
|
|
Future<void> trash(List<String> remoteIds) async {
|
|
|
|
await _assetApiRepository.delete(remoteIds, false);
|
|
|
|
await _remoteAssetRepository.trash(remoteIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> delete(List<String> remoteIds) async {
|
|
|
|
await _assetApiRepository.delete(remoteIds, true);
|
|
|
|
await _remoteAssetRepository.delete(remoteIds);
|
|
|
|
}
|
|
|
|
|
2025-07-02 00:52:11 +08:00
|
|
|
Future<bool> editLocation(
|
|
|
|
List<String> remoteIds,
|
|
|
|
BuildContext context,
|
|
|
|
) async {
|
|
|
|
LatLng? initialLatLng;
|
|
|
|
if (remoteIds.length == 1) {
|
2025-07-02 23:54:37 +05:30
|
|
|
final exif = await _remoteAssetRepository.getExif(remoteIds[0]);
|
2025-07-02 00:52:11 +08:00
|
|
|
|
|
|
|
if (exif?.latitude != null && exif?.longitude != null) {
|
|
|
|
initialLatLng = LatLng(exif!.latitude!, exif.longitude!);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final location = await showLocationPicker(
|
|
|
|
context: context,
|
|
|
|
initialLatLng: initialLatLng,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (location == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
await _assetApiRepository.updateLocation(
|
|
|
|
remoteIds,
|
|
|
|
location,
|
|
|
|
);
|
|
|
|
await _remoteAssetRepository.updateLocation(
|
|
|
|
remoteIds,
|
|
|
|
location,
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2025-06-30 12:21:09 -05:00
|
|
|
}
|