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:
Alexander Capehart
2025-07-04 18:19:52 -06:00
parent 0eb6ba1765
commit 6261fd0957
3 changed files with 5 additions and 85 deletions
@@ -33,6 +33,7 @@ import org.oxycblt.musikr.covers.FDCover
import org.oxycblt.musikr.covers.MutableCovers
import org.oxycblt.musikr.fs.File
import org.oxycblt.musikr.metadata.Metadata
import org.oxycblt.musikr.util.unlikelyToBeNull
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> {
// 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.
val parent = file.parent.await()
val parent = (file.parent ?: return CoverResult.Miss()).await()
val bestCover =
parent.children
.filterIsInstance<File>()
.map { it to coverArtScore(it) }
.maxBy { it.second }
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
// images that are not actually cover art and are just there.,
var score =
(preferredCoverNames + requireNotNull(file.parent.await().path.name))
(preferredCoverNames + requireNotNull(unlikelyToBeNull(file.parent).await().path.name))
.withIndex()
.filter { name.contains(it.value, ignoreCase = true) }
.sumOf { it.index + 1 }
@@ -46,7 +46,7 @@ data class File(
val modifiedMs: Long,
val mimeType: String,
val size: Long,
val parent: Deferred<Directory>
val parent: Deferred<Directory>?
) : FSEntry
sealed interface FSUpdate {
@@ -113,7 +113,6 @@ private constructor(
cursor.getLong(dateModifiedIndex) * 1000 // Convert to milliseconds
// Create file with empty deferred parent
val parentDeferred = CompletableDeferred<Directory>()
val deviceFile =
File(
uri = uri,
@@ -121,16 +120,13 @@ private constructor(
modifiedMs = dateModified,
mimeType = mimeType,
size = size,
parent = parentDeferred)
parent = null)
allFiles.add(deviceFile)
emit(deviceFile)
yield()
}
}
// Build directory hierarchy
buildDirectoryHierarchy(allFiles)
}
override fun track(): Flow<FSUpdate> = callbackFlow {
@@ -141,82 +137,6 @@ private constructor(
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(
val mode: FilterMode,
val filtered: List<Location.Unopened>,