diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/BackgroundServicePlugin.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/BackgroundServicePlugin.kt index b28bc7a08f..ae2ec22a71 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/BackgroundServicePlugin.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/BackgroundServicePlugin.kt @@ -5,7 +5,6 @@ import android.content.ContentResolver import android.content.ContentUris import android.content.Context import android.content.Intent -import android.media.MediaScannerConnection import android.net.Uri import android.os.Build import android.os.Bundle @@ -38,7 +37,6 @@ class BackgroundServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler, private val permissionRequestCode = 1001 private val trashRequestCode = 1002 private var activityBinding: ActivityPluginBinding? = null - private var lastToggledUris: List? = null override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { onAttachedToEngine(binding.applicationContext, binding.binaryMessenger) @@ -233,7 +231,7 @@ class BackgroundServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler, result.error("TrashError", "Activity or ContentResolver not available", null) return } - lastToggledUris = contentUris + try { val pendingIntent = MediaStore.createTrashRequest(contentResolver, contentUris, isTrashed) pendingResult = result // Store for onActivityResult @@ -311,35 +309,6 @@ class BackgroundServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler, if (requestCode == trashRequestCode) { val approved = resultCode == Activity.RESULT_OK - if (approved) { - lastToggledUris?.forEach { uri -> - val projection = arrayOf(MediaStore.MediaColumns.DATA) - try { - val cursor = context?.contentResolver?.query(uri, projection, null, null, null) - if (cursor == null) { - Log.w(TAG, "Cursor is null for URI: $uri") - return@forEach - } - - cursor.use { - if (it.moveToFirst()) { - val path = it.getString(it.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA)) - if (!path.isNullOrBlank()) { - Log.i(TAG, "Scanning updated file: $path") - MediaScannerConnection.scanFile(context, arrayOf(path), null, null) - } else { - Log.w(TAG, "Path is null or blank for URI: $uri") - } - } else { - Log.w(TAG, "Cursor is empty for URI: $uri") - } - } - } catch (e: Exception) { - Log.e(TAG, "Error during rescan for URI: $uri", e) - } - } - } - lastToggledUris = null pendingResult?.success(approved) pendingResult = null return true diff --git a/mobile/lib/domain/services/asset.service.dart b/mobile/lib/domain/services/asset.service.dart index f661128b70..8124e5abfa 100644 --- a/mobile/lib/domain/services/asset.service.dart +++ b/mobile/lib/domain/services/asset.service.dart @@ -107,7 +107,7 @@ class AssetService { if (trashedItems.isNotEmpty) { final trashedAssetsChecksums = trashedItems.map((syncItem) => syncItem.checksum); - final localAssetsToTrash = await _localAssetRepository.getAssetsByChecksums(trashedAssetsChecksums); + final localAssetsToTrash = await _localAssetRepository.getByChecksums(trashedAssetsChecksums); if (localAssetsToTrash.isNotEmpty) { final mediaUrls = await Future.wait( localAssetsToTrash.map( @@ -121,7 +121,7 @@ class AssetService { final modifiedItems = syncItems.where((e) => e.deletedAt == null); if (modifiedItems.isNotEmpty) { final modifiedChecksums = modifiedItems.map((syncItem) => syncItem.checksum); - final remoteAssetsToRestore = await _remoteAssetRepository.getAssetsByChecksums( + final remoteAssetsToRestore = await _remoteAssetRepository.getByChecksums( modifiedChecksums, isTrashed: true, ); diff --git a/mobile/lib/infrastructure/repositories/local_asset.repository.dart b/mobile/lib/infrastructure/repositories/local_asset.repository.dart index 931ddc1473..a33c572e3a 100644 --- a/mobile/lib/infrastructure/repositories/local_asset.repository.dart +++ b/mobile/lib/infrastructure/repositories/local_asset.repository.dart @@ -66,7 +66,7 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository { return _db.managers.localAssetEntity.filter((e) => e.checksum.isNull().not()).count(); } - Future> getAssetsByChecksums(Iterable checksums) { + Future> getByChecksums(Iterable checksums) { if (checksums.isEmpty) return Future.value([]); final query = _db.localAssetEntity.select()..where((lae) => lae.checksum.isIn(checksums)); return query.map((row) => row.toDto()).get(); diff --git a/mobile/lib/infrastructure/repositories/remote_asset.repository.dart b/mobile/lib/infrastructure/repositories/remote_asset.repository.dart index ed8fc217f0..1bb8aaec79 100644 --- a/mobile/lib/infrastructure/repositories/remote_asset.repository.dart +++ b/mobile/lib/infrastructure/repositories/remote_asset.repository.dart @@ -254,22 +254,12 @@ class RemoteAssetRepository extends DriftDatabaseRepository { return _db.managers.remoteAssetEntity.count(); } - Future> getAssetsByChecksums(Iterable checksums, {bool? isTrashed}) { + Future> getByChecksums(Iterable checksums, {bool? isTrashed}) { if (checksums.isEmpty) return Future.value([]); - final conditions = >[ - _db.remoteAssetEntity.checksum.isIn(checksums), - ]; - + final query = _db.remoteAssetEntity.select()..where((rae) => rae.checksum.isIn(checksums)); if (isTrashed != null) { - if (isTrashed) { - conditions.add(_db.remoteAssetEntity.deletedAt.isNotNull()); - } else { - conditions.add(_db.remoteAssetEntity.deletedAt.isNull()); - } + query.where((rae) => isTrashed ? rae.deletedAt.isNotNull() : rae.deletedAt.isNull()); } - - final query = _db.remoteAssetEntity.select()..where((rae) => conditions.reduce((a, b) => a & b)); return query.map((row) => row.toDto()).get(); } - }