mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix: show dialog before delete local action (#22280)
* fix: show dialog on delete local action # Conflicts: # mobile/lib/repositories/asset_media.repository.dart * button style --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
8473dab684
commit
dbee133764
7 changed files with 80 additions and 29 deletions
|
|
@ -56,6 +56,8 @@ sealed class BaseAsset {
|
||||||
|
|
||||||
// Overridden in subclasses
|
// Overridden in subclasses
|
||||||
AssetState get storage;
|
AssetState get storage;
|
||||||
|
String? get localId;
|
||||||
|
String? get remoteId;
|
||||||
String get heroTag;
|
String get heroTag;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ part of 'base_asset.model.dart';
|
||||||
|
|
||||||
class LocalAsset extends BaseAsset {
|
class LocalAsset extends BaseAsset {
|
||||||
final String id;
|
final String id;
|
||||||
final String? remoteId;
|
final String? remoteAssetId;
|
||||||
final int orientation;
|
final int orientation;
|
||||||
|
|
||||||
const LocalAsset({
|
const LocalAsset({
|
||||||
required this.id,
|
required this.id,
|
||||||
this.remoteId,
|
String? remoteId,
|
||||||
required super.name,
|
required super.name,
|
||||||
super.checksum,
|
super.checksum,
|
||||||
required super.type,
|
required super.type,
|
||||||
|
|
@ -19,7 +19,13 @@ class LocalAsset extends BaseAsset {
|
||||||
super.isFavorite = false,
|
super.isFavorite = false,
|
||||||
super.livePhotoVideoId,
|
super.livePhotoVideoId,
|
||||||
this.orientation = 0,
|
this.orientation = 0,
|
||||||
});
|
}) : remoteAssetId = remoteId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get localId => id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get remoteId => remoteAssetId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
AssetState get storage => remoteId == null ? AssetState.local : AssetState.merged;
|
AssetState get storage => remoteId == null ? AssetState.local : AssetState.merged;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ enum AssetVisibility { timeline, hidden, archive, locked }
|
||||||
// Model for an asset stored in the server
|
// Model for an asset stored in the server
|
||||||
class RemoteAsset extends BaseAsset {
|
class RemoteAsset extends BaseAsset {
|
||||||
final String id;
|
final String id;
|
||||||
final String? localId;
|
final String? localAssetId;
|
||||||
final String? thumbHash;
|
final String? thumbHash;
|
||||||
final AssetVisibility visibility;
|
final AssetVisibility visibility;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
|
|
@ -13,7 +13,7 @@ class RemoteAsset extends BaseAsset {
|
||||||
|
|
||||||
const RemoteAsset({
|
const RemoteAsset({
|
||||||
required this.id,
|
required this.id,
|
||||||
this.localId,
|
String? localId,
|
||||||
required super.name,
|
required super.name,
|
||||||
required this.ownerId,
|
required this.ownerId,
|
||||||
required super.checksum,
|
required super.checksum,
|
||||||
|
|
@ -28,7 +28,13 @@ class RemoteAsset extends BaseAsset {
|
||||||
this.visibility = AssetVisibility.timeline,
|
this.visibility = AssetVisibility.timeline,
|
||||||
super.livePhotoVideoId,
|
super.livePhotoVideoId,
|
||||||
this.stackId,
|
this.stackId,
|
||||||
});
|
}) : localAssetId = localId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get localId => localAssetId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get remoteId => id;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
AssetState get storage => localId == null ? AssetState.remote : AssetState.merged;
|
AssetState get storage => localId == null ? AssetState.remote : AssetState.merged;
|
||||||
|
|
|
||||||
|
|
@ -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/presentation/widgets/asset_viewer/asset_viewer.state.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
|
||||||
import 'package:immich_mobile/providers/timeline/multiselect.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';
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
||||||
|
|
||||||
/// This delete action has the following behavior:
|
/// This delete action has the following behavior:
|
||||||
|
|
@ -22,7 +23,17 @@ class DeleteLocalActionButton extends ConsumerWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await ref.read(actionProvider.notifier).deleteLocal(source);
|
bool? backedUpOnly = await showDialog<bool>(
|
||||||
|
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();
|
ref.read(multiSelectProvider.notifier).reset();
|
||||||
|
|
||||||
if (source == ActionSource.viewer) {
|
if (source == ActionSource.viewer) {
|
||||||
|
|
|
||||||
|
|
@ -260,8 +260,15 @@ class ActionNotifier extends Notifier<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ActionResult> deleteLocal(ActionSource source) async {
|
Future<ActionResult> deleteLocal(ActionSource source, bool backedUpOnly) async {
|
||||||
final ids = _getLocalIdsForSource(source);
|
final List<String> 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 {
|
try {
|
||||||
final deletedCount = await _service.deleteLocal(ids);
|
final deletedCount = await _service.deleteLocal(ids);
|
||||||
return ActionResult(count: deletedCount, success: true);
|
return ActionResult(count: deletedCount, success: true);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ final assetMediaRepositoryProvider = Provider((ref) => AssetMediaRepository(ref.
|
||||||
|
|
||||||
class AssetMediaRepository {
|
class AssetMediaRepository {
|
||||||
final AssetApiRepository _assetApiRepository;
|
final AssetApiRepository _assetApiRepository;
|
||||||
|
|
||||||
static final Logger _log = Logger("AssetMediaRepository");
|
static final Logger _log = Logger("AssetMediaRepository");
|
||||||
|
|
||||||
const AssetMediaRepository(this._assetApiRepository);
|
const AssetMediaRepository(this._assetApiRepository);
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ class DeleteLocalOnlyDialog extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
void onDeleteBackedUpOnly() {
|
void onDeleteBackedUpOnly() {
|
||||||
context.pop();
|
context.pop(true);
|
||||||
onDeleteLocal(true);
|
onDeleteLocal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onForceDelete() {
|
void onForceDelete() {
|
||||||
context.pop();
|
context.pop(false);
|
||||||
onDeleteLocal(false);
|
onDeleteLocal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,26 +36,44 @@ class DeleteLocalOnlyDialog extends StatelessWidget {
|
||||||
title: const Text("delete_dialog_title").tr(),
|
title: const Text("delete_dialog_title").tr(),
|
||||||
content: const Text("delete_dialog_alert_local_non_backed_up").tr(),
|
content: const Text("delete_dialog_alert_local_non_backed_up").tr(),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
SizedBox(
|
||||||
onPressed: () => context.pop(),
|
width: double.infinity,
|
||||||
child: Text(
|
height: 48,
|
||||||
"cancel",
|
child: FilledButton(
|
||||||
style: TextStyle(color: context.primaryColor, fontWeight: FontWeight.bold),
|
onPressed: () => context.pop(),
|
||||||
).tr(),
|
style: FilledButton.styleFrom(
|
||||||
|
backgroundColor: context.colorScheme.surfaceDim,
|
||||||
|
foregroundColor: context.primaryColor,
|
||||||
|
),
|
||||||
|
child: const Text("cancel", style: TextStyle(fontWeight: FontWeight.bold)).tr(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
const SizedBox(height: 8),
|
||||||
onPressed: onDeleteBackedUpOnly,
|
SizedBox(
|
||||||
child: Text(
|
width: double.infinity,
|
||||||
"delete_local_dialog_ok_backed_up_only",
|
height: 48,
|
||||||
style: TextStyle(color: context.colorScheme.tertiary, fontWeight: FontWeight.bold),
|
|
||||||
).tr(),
|
child: FilledButton(
|
||||||
|
onPressed: onDeleteBackedUpOnly,
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
backgroundColor: context.colorScheme.errorContainer,
|
||||||
|
foregroundColor: context.colorScheme.onErrorContainer,
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
"delete_local_dialog_ok_backed_up_only",
|
||||||
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
).tr(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
const SizedBox(height: 8),
|
||||||
onPressed: onForceDelete,
|
SizedBox(
|
||||||
child: Text(
|
width: double.infinity,
|
||||||
"delete_local_dialog_ok_force",
|
height: 48,
|
||||||
style: TextStyle(color: Colors.red[400], fontWeight: FontWeight.bold),
|
child: FilledButton(
|
||||||
).tr(),
|
onPressed: onForceDelete,
|
||||||
|
style: FilledButton.styleFrom(backgroundColor: Colors.red[400], foregroundColor: Colors.white),
|
||||||
|
child: const Text("delete_local_dialog_ok_force", style: TextStyle(fontWeight: FontWeight.bold)).tr(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue