music: fixup mediastore query setup
This commit is contained in:
@@ -387,18 +387,17 @@ constructor(
|
||||
} else {
|
||||
Naming.simple()
|
||||
}
|
||||
val locations = musicSettings.musicLocations
|
||||
val excludedLocations = musicSettings.excludedLocations
|
||||
val withHidden = musicSettings.withHidden
|
||||
|
||||
val currentRevision = musicSettings.revision
|
||||
val newRevision = currentRevision?.takeIf { withCache } ?: UUID.randomUUID()
|
||||
val cache = if (withCache) cache else WriteOnlyMutableCache(cache)
|
||||
val covers = settingCovers.mutate(context, newRevision)
|
||||
val fs = when (musicSettings.locationMode) {
|
||||
MusicLocationMode.SAF -> SAF.from(context, musicSettings.safQuery ?: return)
|
||||
MusicLocationMode.SYSTEM -> MediaStoreFS.from(context, musicSettings.mediaStoreQuery ?: return)
|
||||
}
|
||||
val fs =
|
||||
when (musicSettings.locationMode) {
|
||||
MusicLocationMode.SAF -> SAF.from(context, musicSettings.safQuery ?: return)
|
||||
MusicLocationMode.SYSTEM ->
|
||||
MediaStoreFS.from(context, musicSettings.mediaStoreQuery ?: return)
|
||||
}
|
||||
val storage = Storage(cache, covers, storedPlaylists)
|
||||
val interpretation = Interpretation(nameFactory, separators)
|
||||
val config = Config(fs, storage, interpretation)
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
import timber.log.Timber as L
|
||||
|
||||
/**
|
||||
* Represents the mode for loading music locations.
|
||||
*/
|
||||
/** Represents the mode for loading music locations. */
|
||||
enum class MusicLocationMode {
|
||||
/** Use Storage Access Framework (file picker) to select specific folders */
|
||||
SAF,
|
||||
@@ -65,6 +63,12 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
||||
val useFileTreeCache: Boolean
|
||||
/** The mode for loading music locations (SAF or System database). */
|
||||
var locationMode: MusicLocationMode
|
||||
/** The list of music locations to include when using SAF mode. */
|
||||
var musicLocations: List<Location.Opened>
|
||||
/** The list of locations to exclude. */
|
||||
var excludedLocations: List<Location.Unopened>
|
||||
/** Whether to exclude non-music files when using MediaStore. */
|
||||
val excludeNonMusic: Boolean
|
||||
|
||||
interface Listener {
|
||||
/** Called when the current music locations changed. */
|
||||
@@ -141,13 +145,19 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
// MediaStore query is used when in system database mode
|
||||
if (locationMode != MusicLocationMode.SYSTEM) return null
|
||||
|
||||
// Determine filter mode based on whether we have excluded locations
|
||||
val filterMode =
|
||||
if (excludedLocations.isEmpty()) {
|
||||
MediaStoreFS.FilterMode.INCLUDE
|
||||
} else {
|
||||
MediaStoreFS.FilterMode.EXCLUDE
|
||||
}
|
||||
|
||||
return MediaStoreFS.Query(
|
||||
include = emptyList(), // No include filter in system database mode
|
||||
exclude = excludedLocations,
|
||||
excludeNonMusic = excludeNonMusic)
|
||||
mode = filterMode, filtered = excludedLocations, excludeNonMusic = excludeNonMusic)
|
||||
}
|
||||
|
||||
private var musicLocations: List<Location.Opened>
|
||||
override var musicLocations: List<Location.Opened>
|
||||
get() {
|
||||
val locations =
|
||||
sharedPreferences.getString(getString(R.string.set_key_music_locations), null)
|
||||
@@ -164,7 +174,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
}
|
||||
}
|
||||
|
||||
private var excludedLocations: List<Location.Unopened>
|
||||
override var excludedLocations: List<Location.Unopened>
|
||||
get() {
|
||||
val locations =
|
||||
sharedPreferences.getString(getString(R.string.set_key_excluded_locations), null)
|
||||
@@ -180,7 +190,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
}
|
||||
}
|
||||
|
||||
private val excludeNonMusic: Boolean
|
||||
override val excludeNonMusic: Boolean
|
||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
|
||||
|
||||
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Auxio Project
|
||||
* LocationConfig.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.auxio.music.locations
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import org.oxycblt.auxio.util.splitEscaped
|
||||
import org.oxycblt.musikr.fs.Location
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
|
||||
sealed interface LocationConfig {
|
||||
data class Filesystem(private val query: SAF.Query) : LocationConfig
|
||||
|
||||
data class SystemDatabase(private val query: MediaStoreFS.Query) : LocationConfig
|
||||
|
||||
companion object {
|
||||
fun from(context: Context, string: String): LocationConfig? {
|
||||
val typeSplit = string.splitEscaped('!')
|
||||
if (typeSplit.size != 2) return null
|
||||
val type = typeSplit[0]
|
||||
val args = typeSplit[1].splitEscaped('|')
|
||||
return when (type) {
|
||||
"saf" -> {
|
||||
if (args.size < 3) return null
|
||||
val source =
|
||||
args[0]
|
||||
.splitEscaped(';')
|
||||
.map { it.toUri() }
|
||||
.mapNotNull { Location.Unopened.from(context, it)?.open(context) }
|
||||
val exclude =
|
||||
args[1]
|
||||
.splitEscaped(';')
|
||||
.map { it.toUri() }
|
||||
.mapNotNull { Location.Unopened.from(context, it) }
|
||||
val withHidden = args[2].toBoolean()
|
||||
val query =
|
||||
SAF.Query(source = source, exclude = exclude, withHidden = withHidden)
|
||||
Filesystem(query = query)
|
||||
}
|
||||
"media" -> {
|
||||
if (args.size < 3) return null
|
||||
val include =
|
||||
args[0]
|
||||
.splitEscaped(';')
|
||||
.map { it.toUri() }
|
||||
.mapNotNull { Location.Unopened.from(context, it) }
|
||||
val exclude =
|
||||
args[1]
|
||||
.splitEscaped(';')
|
||||
.map { it.toUri() }
|
||||
.mapNotNull { Location.Unopened.from(context, it) }
|
||||
val excludeNonMusic = args[1].toBoolean()
|
||||
SystemDatabase(
|
||||
MediaStoreFS.Query(
|
||||
include = include,
|
||||
exclude = exclude,
|
||||
excludeNonMusic = excludeNonMusic))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,19 +65,22 @@ private constructor(
|
||||
}
|
||||
|
||||
// Handle include/exclude directories
|
||||
if (query.include.isNotEmpty()) {
|
||||
val pathSelector = pathInterpreterFactory.createSelector(query.include.map { it.path })
|
||||
if (pathSelector != null) {
|
||||
selector += " AND (${pathSelector.template})"
|
||||
args.addAll(pathSelector.args)
|
||||
when (query.mode) {
|
||||
FilterMode.INCLUDE -> {
|
||||
val pathSelector =
|
||||
pathInterpreterFactory.createSelector(query.filtered.map { it.path })
|
||||
if (pathSelector != null) {
|
||||
selector += " AND (${pathSelector.template})"
|
||||
args.addAll(pathSelector.args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (query.exclude.isNotEmpty()) {
|
||||
val pathSelector = pathInterpreterFactory.createSelector(query.exclude.map { it.path })
|
||||
if (pathSelector != null) {
|
||||
selector += " AND NOT (${pathSelector.template})"
|
||||
args.addAll(pathSelector.args)
|
||||
FilterMode.EXCLUDE -> {
|
||||
val pathSelector =
|
||||
pathInterpreterFactory.createSelector(query.filtered.map { it.path })
|
||||
if (pathSelector != null) {
|
||||
selector += " AND NOT (${pathSelector.template})"
|
||||
args.addAll(pathSelector.args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,11 +218,16 @@ private constructor(
|
||||
}
|
||||
|
||||
data class Query(
|
||||
val include: List<Location.Unopened>,
|
||||
val exclude: List<Location.Unopened>,
|
||||
val mode: FilterMode,
|
||||
val filtered: List<Location>,
|
||||
val excludeNonMusic: Boolean
|
||||
)
|
||||
|
||||
enum class FilterMode {
|
||||
INCLUDE,
|
||||
EXCLUDE
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun from(context: Context, query: Query) =
|
||||
MediaStoreFS(
|
||||
|
||||
Reference in New Issue
Block a user