mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix: skip local only assets in move to lock action (#22728)
* fix:prefer trashing to deletions * skip local only assets in move to lock action --------- 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
63c2f4415b
commit
265ed0b38f
2 changed files with 28 additions and 3 deletions
|
|
@ -77,11 +77,14 @@ class ActionNotifier extends Notifier<void> {
|
||||||
return _getAssets(source).whereType<RemoteAsset>().toIds().toList(growable: false);
|
return _getAssets(source).whereType<RemoteAsset>().toIds().toList(growable: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> _getLocalIdsForSource(ActionSource source) {
|
List<String> _getLocalIdsForSource(ActionSource source, {bool ignoreLocalOnly = false}) {
|
||||||
final Set<BaseAsset> assets = _getAssets(source);
|
final Set<BaseAsset> assets = _getAssets(source);
|
||||||
final List<String> localIds = [];
|
final List<String> localIds = [];
|
||||||
|
|
||||||
for (final asset in assets) {
|
for (final asset in assets) {
|
||||||
|
if (ignoreLocalOnly && asset.storage != AssetState.merged) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (asset is LocalAsset) {
|
if (asset is LocalAsset) {
|
||||||
localIds.add(asset.id);
|
localIds.add(asset.id);
|
||||||
} else if (asset is RemoteAsset && asset.localId != null) {
|
} else if (asset is RemoteAsset && asset.localId != null) {
|
||||||
|
|
@ -189,7 +192,7 @@ class ActionNotifier extends Notifier<void> {
|
||||||
|
|
||||||
Future<ActionResult> moveToLockFolder(ActionSource source) async {
|
Future<ActionResult> moveToLockFolder(ActionSource source) async {
|
||||||
final ids = _getOwnedRemoteIdsForSource(source);
|
final ids = _getOwnedRemoteIdsForSource(source);
|
||||||
final localIds = _getLocalIdsForSource(source);
|
final localIds = _getLocalIdsForSource(source, ignoreLocalOnly: true);
|
||||||
try {
|
try {
|
||||||
await _service.moveToLockFolder(ids, localIds);
|
await _service.moveToLockFolder(ids, localIds);
|
||||||
return ActionResult(count: ids.length, success: true);
|
return ActionResult(count: ids.length, success: true);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
|
|
@ -25,7 +26,28 @@ class AssetMediaRepository {
|
||||||
|
|
||||||
const AssetMediaRepository(this._assetApiRepository);
|
const AssetMediaRepository(this._assetApiRepository);
|
||||||
|
|
||||||
Future<List<String>> deleteAll(List<String> ids) => PhotoManager.editor.deleteWithIds(ids);
|
Future<bool> _androidSupportsTrash() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||||
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||||
|
int sdkVersion = androidInfo.version.sdkInt;
|
||||||
|
return sdkVersion >= 31;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<String>> deleteAll(List<String> ids) async {
|
||||||
|
if (CurrentPlatform.isAndroid) {
|
||||||
|
if (await _androidSupportsTrash()) {
|
||||||
|
return PhotoManager.editor.android.moveToTrash(
|
||||||
|
ids.map((e) => AssetEntity(id: e, width: 1, height: 1, typeInt: 0)).toList(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return PhotoManager.editor.deleteWithIds(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PhotoManager.editor.deleteWithIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
Future<asset_entity.Asset?> get(String id) async {
|
Future<asset_entity.Asset?> get(String id) async {
|
||||||
final entity = await AssetEntity.fromId(id);
|
final entity = await AssetEntity.fromId(id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue