Revert "musikr.fs: fully encode dir structure"
This reverts commit baf63b60a0.
This commit is contained in:
@@ -99,7 +99,6 @@ class MutableFSCovers(private val context: Context) : MutableCovers<FDCover> {
|
|||||||
val parent = file.parent.await()
|
val parent = file.parent.await()
|
||||||
val bestCover =
|
val bestCover =
|
||||||
parent.children
|
parent.children
|
||||||
.await()
|
|
||||||
.filterIsInstance<DeviceFile>()
|
.filterIsInstance<DeviceFile>()
|
||||||
.map { it to coverArtScore(it) }
|
.map { it to coverArtScore(it) }
|
||||||
.maxBy { it.second }
|
.maxBy { it.second }
|
||||||
|
|||||||
@@ -50,13 +50,11 @@ private class DeviceFSImpl(
|
|||||||
) : DeviceFS {
|
) : DeviceFS {
|
||||||
override fun explore(locations: Flow<MusicLocation>): Flow<DeviceFile> =
|
override fun explore(locations: Flow<MusicLocation>): Flow<DeviceFile> =
|
||||||
locations.flatMapMerge { location ->
|
locations.flatMapMerge { location ->
|
||||||
val (_, query) =
|
|
||||||
exploreDirectoryImpl(
|
exploreDirectoryImpl(
|
||||||
location.uri,
|
location.uri,
|
||||||
DocumentsContract.getTreeDocumentId(location.uri),
|
DocumentsContract.getTreeDocumentId(location.uri),
|
||||||
location.path,
|
location.path,
|
||||||
null)
|
null)
|
||||||
query
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exploreDirectoryImpl(
|
private fun exploreDirectoryImpl(
|
||||||
@@ -64,13 +62,10 @@ private class DeviceFSImpl(
|
|||||||
treeDocumentId: String,
|
treeDocumentId: String,
|
||||||
relativePath: Path,
|
relativePath: Path,
|
||||||
parent: Deferred<DeviceDirectory>?
|
parent: Deferred<DeviceDirectory>?
|
||||||
): Pair<DeviceDirectory, Flow<DeviceFile>> {
|
): Flow<DeviceFile> = flow {
|
||||||
// Make a kotlin future
|
// Make a kotlin future
|
||||||
val uri = DocumentsContract.buildChildDocumentsUriUsingTree(rootUri, treeDocumentId)
|
val uri = DocumentsContract.buildChildDocumentsUriUsingTree(rootUri, treeDocumentId)
|
||||||
val directoryDeferred = CompletableDeferred<DeviceDirectory>()
|
val directoryDeferred = CompletableDeferred<DeviceDirectory>()
|
||||||
val childrenDeferred = CompletableDeferred<List<DeviceFSEntry>>()
|
|
||||||
val dir = DeviceDirectory(uri, relativePath, parent, childrenDeferred)
|
|
||||||
val query = flow {
|
|
||||||
val recursive = mutableListOf<Flow<DeviceFile>>()
|
val recursive = mutableListOf<Flow<DeviceFile>>()
|
||||||
val children = mutableListOf<DeviceFSEntry>()
|
val children = mutableListOf<DeviceFSEntry>()
|
||||||
contentResolver.useQuery(uri, PROJECTION) { cursor ->
|
contentResolver.useQuery(uri, PROJECTION) { cursor ->
|
||||||
@@ -98,10 +93,8 @@ private class DeviceFSImpl(
|
|||||||
val lastModified = cursor.getLong(lastModifiedIndex)
|
val lastModified = cursor.getLong(lastModifiedIndex)
|
||||||
|
|
||||||
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
|
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
|
||||||
val (dir, query) =
|
recursive.add(
|
||||||
exploreDirectoryImpl(rootUri, childId, newPath, directoryDeferred)
|
exploreDirectoryImpl(rootUri, childId, newPath, directoryDeferred))
|
||||||
children.add(dir)
|
|
||||||
recursive.add(query)
|
|
||||||
} else {
|
} else {
|
||||||
val size = cursor.getLong(sizeIndex)
|
val size = cursor.getLong(sizeIndex)
|
||||||
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
||||||
@@ -117,13 +110,10 @@ private class DeviceFSImpl(
|
|||||||
emit(file)
|
emit(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
childrenDeferred.complete(children)
|
directoryDeferred.complete(DeviceDirectory(uri, relativePath, parent, children))
|
||||||
directoryDeferred.complete(dir)
|
|
||||||
emitAll(recursive.asFlow().flattenMerge())
|
emitAll(recursive.asFlow().flattenMerge())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dir to query
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val PROJECTION =
|
val PROJECTION =
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ data class DeviceDirectory(
|
|||||||
override val uri: Uri,
|
override val uri: Uri,
|
||||||
override val path: Path,
|
override val path: Path,
|
||||||
val parent: Deferred<DeviceDirectory>?,
|
val parent: Deferred<DeviceDirectory>?,
|
||||||
var children: Deferred<List<DeviceFSEntry>>
|
var children: List<DeviceFSEntry>
|
||||||
) : DeviceFSEntry
|
) : DeviceFSEntry
|
||||||
|
|
||||||
data class DeviceFile(
|
data class DeviceFile(
|
||||||
|
|||||||
Reference in New Issue
Block a user