musikr: disable mediastore tree construction
Not used except in FS covers, and that won't work with MediaStore as it stands.
This commit is contained in:
@@ -33,6 +33,7 @@ import org.oxycblt.musikr.covers.FDCover
|
|||||||
import org.oxycblt.musikr.covers.MutableCovers
|
import org.oxycblt.musikr.covers.MutableCovers
|
||||||
import org.oxycblt.musikr.fs.File
|
import org.oxycblt.musikr.fs.File
|
||||||
import org.oxycblt.musikr.metadata.Metadata
|
import org.oxycblt.musikr.metadata.Metadata
|
||||||
|
import org.oxycblt.musikr.util.unlikelyToBeNull
|
||||||
|
|
||||||
private const val PREFIX = "mcf:"
|
private const val PREFIX = "mcf:"
|
||||||
|
|
||||||
@@ -96,10 +97,9 @@ class MutableFSCovers(private val context: Context) : MutableCovers<FDCover> {
|
|||||||
override suspend fun create(file: File, metadata: Metadata): CoverResult<FDCover> {
|
override suspend fun create(file: File, metadata: Metadata): CoverResult<FDCover> {
|
||||||
// Since DeviceFiles is a streaming API, we have to wait for the current recursive
|
// Since DeviceFiles is a streaming API, we have to wait for the current recursive
|
||||||
// query to finally finish to be able to have a complete list of siblings to search for.
|
// query to finally finish to be able to have a complete list of siblings to search for.
|
||||||
val parent = file.parent.await()
|
val parent = (file.parent ?: return CoverResult.Miss()).await()
|
||||||
val bestCover =
|
val bestCover =
|
||||||
parent.children
|
parent.children
|
||||||
.filterIsInstance<File>()
|
|
||||||
.map { it to coverArtScore(it) }
|
.map { it to coverArtScore(it) }
|
||||||
.maxBy { it.second }
|
.maxBy { it.second }
|
||||||
if (bestCover.second > 0) {
|
if (bestCover.second > 0) {
|
||||||
@@ -128,7 +128,7 @@ class MutableFSCovers(private val context: Context) : MutableCovers<FDCover> {
|
|||||||
// See if the name contains any of the preferred cover names. This helps weed out
|
// See if the name contains any of the preferred cover names. This helps weed out
|
||||||
// images that are not actually cover art and are just there.,
|
// images that are not actually cover art and are just there.,
|
||||||
var score =
|
var score =
|
||||||
(preferredCoverNames + requireNotNull(file.parent.await().path.name))
|
(preferredCoverNames + requireNotNull(unlikelyToBeNull(file.parent).await().path.name))
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.filter { name.contains(it.value, ignoreCase = true) }
|
.filter { name.contains(it.value, ignoreCase = true) }
|
||||||
.sumOf { it.index + 1 }
|
.sumOf { it.index + 1 }
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ data class File(
|
|||||||
val modifiedMs: Long,
|
val modifiedMs: Long,
|
||||||
val mimeType: String,
|
val mimeType: String,
|
||||||
val size: Long,
|
val size: Long,
|
||||||
val parent: Deferred<Directory>
|
val parent: Deferred<Directory>?
|
||||||
) : FSEntry
|
) : FSEntry
|
||||||
|
|
||||||
sealed interface FSUpdate {
|
sealed interface FSUpdate {
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ private constructor(
|
|||||||
cursor.getLong(dateModifiedIndex) * 1000 // Convert to milliseconds
|
cursor.getLong(dateModifiedIndex) * 1000 // Convert to milliseconds
|
||||||
|
|
||||||
// Create file with empty deferred parent
|
// Create file with empty deferred parent
|
||||||
val parentDeferred = CompletableDeferred<Directory>()
|
|
||||||
val deviceFile =
|
val deviceFile =
|
||||||
File(
|
File(
|
||||||
uri = uri,
|
uri = uri,
|
||||||
@@ -121,16 +120,13 @@ private constructor(
|
|||||||
modifiedMs = dateModified,
|
modifiedMs = dateModified,
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
size = size,
|
size = size,
|
||||||
parent = parentDeferred)
|
parent = null)
|
||||||
|
|
||||||
allFiles.add(deviceFile)
|
allFiles.add(deviceFile)
|
||||||
emit(deviceFile)
|
emit(deviceFile)
|
||||||
yield()
|
yield()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build directory hierarchy
|
|
||||||
buildDirectoryHierarchy(allFiles)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun track(): Flow<FSUpdate> = callbackFlow {
|
override fun track(): Flow<FSUpdate> = callbackFlow {
|
||||||
@@ -141,82 +137,6 @@ private constructor(
|
|||||||
awaitClose { observer.release() }
|
awaitClose { observer.release() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildDirectoryHierarchy(files: List<File>) {
|
|
||||||
// Map to store directories by their path
|
|
||||||
val directoryMap = mutableMapOf<Path, Directory>()
|
|
||||||
|
|
||||||
// Group files by their parent directory path
|
|
||||||
val filesByParent = files.groupBy { it.path.directory }
|
|
||||||
|
|
||||||
// First pass: Create all directories and complete file parent deferreds
|
|
||||||
for ((dirPath, dirFiles) in filesByParent) {
|
|
||||||
val directory =
|
|
||||||
directoryMap.getOrPut(dirPath) {
|
|
||||||
// Create parent deferred for this directory
|
|
||||||
val parentDeferred =
|
|
||||||
if (dirPath.components.components.isEmpty()) {
|
|
||||||
// Root directory has no parent
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
CompletableDeferred<Directory>()
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory(
|
|
||||||
uri = null, // Directories don't have MediaStore URIs
|
|
||||||
path = dirPath,
|
|
||||||
parent = parentDeferred,
|
|
||||||
children = dirFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update children if directory already existed
|
|
||||||
if (directory.children.isEmpty()) {
|
|
||||||
directory.children = dirFiles
|
|
||||||
}
|
|
||||||
|
|
||||||
// Complete parent deferreds for all files in this directory
|
|
||||||
dirFiles.forEach { file ->
|
|
||||||
(file.parent as CompletableDeferred<Directory>).complete(directory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second pass: Create any missing parent directories
|
|
||||||
val directories = directoryMap.values.toList()
|
|
||||||
for (directory in directories) {
|
|
||||||
var currentPath = directory.path
|
|
||||||
while (currentPath.components.components.isNotEmpty()) {
|
|
||||||
val parentPath = currentPath.directory
|
|
||||||
if (!directoryMap.containsKey(parentPath)) {
|
|
||||||
val grandParentDeferred =
|
|
||||||
if (parentPath.components.components.isEmpty()) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
CompletableDeferred<Directory>()
|
|
||||||
}
|
|
||||||
|
|
||||||
directoryMap[parentPath] =
|
|
||||||
Directory(
|
|
||||||
uri = null,
|
|
||||||
path = parentPath,
|
|
||||||
parent = grandParentDeferred,
|
|
||||||
children = emptyList())
|
|
||||||
}
|
|
||||||
currentPath = parentPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Third pass: Complete all directory parent deferreds
|
|
||||||
for (directory in directoryMap.values) {
|
|
||||||
val parentDeferred = directory.parent as? CompletableDeferred<Directory>
|
|
||||||
if (parentDeferred != null && !parentDeferred.isCompleted) {
|
|
||||||
val parentPath = directory.path.directory
|
|
||||||
val parentDirectory = directoryMap[parentPath]
|
|
||||||
if (parentDirectory != null) {
|
|
||||||
parentDeferred.complete(parentDirectory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class Query(
|
data class Query(
|
||||||
val mode: FilterMode,
|
val mode: FilterMode,
|
||||||
val filtered: List<Location.Unopened>,
|
val filtered: List<Location.Unopened>,
|
||||||
|
|||||||
Reference in New Issue
Block a user