mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
refactor code
rollback changes in BackgroundServicePlugin
This commit is contained in:
parent
558e1e7654
commit
a89a35beed
4 changed files with 7 additions and 48 deletions
|
|
@ -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<Uri>? = 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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository {
|
|||
return _db.managers.localAssetEntity.filter((e) => e.checksum.isNull().not()).count();
|
||||
}
|
||||
|
||||
Future<List<LocalAsset>> getAssetsByChecksums(Iterable<String> checksums) {
|
||||
Future<List<LocalAsset>> getByChecksums(Iterable<String> 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();
|
||||
|
|
|
|||
|
|
@ -254,22 +254,12 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
|
|||
return _db.managers.remoteAssetEntity.count();
|
||||
}
|
||||
|
||||
Future<List<RemoteAsset>> getAssetsByChecksums(Iterable<String> checksums, {bool? isTrashed}) {
|
||||
Future<List<RemoteAsset>> getByChecksums(Iterable<String> checksums, {bool? isTrashed}) {
|
||||
if (checksums.isEmpty) return Future.value([]);
|
||||
final conditions = <Expression<bool>>[
|
||||
_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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue