musikr: invert hidden setting

This commit is contained in:
Alexander Capehart
2025-03-03 20:29:25 -07:00
parent 22249cc95b
commit e046aeb671
12 changed files with 39 additions and 37 deletions
@@ -56,6 +56,6 @@ data class Interpretation(
/** What separators delimit multi-value audio tags. */
val separators: Separators,
/** Whether to ignore hidden files and directories (those starting with a dot). */
val ignoreHidden: Boolean
/** Whether to include hidden files and directories (those starting with a dot). */
val withHidden: Boolean
)
@@ -71,7 +71,7 @@ interface Musikr {
fun new(context: Context, storage: Storage, interpretation: Interpretation): Musikr =
MusikrImpl(
storage,
ExploreStep.from(context, storage),
ExploreStep.from(context, storage, interpretation),
ExtractStep.from(context, storage),
EvaluateStep.new(storage, interpretation))
}
@@ -91,15 +91,7 @@ class MutableFSCovers(private val context: Context) : FSCovers(context), Mutable
}
val coverNames =
listOf(
"cover",
"folder",
"album",
"albumart",
"front",
"artwork",
"art",
"folder")
listOf("cover", "folder", "album", "albumart", "front", "artwork", "art", "folder")
val filenameWithoutExt = filename.substringBeforeLast(".")
val extension = filename.substringAfterLast(".", "")
@@ -31,10 +31,11 @@ import org.oxycblt.musikr.fs.MusicLocation
import org.oxycblt.musikr.fs.Path
internal interface DeviceFS {
fun explore(locations: Flow<MusicLocation>, ignoreHidden: Boolean): Flow<DeviceNode>
fun explore(locations: Flow<MusicLocation>): Flow<DeviceNode>
companion object {
fun from(context: Context): DeviceFS = DeviceFSImpl(context.contentResolverSafe)
fun from(context: Context, withHidden: Boolean): DeviceFS =
DeviceFSImpl(context.contentResolverSafe, withHidden)
}
}
@@ -60,8 +61,11 @@ data class DeviceFile(
) : DeviceNode
@OptIn(ExperimentalCoroutinesApi::class)
private class DeviceFSImpl(private val contentResolver: ContentResolver) : DeviceFS {
override fun explore(locations: Flow<MusicLocation>, ignoreHidden: Boolean): Flow<DeviceNode> =
private class DeviceFSImpl(
private val contentResolver: ContentResolver,
private val withHidden: Boolean
) : DeviceFS {
override fun explore(locations: Flow<MusicLocation>): Flow<DeviceNode> =
locations.flatMapMerge { location ->
// Create a root directory for each location
val rootDirectory =
@@ -76,7 +80,7 @@ private class DeviceFSImpl(private val contentResolver: ContentResolver) : Devic
DocumentsContract.getTreeDocumentId(location.uri),
location.path,
rootDirectory,
ignoreHidden)
withHidden)
// Return a flow that emits the root directory
flow { emit(rootDirectory) }
@@ -88,7 +92,7 @@ private class DeviceFSImpl(private val contentResolver: ContentResolver) : Devic
treeDocumentId: String,
relativePath: Path,
parent: DeviceDirectory,
ignoreHidden: Boolean
withHidden: Boolean
): Flow<DeviceNode> = flow {
contentResolver.useQuery(
DocumentsContract.buildChildDocumentsUriUsingTree(rootUri, treeDocumentId),
@@ -108,7 +112,7 @@ private class DeviceFSImpl(private val contentResolver: ContentResolver) : Devic
val displayName = cursor.getString(displayNameIndex)
// Skip hidden files/directories if ignoreHidden is true
if (ignoreHidden && displayName.startsWith(".")) {
if (!withHidden && displayName.startsWith(".")) {
continue
}
@@ -129,7 +133,7 @@ private class DeviceFSImpl(private val contentResolver: ContentResolver) : Devic
// Set up the children flow for this directory
directory.children =
exploreDirectoryImpl(
contentResolver, rootUri, childId, newPath, directory, ignoreHidden)
contentResolver, rootUri, childId, newPath, directory, withHidden)
// Emit the directory node
emit(directory)
@@ -30,6 +30,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import org.oxycblt.musikr.Interpretation
import org.oxycblt.musikr.Storage
import org.oxycblt.musikr.cache.Cache
import org.oxycblt.musikr.cache.CacheResult
@@ -48,9 +49,12 @@ internal interface ExploreStep {
fun explore(locations: List<MusicLocation>): Flow<Explored>
companion object {
fun from(context: Context, storage: Storage): ExploreStep =
fun from(context: Context, storage: Storage, interpretation: Interpretation): ExploreStep =
ExploreStepImpl(
DeviceFS.from(context), storage.cache, storage.covers, storage.storedPlaylists)
DeviceFS.from(context, interpretation.withHidden),
storage.cache,
storage.covers,
storage.storedPlaylists)
}
}
@@ -65,7 +69,9 @@ private class ExploreStepImpl(
val addingMs = System.currentTimeMillis()
return merge(
deviceFS
.explore(locations.asFlow())
.explore(
locations.asFlow(),
)
.flattenFilter { it.mimeType.startsWith("audio/") || it.mimeType == M3U.MIME_TYPE }
.distribute(8)
.distributedMap { file ->