music: more location dialog fixes

This commit is contained in:
Alexander Capehart
2025-07-04 16:28:37 -06:00
parent e8e6c2ee4d
commit a812b070c0
5 changed files with 71 additions and 50 deletions
@@ -15,7 +15,7 @@
* 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
import android.content.Context
@@ -42,26 +42,35 @@ import timber.log.Timber as L
interface MusicSettings : Settings<MusicSettings.Listener> {
/** The current library revision. */
var revision: UUID?
/** The mode for loading music locations (SAF or System database). */
var locationMode: LocationMode
/** The currently configured SAF query (if any) * */
var safQuery: SAF.Query
/** The currently configured MediaStore query (if any) * */
var mediaStoreQuery: MediaStoreFS.Query
/** Whether to be actively watching for changes in the music library. */
val shouldBeObserving: Boolean
/** A [String] of characters representing the desired characters to denote multi-value tags. */
var separators: String
/** Whether to enable more advanced sorting by articles and numbers. */
val intelligentSorting: Boolean
/** Whether to use the file-system cache for improved loading times. */
val useFileTreeCache: Boolean
interface Listener {
/** Called when the current music locations changed. */
fun onMusicLocationsChanged() {}
/** Called when a setting controlling how music is loaded has changed. */
fun onIndexingSettingChanged() {}
/** Called when the [shouldBeObserving] configuration has changed. */
fun onObservingChanged() {}
}
@@ -106,12 +115,13 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() {
val mode =
sharedPreferences.getInt(
getString(R.string.set_key_saf_mode), IntegerTable.LOCATION_MODE_SAF)
getString(R.string.set_key_locations_mode), IntegerTable.LOCATION_MODE_SAF
)
return LocationMode.fromInt(mode) ?: LocationMode.SAF
}
set(value) {
sharedPreferences.edit {
putInt(getString(R.string.set_key_saf_mode), value.intCode)
putInt(getString(R.string.set_key_locations_mode), value.intCode)
apply()
}
}
@@ -120,25 +130,29 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() {
val locations =
unlikelyToBeNull(
sharedPreferences
.getString(getString(R.string.set_key_music_locations), "")
.also { L.d("$it") })
sharedPreferences
.getString(getString(R.string.set_key_music_locations), "")
.also { L.d("$it") })
.toOpenedLocations()
val excludedLocations =
unlikelyToBeNull(
sharedPreferences.getString(
getString(R.string.set_key_excluded_locations), ""))
sharedPreferences.getString(
getString(R.string.set_key_excluded_locations), ""
)
)
.toUnopenedLocations()
val withHidden =
sharedPreferences.getBoolean(getString(R.string.set_key_with_hidden), false)
return SAF.Query(
source = locations, exclude = excludedLocations, withHidden = withHidden)
source = locations, exclude = excludedLocations, withHidden = withHidden
)
}
set(value) {
sharedPreferences.edit {
putString(getString(R.string.set_key_music_locations), value.source.stringify())
putString(getString(R.string.set_key_excluded_locations), value.exclude.stringify())
putBoolean(getString(R.string.set_key_with_hidden), value.withHidden)
apply()
}
}
@@ -146,14 +160,18 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() {
val filterMode =
sharedPreferences.getInt(
getString(R.string.set_key_filter_mode), IntegerTable.FILTER_MODE_EXCLUDE)
getString(R.string.set_key_filter_mode), IntegerTable.FILTER_MODE_EXCLUDE
)
val filteredLocations =
unlikelyToBeNull(
sharedPreferences.getString(
getString(R.string.set_key_filtered_locations), ""))
sharedPreferences.getString(
getString(R.string.set_key_filtered_locations), ""
)
)
.toUnopenedLocations()
val excludeNonMusic =
sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
L.d("${excludeNonMusic}")
return MediaStoreFS.Query(
mode =
when (filterMode) {
@@ -162,7 +180,8 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
else -> MediaStoreFS.FilterMode.EXCLUDE
},
filtered = filteredLocations,
excludeNonMusic = excludeNonMusic)
excludeNonMusic = excludeNonMusic
)
}
set(value) {
sharedPreferences.edit {
@@ -173,8 +192,10 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
}
putInt(getString(R.string.set_key_filter_mode), filterMode)
putString(
getString(R.string.set_key_filtered_locations), value.filtered.stringify())
getString(R.string.set_key_filtered_locations), value.filtered.stringify()
)
putBoolean(getString(R.string.set_key_exclude_non_music), value.excludeNonMusic)
apply()
}
}
@@ -182,18 +203,24 @@ 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_excluded_locations) -> {
getString(R.string.set_key_locations_mode),
getString(R.string.set_key_music_locations) -> {
L.d("Dispatching music locations change")
listener.onMusicLocationsChanged()
}
getString(R.string.set_key_excluded_locations),
getString(R.string.set_key_with_hidden),
getString(R.string.set_key_filter_mode),
getString(R.string.set_key_filtered_locations),
getString(R.string.set_key_exclude_non_music),
getString(R.string.set_key_separators),
getString(R.string.set_key_auto_sort_names),
getString(R.string.set_key_with_hidden),
getString(R.string.set_key_exclude_non_music) -> {
-> {
L.d("Dispatching indexing setting change for $key")
listener.onIndexingSettingChanged()
}
getString(R.string.set_key_observing) -> {
L.d("Dispatching observing setting change")
listener.onObservingChanged()
@@ -243,12 +243,13 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
musicSettings.safQuery.let { query ->
includeLocationAdapter.addAll(query.source)
excludeLocationAdapter.addAll(query.exclude)
binding.configSwitchFilePicker.isChecked = query.withHidden
binding.locationsWithHidden.isChecked = query.withHidden
}
// Load MediaStore data
musicSettings.mediaStoreQuery.let { query ->
filterLocationAdapter.addAll(query.filtered)
binding.configSwitchSystem.isChecked = query.excludeNonMusic
L.d("${query.excludeNonMusic}")
binding.locationsExcludeNonMusic.isChecked = query.excludeNonMusic
isIncludeMode = query.mode == MediaStoreFS.FilterMode.INCLUDE
binding.locationsExcludeModeGroup.check(
@@ -310,20 +311,20 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
with(binding) {
if (isFilePickerMode) {
// File Picker mode
locationsModeDesc.setText(R.string.desc_file_picker)
locationsModeDesc.setText(R.string.lng_file_picker)
// Update permission section
locationsPermsDesc.setText(R.string.lbl_grant_storage_anyway)
locationsPermsSubtitle.setText(R.string.desc_grant_storage_anyway)
locationsPermsSubtitle.setText(R.string.lng_grant_storage_anyway)
// File Picker mode - no need to update switch text as it's set in XML
} else {
// System Database mode
locationsModeDesc.setText(R.string.desc_system_database)
locationsModeDesc.setText(R.string.lng_system_database)
// Update permission section
locationsPermsDesc.setText(R.string.lbl_grant_storage)
locationsPermsSubtitle.setText(R.string.desc_grant_storage_required)
locationsPermsSubtitle.setText(R.string.lng_grant_storage_required)
// Update exclude mode description based on selection
updateExcludeModeUI(binding)
@@ -376,8 +377,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
locationsFilterAdd.isEnabled = isEnabled
locationsFilterRecycler.isEnabled = isEnabled
configSwitchFilePicker.isEnabled = isEnabled
configSwitchSystem.isEnabled = isEnabled
locationsWithHidden.isEnabled = isEnabled
locationsExcludeNonMusic.isEnabled = isEnabled
}
}
@@ -456,8 +457,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
// Config section
configDivider.isVisible = isExtrasExpanded
configSwitchFilePicker.isVisible = isExtrasExpanded
configSwitchSystem.isVisible = false
locationsWithHidden.isVisible = isExtrasExpanded
locationsExcludeNonMusic.isVisible = false
} else {
// System Database mode - show filter mode when expanded
// Hide include section
@@ -483,8 +484,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
// Config section
configDivider.isVisible = isExtrasExpanded
configSwitchFilePicker.isVisible = false
configSwitchSystem.isVisible = isExtrasExpanded
locationsWithHidden.isVisible = false
locationsExcludeNonMusic.isVisible = isExtrasExpanded
}
}
}
@@ -502,7 +503,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
SAF.Query(
source = includeLocationAdapter.locations,
exclude = excludeLocationAdapter.locations,
withHidden = binding.configSwitchFilePicker.isChecked)
withHidden = binding.locationsWithHidden.isChecked)
musicSettings.safQuery = safQuery
} else {
// System database mode - create and save MediaStore query
@@ -517,7 +518,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
MediaStoreFS.Query(
mode = filterMode,
filtered = filterLocationAdapter.locations,
excludeNonMusic = !binding.configSwitchSystem.isChecked)
excludeNonMusic = binding.locationsExcludeNonMusic.isChecked)
musicSettings.mediaStoreQuery = mediaStoreQuery
}
}