music: implement excluded dirs settings fields
Authored by Claude Code.
This commit is contained in:
@@ -386,14 +386,15 @@ constructor(
|
||||
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 query = Query(source = locations, exclude = excludedLocations)
|
||||
val storage = Storage(cache, covers, storedPlaylists)
|
||||
val query = Query(source = locations, exclude = emptyList())
|
||||
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
||||
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
|
||||
// Music loading completed, update the revision right now so we re-use this work
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user