diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/ImageOpStreamHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/ImageOpStreamHandler.kt index 6d8b1a176..7a8f02ae1 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/ImageOpStreamHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/ImageOpStreamHandler.kt @@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch -import java.io.File class ImageOpStreamHandler(private val activity: Activity, private val arguments: Any?) : EventChannel.StreamHandler { private val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) @@ -109,13 +108,11 @@ class ImageOpStreamHandler(private val activity: Activity, private val arguments val mimeType = entry.mimeType val trashed = entry.trashed - val uri = if (trashed) Uri.fromFile(File(entry.trashPath!!)) else entry.uri + val uri = entry.uri val path = if (trashed) entry.trashPath else entry.path val result: FieldMap = hashMapOf( - // `uri` should reference original content URI, - // so it is different with `sourceUri` when deleting trashed entries - "uri" to entry.uri.toString(), + "uri" to uri.toString(), ) if (isCancelledOp()) { result["skipped"] = true diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt index c17870a08..79f3f4a21 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt @@ -393,7 +393,7 @@ class MediaStoreImageProvider : ImageProvider() { val mimeType = entry.mimeType val trashed = entry.trashed - val sourceUri = if (trashed) Uri.fromFile(File(entry.trashPath!!)) else entry.uri + val sourceUri = entry.uri val sourcePath = if (trashed) entry.trashPath else entry.path var desiredName: String? = null @@ -402,9 +402,7 @@ class MediaStoreImageProvider : ImageProvider() { } val result: FieldMap = hashMapOf( - // `uri` should reference original content URI, - // so it is different with `sourceUri` when recycling trashed entries - "uri" to entry.uri.toString(), + "uri" to sourceUri.toString(), "success" to false, ) diff --git a/lib/model/source/media_store_source.dart b/lib/model/source/media_store_source.dart index 03d433eec..48af4d718 100644 --- a/lib/model/source/media_store_source.dart +++ b/lib/model/source/media_store_source.dart @@ -107,15 +107,7 @@ class MediaStoreSource extends CollectionSource { await loadCatalogMetadata(); await loadAddresses(); updateDerivedFilters(); - } - // clean up obsolete entries - if (removedEntries.isNotEmpty) { - debugPrint('$runtimeType refresh ${stopwatch.elapsed} remove obsolete entries'); - await metadataDb.removeIds(removedEntries.map((entry) => entry.id)); - } - - if (directory != null) { // trash await loadTrashDetails(); unawaited(deleteExpiredTrash().then( @@ -129,6 +121,12 @@ class MediaStoreSource extends CollectionSource { )); } + // clean up obsolete entries + if (removedEntries.isNotEmpty) { + debugPrint('$runtimeType refresh ${stopwatch.elapsed} remove obsolete entries'); + await metadataDb.removeIds(removedEntries.map((entry) => entry.id)); + } + // verify paths because some apps move files without updating their `last modified date` debugPrint('$runtimeType refresh ${stopwatch.elapsed} check obsolete paths'); final knownPathByContentId = Map.fromEntries(knownLiveEntries.map((entry) => MapEntry(entry.contentId, entry.path))); diff --git a/lib/widgets/viewer/debug/debug_page.dart b/lib/widgets/viewer/debug/debug_page.dart index 7fe35f4a7..2fdd44e23 100644 --- a/lib/widgets/viewer/debug/debug_page.dart +++ b/lib/widgets/viewer/debug/debug_page.dart @@ -78,11 +78,18 @@ class ViewerDebugPage extends StatelessWidget { 'sourceTitle': entry.sourceTitle ?? '', 'sourceMimeType': entry.sourceMimeType, 'mimeType': entry.mimeType, - 'trashed': '${entry.trashed}', 'isMissingAtPath': '${entry.isMissingAtPath}', }, ), const Divider(), + InfoRowGroup( + info: { + 'trashed': '${entry.trashed}', + 'trashPath': '${entry.trashDetails?.path}', + 'trashDateMillis': '${entry.trashDetails?.dateMillis}', + }, + ), + const Divider(), InfoRowGroup( info: { 'catalogDateMillis': toDateValue(entry.catalogDateMillis),