fixed crash when deleting/recycling trash w/o details
This commit is contained in:
parent
431b88e1d4
commit
aa43029e70
4 changed files with 18 additions and 18 deletions
|
@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class ImageOpStreamHandler(private val activity: Activity, private val arguments: Any?) : EventChannel.StreamHandler {
|
class ImageOpStreamHandler(private val activity: Activity, private val arguments: Any?) : EventChannel.StreamHandler {
|
||||||
private val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
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 mimeType = entry.mimeType
|
||||||
val trashed = entry.trashed
|
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 path = if (trashed) entry.trashPath else entry.path
|
||||||
|
|
||||||
val result: FieldMap = hashMapOf(
|
val result: FieldMap = hashMapOf(
|
||||||
// `uri` should reference original content URI,
|
"uri" to uri.toString(),
|
||||||
// so it is different with `sourceUri` when deleting trashed entries
|
|
||||||
"uri" to entry.uri.toString(),
|
|
||||||
)
|
)
|
||||||
if (isCancelledOp()) {
|
if (isCancelledOp()) {
|
||||||
result["skipped"] = true
|
result["skipped"] = true
|
||||||
|
|
|
@ -393,7 +393,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
val mimeType = entry.mimeType
|
val mimeType = entry.mimeType
|
||||||
val trashed = entry.trashed
|
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
|
val sourcePath = if (trashed) entry.trashPath else entry.path
|
||||||
|
|
||||||
var desiredName: String? = null
|
var desiredName: String? = null
|
||||||
|
@ -402,9 +402,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val result: FieldMap = hashMapOf(
|
val result: FieldMap = hashMapOf(
|
||||||
// `uri` should reference original content URI,
|
"uri" to sourceUri.toString(),
|
||||||
// so it is different with `sourceUri` when recycling trashed entries
|
|
||||||
"uri" to entry.uri.toString(),
|
|
||||||
"success" to false,
|
"success" to false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -107,15 +107,7 @@ class MediaStoreSource extends CollectionSource {
|
||||||
await loadCatalogMetadata();
|
await loadCatalogMetadata();
|
||||||
await loadAddresses();
|
await loadAddresses();
|
||||||
updateDerivedFilters();
|
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
|
// trash
|
||||||
await loadTrashDetails();
|
await loadTrashDetails();
|
||||||
unawaited(deleteExpiredTrash().then(
|
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`
|
// verify paths because some apps move files without updating their `last modified date`
|
||||||
debugPrint('$runtimeType refresh ${stopwatch.elapsed} check obsolete paths');
|
debugPrint('$runtimeType refresh ${stopwatch.elapsed} check obsolete paths');
|
||||||
final knownPathByContentId = Map.fromEntries(knownLiveEntries.map((entry) => MapEntry(entry.contentId, entry.path)));
|
final knownPathByContentId = Map.fromEntries(knownLiveEntries.map((entry) => MapEntry(entry.contentId, entry.path)));
|
||||||
|
|
|
@ -78,11 +78,18 @@ class ViewerDebugPage extends StatelessWidget {
|
||||||
'sourceTitle': entry.sourceTitle ?? '',
|
'sourceTitle': entry.sourceTitle ?? '',
|
||||||
'sourceMimeType': entry.sourceMimeType,
|
'sourceMimeType': entry.sourceMimeType,
|
||||||
'mimeType': entry.mimeType,
|
'mimeType': entry.mimeType,
|
||||||
'trashed': '${entry.trashed}',
|
|
||||||
'isMissingAtPath': '${entry.isMissingAtPath}',
|
'isMissingAtPath': '${entry.isMissingAtPath}',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
InfoRowGroup(
|
||||||
|
info: {
|
||||||
|
'trashed': '${entry.trashed}',
|
||||||
|
'trashPath': '${entry.trashDetails?.path}',
|
||||||
|
'trashDateMillis': '${entry.trashDetails?.dateMillis}',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
InfoRowGroup(
|
InfoRowGroup(
|
||||||
info: {
|
info: {
|
||||||
'catalogDateMillis': toDateValue(entry.catalogDateMillis),
|
'catalogDateMillis': toDateValue(entry.catalogDateMillis),
|
||||||
|
|
Loading…
Reference in a new issue