music: implement excluded dirs settings fields

Authored by Claude Code.
This commit is contained in:
Alexander Capehart
2025-05-31 14:44:37 -06:00
parent 0612772794
commit a05460d54c
3 changed files with 28 additions and 2 deletions
@@ -388,6 +388,7 @@ constructor(
Naming.simple()
}
val locations = musicSettings.musicLocations
val excludedLocations = musicSettings.excludedLocations
val withHidden = musicSettings.withHidden
val currentRevision = musicSettings.revision
@@ -397,7 +398,7 @@ constructor(
val fileTreeCache =
if (withCache) FileTreeCache.from(context)
else WriteOnlyFileTreeCache(FileTreeCache.from(context))
val query = Query(source = locations, exclude = emptyList())
val query = Query(source = locations, exclude = excludedLocations)
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
val interpretation = Interpretation(nameFactory, separators, withHidden)
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
@@ -40,6 +40,8 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
var revision: UUID?
/** The locations of music to load. */
var musicLocations: List<OpenedLocation>
/** The locations to exclude from music loading. */
var excludedLocations: List<Location>
/** Whether to exclude non-music audio files from the music library. */
val excludeNonMusic: Boolean
/** Whether to ignore hidden files and directories during music loading. */
@@ -93,6 +95,21 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
}
}
override var excludedLocations: List<Location>
get() {
val locations =
sharedPreferences.getString(getString(R.string.set_key_excluded_locations), null)
?: return emptyList()
return locations.toLocations()
}
set(value) {
sharedPreferences.edit {
putString(getString(R.string.set_key_excluded_locations), value.stringifyLocations())
commit()
listener?.onMusicLocationsChanged()
}
}
override val excludeNonMusic: Boolean
get() = sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
@@ -120,7 +137,8 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
// (just need to manipulate data)
when (key) {
getString(R.string.set_key_music_locations) -> {
getString(R.string.set_key_music_locations),
getString(R.string.set_key_excluded_locations) -> {
L.d("Dispatching music locations change")
listener.onMusicLocationsChanged()
}
@@ -144,6 +162,12 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
private fun String.toOpenedLocations(): List<OpenedLocation> =
splitEscaped { it == ';' }.mapNotNull { Location.from(context, it.toUri())?.open(context) }
private fun List<Location>.stringifyLocations(): String =
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
private fun String.toLocations(): List<Location> =
splitEscaped { it == ';' }.mapNotNull { Location.from(context, it.toUri()) }
private inline fun String.splitEscaped(selector: (Char) -> Boolean): List<String> {
val split = mutableListOf<String>()
var currentString = ""
+1
View File
@@ -19,6 +19,7 @@
<string name="set_key_exclude_non_music" translatable="false">auxio_exclude_non_music</string>
<string name="set_key_with_hidden" translatable="false">auxio_with_hidden</string>
<string name="set_key_music_locations" translatable="false">auxio_music_locations2</string>
<string name="set_key_excluded_locations" translatable="false">auxio_excluded_locations</string>
<string name="set_key_separators" translatable="false">auxio_separators</string>
<string name="set_key_auto_sort_names" translatable="false">auxio_auto_sort_names</string>