diff --git a/mobile/lib/domain/models/asset/base_asset.model.dart b/mobile/lib/domain/models/asset/base_asset.model.dart index 4d40be2d32..5774a13c90 100644 --- a/mobile/lib/domain/models/asset/base_asset.model.dart +++ b/mobile/lib/domain/models/asset/base_asset.model.dart @@ -56,6 +56,8 @@ sealed class BaseAsset { // Overridden in subclasses AssetState get storage; + String? get localId; + String? get remoteId; String get heroTag; @override diff --git a/mobile/lib/domain/models/asset/local_asset.model.dart b/mobile/lib/domain/models/asset/local_asset.model.dart index 9cd20acb0a..6f2f4c06ba 100644 --- a/mobile/lib/domain/models/asset/local_asset.model.dart +++ b/mobile/lib/domain/models/asset/local_asset.model.dart @@ -2,12 +2,12 @@ part of 'base_asset.model.dart'; class LocalAsset extends BaseAsset { final String id; - final String? remoteId; + final String? remoteAssetId; final int orientation; const LocalAsset({ required this.id, - this.remoteId, + String? remoteId, required super.name, super.checksum, required super.type, @@ -19,7 +19,13 @@ class LocalAsset extends BaseAsset { super.isFavorite = false, super.livePhotoVideoId, this.orientation = 0, - }); + }) : remoteAssetId = remoteId; + + @override + String? get localId => id; + + @override + String? get remoteId => remoteAssetId; @override AssetState get storage => remoteId == null ? AssetState.local : AssetState.merged; diff --git a/mobile/lib/domain/models/asset/remote_asset.model.dart b/mobile/lib/domain/models/asset/remote_asset.model.dart index 8648255167..4974dc9118 100644 --- a/mobile/lib/domain/models/asset/remote_asset.model.dart +++ b/mobile/lib/domain/models/asset/remote_asset.model.dart @@ -5,7 +5,7 @@ enum AssetVisibility { timeline, hidden, archive, locked } // Model for an asset stored in the server class RemoteAsset extends BaseAsset { final String id; - final String? localId; + final String? localAssetId; final String? thumbHash; final AssetVisibility visibility; final String ownerId; @@ -13,7 +13,7 @@ class RemoteAsset extends BaseAsset { const RemoteAsset({ required this.id, - this.localId, + String? localId, required super.name, required this.ownerId, required super.checksum, @@ -28,7 +28,13 @@ class RemoteAsset extends BaseAsset { this.visibility = AssetVisibility.timeline, super.livePhotoVideoId, this.stackId, - }); + }) : localAssetId = localId; + + @override + String? get localId => localAssetId; + + @override + String? get remoteId => id; @override AssetState get storage => localId == null ? AssetState.remote : AssetState.merged; diff --git a/mobile/lib/presentation/widgets/action_buttons/delete_local_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/delete_local_action_button.widget.dart index cccdee9b3a..9445daa2ad 100644 --- a/mobile/lib/presentation/widgets/action_buttons/delete_local_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/delete_local_action_button.widget.dart @@ -8,6 +8,7 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_bu import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.state.dart'; import 'package:immich_mobile/providers/infrastructure/action.provider.dart'; import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; +import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart'; import 'package:immich_mobile/widgets/common/immich_toast.dart'; /// This delete action has the following behavior: @@ -22,7 +23,17 @@ class DeleteLocalActionButton extends ConsumerWidget { return; } - final result = await ref.read(actionProvider.notifier).deleteLocal(source); + bool? backedUpOnly = await showDialog( + context: context, + builder: (BuildContext context) => DeleteLocalOnlyDialog(onDeleteLocal: (_) {}), + ); + + if (backedUpOnly == null) { + // User cancelled the dialog + return; + } + + final result = await ref.read(actionProvider.notifier).deleteLocal(source, backedUpOnly); ref.read(multiSelectProvider.notifier).reset(); if (source == ActionSource.viewer) { diff --git a/mobile/lib/providers/infrastructure/action.provider.dart b/mobile/lib/providers/infrastructure/action.provider.dart index 9a343aa358..fd53065fe2 100644 --- a/mobile/lib/providers/infrastructure/action.provider.dart +++ b/mobile/lib/providers/infrastructure/action.provider.dart @@ -252,8 +252,15 @@ class ActionNotifier extends Notifier { } } - Future deleteLocal(ActionSource source) async { - final ids = _getLocalIdsForSource(source); + Future deleteLocal(ActionSource source, bool backedUpOnly) async { + final List ids; + if (backedUpOnly) { + final assets = _getAssets(source); + ids = assets.where((asset) => asset.storage == AssetState.merged).map((asset) => asset.localId!).toList(); + } else { + ids = _getLocalIdsForSource(source); + } + try { final deletedCount = await _service.deleteLocal(ids); return ActionResult(count: deletedCount, success: true); diff --git a/mobile/lib/repositories/asset_media.repository.dart b/mobile/lib/repositories/asset_media.repository.dart index bfcf7060e0..aa63fda752 100644 --- a/mobile/lib/repositories/asset_media.repository.dart +++ b/mobile/lib/repositories/asset_media.repository.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/widgets.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/domain/models/asset/base_asset.model.dart'; @@ -8,6 +9,7 @@ import 'package:immich_mobile/domain/models/store.model.dart'; import 'package:immich_mobile/entities/asset.entity.dart' as asset_entity; import 'package:immich_mobile/entities/store.entity.dart'; import 'package:immich_mobile/extensions/build_context_extensions.dart'; +import 'package:immich_mobile/extensions/platform_extensions.dart'; import 'package:immich_mobile/extensions/response_extensions.dart'; import 'package:immich_mobile/repositories/asset_api.repository.dart'; import 'package:immich_mobile/utils/hash.dart'; @@ -20,11 +22,26 @@ final assetMediaRepositoryProvider = Provider((ref) => AssetMediaRepository(ref. class AssetMediaRepository { final AssetApiRepository _assetApiRepository; + static final Logger _log = Logger("AssetMediaRepository"); const AssetMediaRepository(this._assetApiRepository); - Future> deleteAll(List ids) => PhotoManager.editor.deleteWithIds(ids); + Future> deleteAll(List ids) async { + if (CurrentPlatform.isIOS) { + return PhotoManager.editor.deleteWithIds(ids); + } else if (CurrentPlatform.isAndroid) { + final androidInfo = await DeviceInfoPlugin().androidInfo; + if (androidInfo.version.sdkInt < 30) { + return PhotoManager.editor.deleteWithIds(ids); + } + return PhotoManager.editor.android.moveToTrash( + // Only the id is needed + ids.map((id) => AssetEntity(id: id, width: 1, height: 1, typeInt: 0)).toList(), + ); + } + return []; + } Future get(String id) async { final entity = await AssetEntity.fromId(id); diff --git a/mobile/lib/widgets/asset_grid/delete_dialog.dart b/mobile/lib/widgets/asset_grid/delete_dialog.dart index e7c7775e54..fa6c19d125 100644 --- a/mobile/lib/widgets/asset_grid/delete_dialog.dart +++ b/mobile/lib/widgets/asset_grid/delete_dialog.dart @@ -22,12 +22,12 @@ class DeleteLocalOnlyDialog extends StatelessWidget { @override Widget build(BuildContext context) { void onDeleteBackedUpOnly() { - context.pop(); + context.pop(true); onDeleteLocal(true); } void onForceDelete() { - context.pop(); + context.pop(false); onDeleteLocal(false); }