mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
refactor and format code
This commit is contained in:
parent
bec1b30554
commit
ccc86d8440
3 changed files with 27 additions and 32 deletions
|
|
@ -83,15 +83,16 @@ class NativeSyncApiImpl30(context: Context) : NativeSyncApiImplBase(context), Na
|
|||
storedGen.toString(),
|
||||
storedGen.toString()
|
||||
)
|
||||
if (isTrashed) {
|
||||
val uri = MediaStore.Files.getContentUri(volume)
|
||||
val cursor = if (isTrashed) {
|
||||
val queryArgs = Bundle().apply {
|
||||
putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection)
|
||||
putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs)
|
||||
putInt(MediaStore.QUERY_ARG_MATCH_TRASHED, MediaStore.MATCH_ONLY)
|
||||
}
|
||||
|
||||
ctx.contentResolver.query(uri, ASSET_PROJECTION, queryArgs, null).use { cursor ->
|
||||
getCursor(volume, queryArgs)
|
||||
} else {
|
||||
getCursor(volume, selection, selectionArgs)
|
||||
}
|
||||
getAssets(cursor).forEach {
|
||||
when (it) {
|
||||
is AssetResult.ValidAsset -> {
|
||||
|
|
@ -103,19 +104,6 @@ class NativeSyncApiImpl30(context: Context) : NativeSyncApiImplBase(context), Na
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getAssets(getCursor(volume, selection, selectionArgs)).forEach {
|
||||
when (it) {
|
||||
is AssetResult.ValidAsset -> {
|
||||
changed.add(it.asset)
|
||||
assetAlbums[it.asset.id] = listOf(it.albumId)
|
||||
}
|
||||
|
||||
is AssetResult.InvalidAsset -> deleted.add(it.assetId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Unmounted volumes are handled in dart when the album is removed
|
||||
return SyncDelta(hasChanges, changed, deleted, assetAlbums)
|
||||
}
|
||||
|
|
@ -130,19 +118,16 @@ class NativeSyncApiImpl30(context: Context) : NativeSyncApiImplBase(context), Na
|
|||
val selectionArgs = mutableListOf(albumId, *MEDIA_SELECTION_ARGS)
|
||||
|
||||
for (volume in volumes) {
|
||||
val uri = MediaStore.Files.getContentUri(volume)
|
||||
val queryArgs = Bundle().apply {
|
||||
val cursor = getCursor(volume, Bundle().apply {
|
||||
putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection)
|
||||
putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs.toTypedArray())
|
||||
putInt(MediaStore.QUERY_ARG_MATCH_TRASHED, MediaStore.MATCH_ONLY)
|
||||
}
|
||||
|
||||
ctx.contentResolver.query(uri, ASSET_PROJECTION, queryArgs, null).use { cursor ->
|
||||
})
|
||||
getAssets(cursor).forEach { res ->
|
||||
if (res is AssetResult.ValidAsset) trashed += res.asset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trashed
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.ContentUris
|
|||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.Base64
|
||||
import androidx.core.database.getStringOrNull
|
||||
|
|
@ -83,6 +84,16 @@ open class NativeSyncApiImplBase(context: Context) {
|
|||
sortOrder,
|
||||
)
|
||||
|
||||
protected fun getCursor(
|
||||
volume: String,
|
||||
queryArgs: Bundle
|
||||
): Cursor? = ctx.contentResolver.query(
|
||||
MediaStore.Files.getContentUri(volume),
|
||||
ASSET_PROJECTION,
|
||||
queryArgs,
|
||||
null
|
||||
)
|
||||
|
||||
protected fun getAssets(cursor: Cursor?): Sequence<AssetResult> {
|
||||
return sequence {
|
||||
cursor?.use { c ->
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ class TrashedLocalAssetEntity extends Table with DriftDefaultsMixin, AssetEntity
|
|||
|
||||
@override
|
||||
Set<Column> get primaryKey => {id, albumId};
|
||||
|
||||
}
|
||||
|
||||
extension TrashedLocalAssetEntityDataDomainExtension on TrashedLocalAssetEntityData {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue