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 14 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
33 changes: 28 additions & 5 deletions mobile/lib/providers/asset.provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/providers/memory.provider.dart';
import 'package:immich_mobile/repositories/asset_media.repository.dart';
Expand All @@ -14,6 +15,7 @@ import 'package:immich_mobile/services/sync.service.dart';
import 'package:immich_mobile/services/user.service.dart';
import 'package:immich_mobile/utils/db.dart';
import 'package:immich_mobile/utils/renderlist_generator.dart';
import 'package:immich_mobile/widgets/common/immich_toast.dart';
import 'package:isar/isar.dart';
import 'package:logging/logging.dart';

Expand Down Expand Up @@ -78,27 +80,48 @@ class AssetNotifier extends StateNotifier<bool> {
}

Future<bool> deleteLocalOnlyAssets(
BuildContext context,
Iterable<Asset> deleteAssets, {
bool onlyBackedUp = false,
}) async {
_deleteInProgress = true;
state = true;
try {
// Filter local assets based on the backup status (`isRemote`).
// If `onlyBackedUp` is true, only select assets that are also present on the server (`isRemote`).
final assetsToDelete = deleteAssets
.where((e) => e.isLocal && (!onlyBackedUp || e.isRemote))
.toList();

if (assetsToDelete.isEmpty) {
// No assets to delete, exit early
ImmichToast.show(
context: context,
msg: 'No backed-up assets selected for deletion.',
gravity: ToastGravity.BOTTOM,
);
yashrajjain726 marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

// Continue with deletion of the filtered assets
final assets = onlyBackedUp
? deleteAssets.where((e) => e.storage == AssetState.merged)
: deleteAssets;
yashrajjain726 marked this conversation as resolved.
Show resolved Hide resolved
? assetsToDelete.where((e) => e.storage == AssetState.merged)
: assetsToDelete;

final localDeleted = await _deleteLocalAssets(assets);
if (localDeleted.isNotEmpty) {
final localOnlyIds = deleteAssets
final localOnlyIds = assetsToDelete
.where((e) => e.storage == AssetState.local)
.map((e) => e.id)
.toList();
// Update merged assets to remote only
final mergedAssets =
deleteAssets.where((e) => e.storage == AssetState.merged).map((e) {
yashrajjain726 marked this conversation as resolved.
Show resolved Hide resolved
final mergedAssets = assetsToDelete
.where((e) => e.storage == AssetState.merged)
.map((e) {
e.localId = null;
return e;
}).toList();

await _db.writeTxn(() async {
if (mergedAssets.isNotEmpty) {
await _db.assets.putAll(mergedAssets);
Expand Down
5 changes: 3 additions & 2 deletions mobile/lib/widgets/asset_grid/multiselect_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ class MultiselectGrid extends HookConsumerWidget {
processing.value = true;
try {
final localIds = selection.value.where((a) => a.isLocal).toList();

final isDeleted = await ref
.read(assetProvider.notifier)
.deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp);
.deleteLocalOnlyAssets(context, localIds,
onlyBackedUp: onlyBackedUp);

if (isDeleted) {
ImmichToast.show(
context: context,
Expand Down
Loading