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,65 +62,57 @@ 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 recursive = mutableListOf<Flow<DeviceFile>>()
|
||||||
val dir = DeviceDirectory(uri, relativePath, parent, childrenDeferred)
|
val children = mutableListOf<DeviceFSEntry>()
|
||||||
val query = flow {
|
contentResolver.useQuery(uri, PROJECTION) { cursor ->
|
||||||
val recursive = mutableListOf<Flow<DeviceFile>>()
|
val childUriIndex =
|
||||||
val children = mutableListOf<DeviceFSEntry>()
|
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
|
||||||
contentResolver.useQuery(uri, PROJECTION) { cursor ->
|
val displayNameIndex =
|
||||||
val childUriIndex =
|
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
|
||||||
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
|
val mimeTypeIndex =
|
||||||
val displayNameIndex =
|
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_MIME_TYPE)
|
||||||
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
|
val sizeIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_SIZE)
|
||||||
val mimeTypeIndex =
|
val lastModifiedIndex =
|
||||||
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_MIME_TYPE)
|
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED)
|
||||||
val sizeIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_SIZE)
|
|
||||||
val lastModifiedIndex =
|
|
||||||
cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED)
|
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val childId = cursor.getString(childUriIndex)
|
val childId = cursor.getString(childUriIndex)
|
||||||
val displayName = cursor.getString(displayNameIndex)
|
val displayName = cursor.getString(displayNameIndex)
|
||||||
|
|
||||||
// Skip hidden files/directories if ignoreHidden is true
|
// Skip hidden files/directories if ignoreHidden is true
|
||||||
if (!withHidden && displayName.startsWith(".")) {
|
if (!withHidden && displayName.startsWith(".")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val newPath = relativePath.file(displayName)
|
val newPath = relativePath.file(displayName)
|
||||||
val mimeType = cursor.getString(mimeTypeIndex)
|
val mimeType = cursor.getString(mimeTypeIndex)
|
||||||
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)
|
} else {
|
||||||
recursive.add(query)
|
val size = cursor.getLong(sizeIndex)
|
||||||
} else {
|
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
||||||
val size = cursor.getLong(sizeIndex)
|
val file =
|
||||||
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
DeviceFile(
|
||||||
val file =
|
uri = childUri,
|
||||||
DeviceFile(
|
mimeType = mimeType,
|
||||||
uri = childUri,
|
path = newPath,
|
||||||
mimeType = mimeType,
|
size = size,
|
||||||
path = newPath,
|
modifiedMs = lastModified,
|
||||||
size = size,
|
parent = directoryDeferred)
|
||||||
modifiedMs = lastModified,
|
children.add(file)
|
||||||
parent = directoryDeferred)
|
emit(file)
|
||||||
children.add(file)
|
|
||||||
emit(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
childrenDeferred.complete(children)
|
|
||||||
directoryDeferred.complete(dir)
|
|
||||||
emitAll(recursive.asFlow().flattenMerge())
|
|
||||||
}
|
}
|
||||||
|
directoryDeferred.complete(DeviceDirectory(uri, relativePath, parent, children))
|
||||||
|
emitAll(recursive.asFlow().flattenMerge())
|
||||||
}
|
}
|
||||||
return dir to query
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|||||||
@@ -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