remove toggle inside alert and show different content

This commit is contained in:
shalong-tanwen 2023-11-05 19:07:27 +05:30
parent 5039d68dd1
commit 1270086b43
6 changed files with 14 additions and 88 deletions

View file

@ -148,7 +148,7 @@
"date_format": "E, LLL d, y • h:mm a",
"delete_dialog_alert": "These items will be permanently deleted from Immich and from your device",
"delete_dialog_alert_local": "These items will be permanently removed from your device",
"delete_dialog_alert_merged_only": "Delete only backed up assets",
"delete_dialog_alert_local_non_backed_up": "Some of the items aren't backed up to Immich and will be permanently removed from your device",
"delete_dialog_cancel": "Cancel",
"delete_dialog_ok": "Delete",
"delete_dialog_title": "Delete Permanently",

View file

@ -14,7 +14,7 @@ class ControlBottomAppBar extends ConsumerWidget {
final void Function() onFavorite;
final void Function() onArchive;
final void Function() onDelete;
final void Function(bool onlyMerged) onDeleteLocal;
final void Function() onDeleteLocal;
final Function(Album album) onAddToAlbum;
final void Function() onCreateNewAlbum;
final void Function() onUpload;
@ -109,7 +109,10 @@ class ControlBottomAppBar extends ConsumerWidget {
showDialog(
context: context,
builder: (BuildContext context) {
return DeleteLocalDialog(
return DeleteDialog(
content: selectionAssetState.hasLocal
? "delete_dialog_alert_local_non_backed_up"
: "delete_dialog_alert_local",
onDelete: onDeleteLocal,
);
},

View file

@ -1,86 +1,16 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/ui/confirm_dialog.dart';
class DeleteDialog extends ConfirmDialog {
final Function onDelete;
const DeleteDialog({Key? key, required this.onDelete})
const DeleteDialog({Key? key, required this.onDelete, content})
: super(
key: key,
title: "delete_dialog_title",
content: "delete_dialog_alert",
content: content ?? "delete_dialog_alert",
cancel: "delete_dialog_cancel",
ok: "delete_dialog_ok",
onOk: onDelete,
);
}
class DeleteLocalDialog extends HookConsumerWidget {
final Function(bool onlyMerged) onDelete;
const DeleteLocalDialog({
Key? key,
required this.onDelete,
}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final themeData = Theme.of(context);
final onlyMerged = useState(true);
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
title: const Text("delete_dialog_title").tr(),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("delete_dialog_alert_local").tr(),
Padding(
padding: const EdgeInsets.only(top: 20),
child: SwitchListTile.adaptive(
value: onlyMerged.value,
onChanged: (value) {
onlyMerged.value = value;
},
activeColor: themeData.primaryColor,
dense: true,
title: Text(
"delete_dialog_alert_merged_only",
style: themeData.textTheme.labelLarge
?.copyWith(fontWeight: FontWeight.bold),
).tr(),
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
"delete_dialog_cancel",
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
).tr(),
),
TextButton(
onPressed: () {
onDelete(onlyMerged.value);
Navigator.of(context).pop(true);
},
child: Text(
"delete_dialog_ok",
style: TextStyle(
color: Colors.red[400],
fontWeight: FontWeight.bold,
),
).tr(),
),
],
);
}
}

View file

@ -164,14 +164,14 @@ class HomePage extends HookConsumerWidget {
}
}
void onDeleteLocal(bool onlyMerged) async {
void onDeleteLocal() async {
processing.value = true;
try {
final localIds = selection.value.where((a) => a.isLocal).toList();
final isDeleted = await ref
.read(assetProvider.notifier)
.deleteLocalAssets(localIds, onlyMerged: onlyMerged);
.deleteLocalAssets(localIds);
if (isDeleted) {
final assetOrAssets = localIds.length > 1 ? 'assets' : 'asset';
ImmichToast.show(

View file

@ -92,17 +92,11 @@ class AssetNotifier extends StateNotifier<bool> {
await _syncService.syncNewAssetToDb(newAsset);
}
Future<bool> deleteLocalAssets(
Iterable<Asset> deleteAssets, {
bool onlyMerged = true,
}) async {
Future<bool> deleteLocalAssets(Iterable<Asset> deleteAssets) async {
_deleteInProgress = true;
state = true;
try {
final assets = onlyMerged
? deleteAssets.where((e) => e.storage == AssetState.merged)
: deleteAssets;
final localDeleted = await _deleteLocalAssets(assets);
final localDeleted = await _deleteLocalAssets(deleteAssets);
if (localDeleted.isNotEmpty) {
final localOnlyIds = deleteAssets
.where((e) => e.storage == AssetState.local)

View file

@ -1,8 +1,7 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ConfirmDialog extends ConsumerWidget {
class ConfirmDialog extends StatelessWidget {
final Function onOk;
final String title;
final String content;
@ -19,7 +18,7 @@ class ConfirmDialog extends ConsumerWidget {
}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
Widget build(BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
title: Text(title).tr(),