Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): do not removed not backup asset when selecting the correspond options #13256

Merged
merged 27 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7085b19
fixed the local ids selecting issue
yashrajjain726 Oct 7, 2024
07bbf08
Merge branch 'main' into fix/11428
yashrajjain726 Oct 7, 2024
00b9bea
Merge branch 'main' into fix/11428
yashrajjain726 Oct 8, 2024
7f18f82
Merge branch 'main' into fix/11428
yashrajjain726 Oct 8, 2024
c266d23
Merge branch 'main' into fix/11428
yashrajjain726 Oct 8, 2024
a52ba17
code: updated impl inside deleteLocalOnlyAssets
yashrajjain726 Oct 9, 2024
a37a247
Merge branch 'main' into fix/11428
yashrajjain726 Oct 9, 2024
04f2ed5
fix: used png instead of jpg to maintain picture quality
yashrajjain726 Oct 9, 2024
9ccfed7
Revert "fix: used png instead of jpg to maintain picture quality"
yashrajjain726 Oct 9, 2024
9de7e71
Merge branch 'main' into fix/11428
yashrajjain726 Oct 9, 2024
b785e41
Merge branch 'main' into fix/11428
yashrajjain726 Oct 9, 2024
3535277
Merge branch 'main' into fix/11428
yashrajjain726 Oct 10, 2024
e7219ec
Merge branch 'main' into fix/11428
yashrajjain726 Oct 11, 2024
385a12b
Merge branch 'main' into fix/11428
yashrajjain726 Oct 12, 2024
15589f7
Merge branch 'main' into fix/11428
yashrajjain726 Oct 14, 2024
508148a
Merge branch 'main' into fix/11428
yashrajjain726 Oct 16, 2024
174ac35
fix: update logic from code-review perspective
yashrajjain726 Oct 16, 2024
f7ea501
Merge branch 'main' into fix/11428
yashrajjain726 Oct 16, 2024
3c57194
refractor (mobile) : Dart fix applied
yashrajjain726 Oct 18, 2024
87dbd0b
Merge branch 'main' into fix/11428
yashrajjain726 Oct 18, 2024
6f12401
Merge branch 'main' into fix/11428
yashrajjain726 Oct 19, 2024
875797f
Merge branch 'main' into fix/11428
yashrajjain726 Oct 20, 2024
6893286
Merge branch 'main' into fix/11428
yashrajjain726 Oct 24, 2024
8dc22f0
fix (mobile) : Updated multi grid as per requirement
yashrajjain726 Oct 24, 2024
b229ac3
Merge branch 'main' into fix/11428
yashrajjain726 Oct 26, 2024
6f58997
Merge branch 'main' into fix/11428
yashrajjain726 Oct 27, 2024
c14c147
Merge branch 'main' of github.com:immich-app/immich into fix/11428
alextran1502 Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions mobile/lib/providers/asset.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,48 @@ class AssetNotifier extends StateNotifier<bool> {
_deleteInProgress = true;
state = true;
try {
// Filter the assets based on the backed-up status
final assets = onlyBackedUp
? deleteAssets.where((e) => e.storage == AssetState.merged)
: deleteAssets;

if (assets.isEmpty) {
return false; // No assets to delete
}

// Proceed with local deletion of the filtered assets
final localDeleted = await _deleteLocalAssets(assets);

if (localDeleted.isNotEmpty) {
final localOnlyIds = deleteAssets
final localOnlyIds = assets
.where((e) => e.storage == AssetState.local)
.map((e) => e.id)
.toList();
// Update merged assets to remote only

// Update merged assets to remote-only
final mergedAssets =
deleteAssets.where((e) => e.storage == AssetState.merged).map((e) {
assets.where((e) => e.storage == AssetState.merged).map((e) {
e.localId = null;
return e;
}).toList();

// Update the local database
await _db.writeTxn(() async {
if (mergedAssets.isNotEmpty) {
await _db.assets.putAll(mergedAssets);
await _db.assets
.putAll(mergedAssets); // Use the filtered merged assets
}
await _db.exifInfos.deleteAll(localOnlyIds);
await _db.assets.deleteAll(localOnlyIds);
});

return true;
}
} finally {
_deleteInProgress = false;
state = false;
}

return false;
}

Expand Down
14 changes: 13 additions & 1 deletion mobile/lib/widgets/asset_grid/multiselect_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,30 @@ class MultiselectGrid extends HookConsumerWidget {
void onDeleteLocal(bool onlyBackedUp) async {
processing.value = true;
try {
// Select only the local assets from the selection
final localIds = selection.value.where((a) => a.isLocal).toList();

// Delete only the backed-up assets if 'onlyBackedUp' is true
final isDeleted = await ref
.read(assetProvider.notifier)
.deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp);
yashrajjain726 marked this conversation as resolved.
Show resolved Hide resolved

if (isDeleted) {
// Show a toast with the correct number of deleted assets
final deletedCount = localIds
.where(
(e) => !onlyBackedUp || e.isRemote,
) // Only count backed-up assets
.length;

ImmichToast.show(
context: context,
msg: 'assets_removed_permanently_from_device'
.tr(args: ["${localIds.length}"]),
.tr(args: ["$deletedCount"]),
gravity: ToastGravity.BOTTOM,
);

// Reset the selection
selectionEnabledHook.value = false;
}
} finally {
Expand Down
Loading