Skip to content

Commit 45bcca1

Browse files
shenlong-tanwenbwees
authored andcommitted
fix: show dialog on delete local action
1 parent 25142bb commit 45bcca1

File tree

7 files changed

+60
-12
lines changed

7 files changed

+60
-12
lines changed

mobile/lib/domain/models/asset/base_asset.model.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ sealed class BaseAsset {
5656

5757
// Overridden in subclasses
5858
AssetState get storage;
59+
String? get localId;
60+
String? get remoteId;
5961
String get heroTag;
6062

6163
@override

mobile/lib/domain/models/asset/local_asset.model.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ part of 'base_asset.model.dart';
22

33
class LocalAsset extends BaseAsset {
44
final String id;
5-
final String? remoteId;
5+
final String? remoteAssetId;
66
final int orientation;
77

88
const LocalAsset({
99
required this.id,
10-
this.remoteId,
10+
String? remoteId,
1111
required super.name,
1212
super.checksum,
1313
required super.type,
@@ -19,7 +19,13 @@ class LocalAsset extends BaseAsset {
1919
super.isFavorite = false,
2020
super.livePhotoVideoId,
2121
this.orientation = 0,
22-
});
22+
}) : remoteAssetId = remoteId;
23+
24+
@override
25+
String? get localId => id;
26+
27+
@override
28+
String? get remoteId => remoteAssetId;
2329

2430
@override
2531
AssetState get storage => remoteId == null ? AssetState.local : AssetState.merged;

mobile/lib/domain/models/asset/remote_asset.model.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ enum AssetVisibility { timeline, hidden, archive, locked }
55
// Model for an asset stored in the server
66
class RemoteAsset extends BaseAsset {
77
final String id;
8-
final String? localId;
8+
final String? localAssetId;
99
final String? thumbHash;
1010
final AssetVisibility visibility;
1111
final String ownerId;
1212
final String? stackId;
1313

1414
const RemoteAsset({
1515
required this.id,
16-
this.localId,
16+
String? localId,
1717
required super.name,
1818
required this.ownerId,
1919
required super.checksum,
@@ -28,7 +28,13 @@ class RemoteAsset extends BaseAsset {
2828
this.visibility = AssetVisibility.timeline,
2929
super.livePhotoVideoId,
3030
this.stackId,
31-
});
31+
}) : localAssetId = localId;
32+
33+
@override
34+
String? get localId => localAssetId;
35+
36+
@override
37+
String? get remoteId => id;
3238

3339
@override
3440
AssetState get storage => localId == null ? AssetState.remote : AssetState.merged;

mobile/lib/presentation/widgets/action_buttons/delete_local_action_button.widget.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_bu
88
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.state.dart';
99
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
1010
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
11+
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
1112
import 'package:immich_mobile/widgets/common/immich_toast.dart';
1213

1314
/// This delete action has the following behavior:
@@ -22,7 +23,17 @@ class DeleteLocalActionButton extends ConsumerWidget {
2223
return;
2324
}
2425

25-
final result = await ref.read(actionProvider.notifier).deleteLocal(source);
26+
bool? backedUpOnly = await showDialog<bool>(
27+
context: context,
28+
builder: (BuildContext context) => DeleteLocalOnlyDialog(onDeleteLocal: (_) {}),
29+
);
30+
31+
if (backedUpOnly == null) {
32+
// User cancelled the dialog
33+
return;
34+
}
35+
36+
final result = await ref.read(actionProvider.notifier).deleteLocal(source, backedUpOnly);
2637
ref.read(multiSelectProvider.notifier).reset();
2738

2839
if (source == ActionSource.viewer) {

mobile/lib/providers/infrastructure/action.provider.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,15 @@ class ActionNotifier extends Notifier<void> {
257257
}
258258
}
259259

260-
Future<ActionResult> deleteLocal(ActionSource source) async {
261-
final ids = _getLocalIdsForSource(source);
260+
Future<ActionResult> deleteLocal(ActionSource source, bool backedUpOnly) async {
261+
final List<String> ids;
262+
if (backedUpOnly) {
263+
final assets = _getAssets(source);
264+
ids = assets.where((asset) => asset.storage == AssetState.merged).map((asset) => asset.localId!).toList();
265+
} else {
266+
ids = _getLocalIdsForSource(source);
267+
}
268+
262269
try {
263270
final deletedCount = await _service.deleteLocal(ids);
264271
return ActionResult(count: deletedCount, success: true);

mobile/lib/repositories/asset_media.repository.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io';
22

3+
import 'package:device_info_plus/device_info_plus.dart';
34
import 'package:flutter/widgets.dart';
45
import 'package:hooks_riverpod/hooks_riverpod.dart';
56
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
@@ -21,11 +22,26 @@ final assetMediaRepositoryProvider = Provider((ref) => AssetMediaRepository(ref.
2122

2223
class AssetMediaRepository {
2324
final AssetApiRepository _assetApiRepository;
25+
2426
static final Logger _log = Logger("AssetMediaRepository");
2527

2628
const AssetMediaRepository(this._assetApiRepository);
2729

28-
Future<List<String>> deleteAll(List<String> ids) => PhotoManager.editor.deleteWithIds(ids);
30+
Future<List<String>> deleteAll(List<String> ids) async {
31+
if (CurrentPlatform.isIOS) {
32+
return PhotoManager.editor.deleteWithIds(ids);
33+
} else if (CurrentPlatform.isAndroid) {
34+
final androidInfo = await DeviceInfoPlugin().androidInfo;
35+
if (androidInfo.version.sdkInt < 30) {
36+
return PhotoManager.editor.deleteWithIds(ids);
37+
}
38+
return PhotoManager.editor.android.moveToTrash(
39+
// Only the id is needed
40+
ids.map((id) => AssetEntity(id: id, width: 1, height: 1, typeInt: 0)).toList(),
41+
);
42+
}
43+
return [];
44+
}
2945

3046
Future<asset_entity.Asset?> get(String id) async {
3147
final entity = await AssetEntity.fromId(id);

mobile/lib/widgets/asset_grid/delete_dialog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class DeleteLocalOnlyDialog extends StatelessWidget {
2222
@override
2323
Widget build(BuildContext context) {
2424
void onDeleteBackedUpOnly() {
25-
context.pop();
25+
context.pop(true);
2626
onDeleteLocal(true);
2727
}
2828

2929
void onForceDelete() {
30-
context.pop();
30+
context.pop(false);
3131
onDeleteLocal(false);
3232
}
3333

0 commit comments

Comments
 (0)