@@ -22,6 +22,7 @@ import android.content.ContentResolver
2222import android.content.Context
2323import android.net.Uri
2424import android.provider.DocumentsContract
25+ import android.util.Log
2526import androidx.core.net.toUri
2627import kotlinx.coroutines.CoroutineScope
2728import kotlinx.coroutines.Dispatchers
@@ -39,7 +40,6 @@ import kotlinx.coroutines.flow.mapNotNull
3940import kotlinx.coroutines.flow.merge
4041import kotlinx.coroutines.flow.shareIn
4142import kotlinx.coroutines.flow.takeWhile
42- import kotlinx.coroutines.flow.transform
4343import org.oxycblt.musikr.fs.MusicLocation
4444import org.oxycblt.musikr.fs.Path
4545
@@ -76,7 +76,7 @@ private class DeviceFSImpl(
7676 if (modifiedMs == null ) {
7777 return null
7878 }
79- return query(location.uri, treeDocumentId, location.path, modifiedMs, null , fileTree, location.excludedSubdirs )
79+ return query(location.uri, treeDocumentId, location.path, modifiedMs, null , fileTree)
8080 }
8181
8282 private suspend fun query (
@@ -85,14 +85,13 @@ private class DeviceFSImpl(
8585 path : Path ,
8686 modifiedMs : Long ,
8787 parent : DeviceDirectory ? ,
88- fileTree : FileTree ,
89- excludedSubdirs : Set <String > = emptySet()
88+ fileTree : FileTree
9089 ): DeviceDirectory = coroutineScope {
9190 val uri = DocumentsContract .buildDocumentUriUsingTree(rootUri, treeDocumentId)
9291 val cached = fileTree.queryDirectory(uri)
9392 if (cached != null && cached.modifiedMs == modifiedMs) {
9493 return @coroutineScope hydrateCached(
95- cached = cached, parentDir = parent, path = path, fileTree = fileTree, excludedSubdirs = excludedSubdirs )
94+ cached = cached, parentDir = parent, path = path, fileTree = fileTree)
9695 }
9796 val dir =
9897 DeviceDirectoryImpl (
@@ -103,6 +102,7 @@ private class DeviceFSImpl(
103102 children = emptyFlow())
104103 dir.children =
105104 flow {
105+ Log .d(" DeviceFS" , " Querying $uri " )
106106 contentResolver.useQuery(
107107 DocumentsContract .buildChildDocumentsUriUsingTree(
108108 rootUri,
@@ -129,6 +129,8 @@ private class DeviceFSImpl(
129129 val childSubdirUris = mutableListOf<String >()
130130 val childFileUris = mutableListOf<String >()
131131
132+ val subqueries = mutableListOf<DeviceDirectory >()
133+
132134 while (cursor.moveToNext()) {
133135 val childId = cursor.getString(childUriIndex)
134136 val displayName = cursor.getString(displayNameIndex)
@@ -143,23 +145,18 @@ private class DeviceFSImpl(
143145 val lastModified = cursor.getLong(lastModifiedIndex)
144146
145147 if (mimeType == DocumentsContract .Document .MIME_TYPE_DIR ) {
146- // Skip this directory if it's in the excluded list
147- if (displayName in excludedSubdirs) {
148- continue
149- }
150-
151148 val subdir =
152149 query(
153150 rootUri = rootUri,
154151 treeDocumentId = childId,
155152 path = newPath,
156153 modifiedMs = modifiedMs,
157154 parent = dir,
158- fileTree = fileTree,
159- excludedSubdirs = excludedSubdirs)
155+ fileTree = fileTree)
160156 childSubdirUris.add(subdir.uri.toString())
161157 emit(StreamedFile .More (subdir))
162158 } else {
159+ Log .d(" DeviceFS" , " Querying file $childId " )
163160 val size = cursor.getLong(sizeIndex)
164161 val childUri =
165162 DocumentsContract .buildDocumentUriUsingTree(
@@ -205,8 +202,7 @@ private class DeviceFSImpl(
205202 cached : CachedDirectory ,
206203 parentDir : DeviceDirectory ? ,
207204 path : Path ,
208- fileTree : FileTree ,
209- excludedSubdirs : Set <String > = emptySet()
205+ fileTree : FileTree
210206 ): DeviceDirectory = coroutineScope {
211207 val dir =
212208 DeviceDirectoryImpl (
@@ -219,23 +215,17 @@ private class DeviceFSImpl(
219215 flow {
220216 emitAll(
221217 merge(
222- cached.subdirUris.asFlow().transform { subdirUriString ->
218+ cached.subdirUris.asFlow().map { subdirUriString ->
223219 val subdirUri = subdirUriString.toUri()
224220 val cachedSubdir =
225221 requireNotNull(fileTree.queryDirectory(subdirUri)) {
226222 " No cached subdir for $subdirUri , malformed cache! Rescan needed."
227223 }
228- // Skip this directory if it's in the excluded list
229- if (cachedSubdir.name in excludedSubdirs) {
230- return @transform
231- }
232-
233- emit(hydrateCached(
224+ hydrateCached(
234225 cachedSubdir,
235226 dir,
236227 dir.path.file(cachedSubdir.name),
237- fileTree,
238- excludedSubdirs))
228+ fileTree)
239229 },
240230 cached.fileUris.asFlow().map {
241231 val cachedFile = requireNotNull(fileTree.queryFile(it.toUri()))
0 commit comments