music: implement excluded dirs settings fields
Authored by Claude Code.
This commit is contained in:
@@ -388,6 +388,7 @@ constructor(
|
|||||||
Naming.simple()
|
Naming.simple()
|
||||||
}
|
}
|
||||||
val locations = musicSettings.musicLocations
|
val locations = musicSettings.musicLocations
|
||||||
|
val excludedLocations = musicSettings.excludedLocations
|
||||||
val withHidden = musicSettings.withHidden
|
val withHidden = musicSettings.withHidden
|
||||||
|
|
||||||
val currentRevision = musicSettings.revision
|
val currentRevision = musicSettings.revision
|
||||||
@@ -397,7 +398,7 @@ constructor(
|
|||||||
val fileTreeCache =
|
val fileTreeCache =
|
||||||
if (withCache) FileTreeCache.from(context)
|
if (withCache) FileTreeCache.from(context)
|
||||||
else WriteOnlyFileTreeCache(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 storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
|
||||||
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
||||||
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
|
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
|||||||
var revision: UUID?
|
var revision: UUID?
|
||||||
/** The locations of music to load. */
|
/** The locations of music to load. */
|
||||||
var musicLocations: List<OpenedLocation>
|
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. */
|
/** Whether to exclude non-music audio files from the music library. */
|
||||||
val excludeNonMusic: Boolean
|
val excludeNonMusic: Boolean
|
||||||
/** Whether to ignore hidden files and directories during music loading. */
|
/** 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
|
override val excludeNonMusic: Boolean
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
|
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"
|
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
|
||||||
// (just need to manipulate data)
|
// (just need to manipulate data)
|
||||||
when (key) {
|
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")
|
L.d("Dispatching music locations change")
|
||||||
listener.onMusicLocationsChanged()
|
listener.onMusicLocationsChanged()
|
||||||
}
|
}
|
||||||
@@ -144,6 +162,12 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
private fun String.toOpenedLocations(): List<OpenedLocation> =
|
private fun String.toOpenedLocations(): List<OpenedLocation> =
|
||||||
splitEscaped { it == ';' }.mapNotNull { Location.from(context, it.toUri())?.open(context) }
|
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> {
|
private inline fun String.splitEscaped(selector: (Char) -> Boolean): List<String> {
|
||||||
val split = mutableListOf<String>()
|
val split = mutableListOf<String>()
|
||||||
var currentString = ""
|
var currentString = ""
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<string name="set_key_exclude_non_music" translatable="false">auxio_exclude_non_music</string>
|
<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_with_hidden" translatable="false">auxio_with_hidden</string>
|
||||||
<string name="set_key_music_locations" translatable="false">auxio_music_locations2</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_separators" translatable="false">auxio_separators</string>
|
||||||
<string name="set_key_auto_sort_names" translatable="false">auxio_auto_sort_names</string>
|
<string name="set_key_auto_sort_names" translatable="false">auxio_auto_sort_names</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user