diff --git a/musikr/src/main/java/org/oxycblt/musikr/Musikr.kt b/musikr/src/main/java/org/oxycblt/musikr/Musikr.kt index 580debe92..29e5ff67f 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/Musikr.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/Musikr.kt @@ -57,26 +57,6 @@ interface Musikr { locations: List, onProgress: suspend (IndexingProgress) -> Unit = {} ): LibraryResult - - /** - * Update a music location with a set of subdirectories to exclude from scanning. - * - * @param context The context to use for loading resources. - * @param uri The URI of the music location to update. - * @param excludedSubdirs The set of subdirectory names to exclude when scanning this location. - * @return The updated [MusicLocation] or null if the location doesn't exist. - */ - fun updateLocationExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set): MusicLocation? - - /** - * Create a new music location with a set of subdirectories to exclude from scanning. - * - * @param context The context to use for loading resources. - * @param uri The URI of the music location to create. - * @param excludedSubdirs The set of subdirectory names to exclude when scanning this location. - * @return The new [MusicLocation] or null if the location couldn't be created. - */ - fun newLocationWithExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set): MusicLocation? companion object { /** @@ -136,14 +116,6 @@ private class MusikrImpl( private val extractStep: ExtractStep, private val evaluateStep: EvaluateStep ) : Musikr { - override fun updateLocationExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set): MusicLocation? { - return MusicLocation.existing(context, uri, excludedSubdirs) - } - - override fun newLocationWithExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set): MusicLocation? { - return MusicLocation.new(context, uri, excludedSubdirs) - } - override suspend fun run( locations: List, onProgress: suspend (IndexingProgress) -> Unit diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/MusicLocation.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/MusicLocation.kt index 37baa94b9..636d16c61 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/MusicLocation.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/MusicLocation.kt @@ -26,7 +26,7 @@ import org.oxycblt.musikr.fs.device.contentResolverSafe import org.oxycblt.musikr.fs.path.DocumentPathFactory import org.oxycblt.musikr.util.splitEscaped -class MusicLocation private constructor(val uri: Uri, val path: Path, val excludedSubdirs: Set = emptySet()) { +class MusicLocation private constructor(val uri: Uri, val path: Path) { override fun equals(other: Any?) = other is MusicLocation && uri == other.uri override fun hashCode() = 31 * uri.hashCode() @@ -34,7 +34,7 @@ class MusicLocation private constructor(val uri: Uri, val path: Path, val exclud override fun toString(): String = uri.toString() companion object { - fun new(context: Context, uri: Uri, excludedSubdirs: Set = emptySet()): MusicLocation? { + fun new(context: Context, uri: Uri): MusicLocation? { if (!DocumentsContract.isTreeUri(uri)) return null val documentPathFactory = DocumentPathFactory.from(context) val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null @@ -47,10 +47,10 @@ class MusicLocation private constructor(val uri: Uri, val path: Path, val exclud uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) } - return MusicLocation(uri, path, excludedSubdirs) + return MusicLocation(uri, path) } - fun existing(context: Context, uri: Uri, excludedSubdirs: Set = emptySet()): MusicLocation? { + fun existing(context: Context, uri: Uri): MusicLocation? { val documentPathFactory = DocumentPathFactory.from(context) if (!DocumentsContract.isTreeUri(uri)) return null val notPersisted = @@ -59,28 +59,14 @@ class MusicLocation private constructor(val uri: Uri, val path: Path, val exclud } if (notPersisted) return null val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null - return MusicLocation(uri, path, excludedSubdirs) + return MusicLocation(uri, path) } - fun toString(list: List): String { - return list.joinToString(";") { location -> - val uriStr = location.uri.toString().replace(";", "\\;") - val excludedSubdirsStr = location.excludedSubdirs.joinToString(",") { it.replace(",", "\\,").replace(";", "\\;") } - if (excludedSubdirsStr.isEmpty()) uriStr else "$uriStr|$excludedSubdirsStr" - } - } + fun toString(list: List) = + list.joinToString(";") { it.uri.toString().replace(";", "\\;") } fun existing(context: Context, string: String): List { - return string.splitEscaped { it == ';' }.mapNotNull { entry -> - val parts = entry.split("|", limit = 2) - val uriStr = parts[0] - val excludedSubdirs = if (parts.size > 1) { - parts[1].splitEscaped { it == ',' }.toSet() - } else { - emptySet() - } - existing(context, Uri.parse(uriStr), excludedSubdirs) - } + return string.splitEscaped { it == ';' }.mapNotNull { existing(context, Uri.parse(it)) } } } } diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/device/DeviceFS.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/device/DeviceFS.kt index 346d02132..c0c27f5ae 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/device/DeviceFS.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/device/DeviceFS.kt @@ -22,6 +22,7 @@ import android.content.ContentResolver import android.content.Context import android.net.Uri import android.provider.DocumentsContract +import android.util.Log import androidx.core.net.toUri import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -39,7 +40,6 @@ import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.flow.takeWhile -import kotlinx.coroutines.flow.transform import org.oxycblt.musikr.fs.MusicLocation import org.oxycblt.musikr.fs.Path @@ -76,7 +76,7 @@ private class DeviceFSImpl( if (modifiedMs == null) { return null } - return query(location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree, location.excludedSubdirs) + return query(location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree) } private suspend fun query( @@ -85,14 +85,13 @@ private class DeviceFSImpl( path: Path, modifiedMs: Long, parent: DeviceDirectory?, - fileTree: FileTree, - excludedSubdirs: Set = emptySet() + fileTree: FileTree ): DeviceDirectory = coroutineScope { val uri = DocumentsContract.buildDocumentUriUsingTree(rootUri, treeDocumentId) val cached = fileTree.queryDirectory(uri) if (cached != null && cached.modifiedMs == modifiedMs) { return@coroutineScope hydrateCached( - cached = cached, parentDir = parent, path = path, fileTree = fileTree, excludedSubdirs = excludedSubdirs) + cached = cached, parentDir = parent, path = path, fileTree = fileTree) } val dir = DeviceDirectoryImpl( @@ -103,6 +102,7 @@ private class DeviceFSImpl( children = emptyFlow()) dir.children = flow { + Log.d("DeviceFS", "Querying $uri") contentResolver.useQuery( DocumentsContract.buildChildDocumentsUriUsingTree( rootUri, @@ -129,6 +129,8 @@ private class DeviceFSImpl( val childSubdirUris = mutableListOf() val childFileUris = mutableListOf() + val subqueries = mutableListOf() + while (cursor.moveToNext()) { val childId = cursor.getString(childUriIndex) val displayName = cursor.getString(displayNameIndex) @@ -143,11 +145,6 @@ private class DeviceFSImpl( val lastModified = cursor.getLong(lastModifiedIndex) if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) { - // Skip this directory if it's in the excluded list - if (displayName in excludedSubdirs) { - continue - } - val subdir = query( rootUri = rootUri, @@ -155,11 +152,11 @@ private class DeviceFSImpl( path = newPath, modifiedMs = modifiedMs, parent = dir, - fileTree = fileTree, - excludedSubdirs = excludedSubdirs) + fileTree = fileTree) childSubdirUris.add(subdir.uri.toString()) emit(StreamedFile.More(subdir)) } else { + Log.d("DeviceFS", "Querying file $childId") val size = cursor.getLong(sizeIndex) val childUri = DocumentsContract.buildDocumentUriUsingTree( @@ -205,8 +202,7 @@ private class DeviceFSImpl( cached: CachedDirectory, parentDir: DeviceDirectory?, path: Path, - fileTree: FileTree, - excludedSubdirs: Set = emptySet() + fileTree: FileTree ): DeviceDirectory = coroutineScope { val dir = DeviceDirectoryImpl( @@ -219,23 +215,17 @@ private class DeviceFSImpl( flow { emitAll( merge( - cached.subdirUris.asFlow().transform { subdirUriString -> + cached.subdirUris.asFlow().map { subdirUriString -> val subdirUri = subdirUriString.toUri() val cachedSubdir = requireNotNull(fileTree.queryDirectory(subdirUri)) { "No cached subdir for $subdirUri, malformed cache! Rescan needed." } - // Skip this directory if it's in the excluded list - if (cachedSubdir.name in excludedSubdirs) { - return@transform - } - - emit(hydrateCached( + hydrateCached( cachedSubdir, dir, dir.path.file(cachedSubdir.name), - fileTree, - excludedSubdirs)) + fileTree) }, cached.fileUris.asFlow().map { val cachedFile = requireNotNull(fileTree.queryFile(it.toUri()))