fixed crash when deleting/recycling trash w/o details

This commit is contained in:
Thibault Deckers 2022-02-23 12:08:18 +09:00
parent 431b88e1d4
commit aa43029e70
4 changed files with 18 additions and 18 deletions

View file

@ -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

View file

@ -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,
)

View file

@ -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)));

View file

@ -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),