checkpt
This commit is contained in:
@@ -30,6 +30,7 @@ plugins {
|
|||||||
//noinspection GradlePluginVersion
|
//noinspection GradlePluginVersion
|
||||||
id 'com.android.library' version "$agp_version" apply false
|
id 'com.android.library' version "$agp_version" apply false
|
||||||
id "org.jetbrains.kotlin.android" version "$kotlin_version" apply false
|
id "org.jetbrains.kotlin.android" version "$kotlin_version" apply false
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false
|
||||||
id "com.google.devtools.ksp" version '2.0.21-1.0.25' apply false
|
id "com.google.devtools.ksp" version '2.0.21-1.0.25' apply false
|
||||||
// We use spotless in the root build.gradle to apply to all modules.
|
// We use spotless in the root build.gradle to apply to all modules.
|
||||||
id "com.diffplug.spotless" version "6.25.0" apply true
|
id "com.diffplug.spotless" version "6.25.0" apply true
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ plugins {
|
|||||||
id 'com.android.library'
|
id 'com.android.library'
|
||||||
id 'org.jetbrains.kotlin.android'
|
id 'org.jetbrains.kotlin.android'
|
||||||
id "com.google.devtools.ksp"
|
id "com.google.devtools.ksp"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
id "com.diffplug.spotless"
|
id "com.diffplug.spotless"
|
||||||
id "kotlin-parcelize"
|
id "kotlin-parcelize"
|
||||||
id "org.jetbrains.dokka"
|
id "org.jetbrains.dokka"
|
||||||
@@ -62,6 +63,8 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||||
|
|
||||||
|
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0'
|
||||||
|
|
||||||
// AndroidX
|
// AndroidX
|
||||||
implementation "androidx.core:core-ktx:$core_version"
|
implementation "androidx.core:core-ktx:$core_version"
|
||||||
|
|
||||||
|
|||||||
@@ -39,20 +39,21 @@ import org.oxycblt.musikr.fs.MusicLocation
|
|||||||
import org.oxycblt.musikr.fs.Path
|
import org.oxycblt.musikr.fs.Path
|
||||||
|
|
||||||
internal interface DeviceFS {
|
internal interface DeviceFS {
|
||||||
fun explore(locations: Flow<MusicLocation>): Flow<DeviceDirectory>
|
suspend fun explore(locations: Flow<MusicLocation>): Flow<DeviceDirectory>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(context: Context, withHidden: Boolean): DeviceFS =
|
fun from(context: Context, withHidden: Boolean): DeviceFS =
|
||||||
DeviceFSImpl(context.contentResolverSafe, withHidden)
|
DeviceFSImpl(context.contentResolverSafe, JsonFileTreeCache(context), withHidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private class DeviceFSImpl(
|
private class DeviceFSImpl(
|
||||||
private val contentResolver: ContentResolver,
|
private val contentResolver: ContentResolver,
|
||||||
|
private val cache: FileTreeCache,
|
||||||
private val withHidden: Boolean
|
private val withHidden: Boolean
|
||||||
) : DeviceFS {
|
) : DeviceFS {
|
||||||
override fun explore(locations: Flow<MusicLocation>): Flow<DeviceDirectory> =
|
override fun explore(locations: Flow<MusicLocation>): Flow<DeviceDirectory> {
|
||||||
locations.mapNotNull { location ->
|
locations.mapNotNull { location ->
|
||||||
val treeDocumentId =
|
val treeDocumentId =
|
||||||
DocumentsContract.getTreeDocumentId(location.uri)
|
DocumentsContract.getTreeDocumentId(location.uri)
|
||||||
@@ -73,10 +74,11 @@ private class DeviceFSImpl(
|
|||||||
location.uri,
|
location.uri,
|
||||||
treeDocumentId,
|
treeDocumentId,
|
||||||
location.path,
|
location.path,
|
||||||
0,
|
modifiedMs,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun query(
|
private suspend fun query(
|
||||||
rootUri: Uri,
|
rootUri: Uri,
|
||||||
@@ -93,7 +95,6 @@ private class DeviceFSImpl(
|
|||||||
children = emptyFlow()
|
children = emptyFlow()
|
||||||
)
|
)
|
||||||
dir.children = flow {
|
dir.children = flow {
|
||||||
Log.d("DeviceFS", "Finished querying $path")
|
|
||||||
contentResolver.useQuery(
|
contentResolver.useQuery(
|
||||||
DocumentsContract.buildChildDocumentsUriUsingTree(
|
DocumentsContract.buildChildDocumentsUriUsingTree(
|
||||||
rootUri,
|
rootUri,
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Auxio Project
|
||||||
|
* FileTreeCache.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.oxycblt.musikr.fs.device
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import android.util.Log
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
interface FileTreeCache {
|
||||||
|
suspend fun queryRootDirectory(uri: Uri): CachedRoot
|
||||||
|
suspend fun updateRootDirectory(uri: Uri, cachedRoot: CachedRoot)
|
||||||
|
|
||||||
|
suspend fun queryDirectory(uri: Uri): CachedDirectory
|
||||||
|
suspend fun updateDirectory(uri: Uri, directory: CachedDirectory)
|
||||||
|
|
||||||
|
suspend fun queryFile(uri: Uri): CachedFile?
|
||||||
|
suspend fun updateFile(uri: Uri, file: CachedFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CachedRoot(
|
||||||
|
val uri: String,
|
||||||
|
val path: String,
|
||||||
|
val modifiedMs: Long,
|
||||||
|
val childUris: List<String>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class CachedDirectory(
|
||||||
|
val uri: String,
|
||||||
|
val name: String,
|
||||||
|
val modifiedMs: Long,
|
||||||
|
val childUris: List<String>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class CachedFile(
|
||||||
|
val uri: String,
|
||||||
|
val name: String,
|
||||||
|
val modifiedMs: Long,
|
||||||
|
val mimeType: String,
|
||||||
|
val size: Long
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user