fix(trash-sync): clean up NativeSyncApiImplBase and correct applyDelta

This commit is contained in:
Peter Ombodi 2025-10-14 18:10:53 +03:00
parent 89d2d04ae4
commit 5582a08c3a
3 changed files with 11 additions and 11 deletions

View file

@ -243,15 +243,13 @@ class BackgroundServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
return
}
val primary = ContentUris.withAppendedId(contentUriForType(type), id)
val fallback = ContentUris.withAppendedId(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL), id)
val uri = ContentUris.withAppendedId(contentUriForType(type), id)
try {
Log.i(TAG, "restoreFromTrashById: primary=$primary (type=$type,id=$id)")
restoreUris(listOf(primary), result)
Log.i(TAG, "restoreFromTrashById: uri=$uri (type=$type,id=$id)")
restoreUris(listOf(uri), result)
} catch (e: Exception) {
Log.w(TAG, "restoreFromTrashById: primary failed, try fallback=$fallback", e)
restoreUris(listOf(fallback), result)
Log.w(TAG, "restoreFromTrashById failed", e)
}
}

View file

@ -32,12 +32,12 @@ sealed class AssetResult {
open class NativeSyncApiImplBase(context: Context) {
private val ctx: Context = context.applicationContext
internal var hashTask: Job? = null
private var hashTask: Job? = null
companion object {
private const val MAX_CONCURRENT_HASH_OPERATIONS = 16
internal val hashSemaphore = Semaphore(MAX_CONCURRENT_HASH_OPERATIONS)
internal const val HASHING_CANCELLED_CODE = "HASH_CANCELLED"
private val hashSemaphore = Semaphore(MAX_CONCURRENT_HASH_OPERATIONS)
private const val HASHING_CANCELLED_CODE = "HASH_CANCELLED"
const val MEDIA_SELECTION =
"(${MediaStore.Files.FileColumns.MEDIA_TYPE} = ? OR ${MediaStore.Files.FileColumns.MEDIA_TYPE} = ?)"
@ -59,7 +59,7 @@ open class NativeSyncApiImplBase(context: Context) {
add(MediaStore.MediaColumns.HEIGHT)
add(MediaStore.MediaColumns.DURATION)
add(MediaStore.MediaColumns.ORIENTATION)
// only available on Android 11 and above
// IS_FAVORITE is only available on Android 11 and above
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
add(MediaStore.MediaColumns.IS_FAVORITE)
}
@ -138,6 +138,7 @@ open class NativeSyncApiImplBase(context: Context) {
val bucketId = c.getString(bucketIdColumn)
val orientation = c.getInt(orientationColumn)
val isFavorite = if (favoriteColumn == -1) false else c.getInt(favoriteColumn) != 0
val asset = PlatformAsset(
id,
name,

View file

@ -133,8 +133,9 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
albumId: item.albumId,
name: item.asset.name,
type: item.asset.type,
checksum: effectiveChecksum == null ? const Value.absent() : Value(effectiveChecksum),
checksum: Value(effectiveChecksum),
createdAt: Value(item.asset.createdAt),
updatedAt: Value(item.asset.updatedAt),
width: Value(item.asset.width),
height: Value(item.asset.height),
durationInSeconds: Value(item.asset.durationInSeconds),