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
}
}
@@ -353,10 +353,8 @@
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/locations_exclude_recycler" />
<!-- "Load Hidden Folders" for File Picker mode -->
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/config_switch_file_picker"
android:id="@+id/locations_with_hidden"
style="@style/Widget.Auxio.RecyclerView.Linear"
android:layout_width="match_parent"
android:layout_height="0dp"
@@ -366,6 +364,7 @@
android:layout_weight="1"
android:clipToPadding="false"
android:overScrollMode="never"
android:textAppearance="@style/TextAppearance.Auxio.BodyLarge"
android:text="@string/lbl_load_hidden_folders"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -373,10 +372,8 @@
tools:itemCount="1"
tools:listitem="@layout/item_music_location" />
<!-- "Exclude non-music" for System Database mode -->
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/config_switch_system"
android:id="@+id/locations_exclude_non_music"
style="@style/Widget.Auxio.RecyclerView.Linear"
android:layout_width="match_parent"
android:layout_height="0dp"
@@ -387,6 +384,7 @@
android:clipToPadding="false"
android:overScrollMode="never"
android:text="@string/lbl_exclude_non_music"
android:textAppearance="@style/TextAppearance.Auxio.BodyLarge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/config_divider"
+1 -1
View File
@@ -26,7 +26,7 @@
<string name="set_key_filtered_locations" translatable="false">auxio_filtered_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>
<string name="set_key_saf_mode" translatable="false">auxio_saf_mode</string>
<string name="set_key_locations_mode" translatable="false">auxio_locations_mode</string>
<string name="set_key_headset_autoplay" translatable="false">auxio_headset_autoplay</string>
<string name="set_key_replay_gain" translatable="false">auxio_replay_gain</string>
+6 -11
View File
@@ -17,28 +17,19 @@
<!-- As in to retry loading music -->
<string name="lbl_retry">Retry</string>
<string name="lbl_music_sources">Music Sources</string>
<!-- As in to show additional information about a music loading error -->
<!-- As in grant permission -->
<string name="lbl_grant">Grant</string>
<!-- Music location dialog strings -->
<string name="lbl_load_from">Load From</string>
<string name="lbl_file_picker">File Picker</string>
<string name="lbl_system_database">System</string>
<string name="desc_file_picker">Load music from the folders that you select. Slower, but more reliable. Requires the vanilla file manager app to be installed.</string>
<string name="desc_system_database">Load music that the Android OS automatically detects. Faster, but less reliable. Manufacturers might break this.</string>
<string name="lbl_grant_storage_anyway">Storage Access Recommended</string>
<string name="desc_grant_storage_anyway">Granting external storage permissions can fix issues on some devices.</string>
<string name="lbl_grant_storage">Storage Access Required</string>
<string name="desc_grant_storage_required">Grant external storage permissions to enable this option.</string>
<string name="lbl_folders_to_load">Folders to Load</string>
<string name="lbl_folders_to_ignore">Folders to Ignore</string>
<string name="lbl_filtered_folders">Filtered Folders</string>
<string name="lbl_filter_mode">Filter Mode</string>
<string name="lbl_include">Include</string>
<string name="lbl_exclude">Exclude</string>
<string name="desc_include_folders">Audio files outside of the selected folders will be ignored.</string>
<string name="desc_exclude_folders">Audio files in the selected folders will be ignored.</string>
<string name="desc_include_folders">Music outside of the selected folders will be ignored.</string>
<string name="desc_exclude_folders">Music inside the selected folders will be ignored.</string>
<string name="lbl_exclude_non_music">Exclude Non-Music</string>
<string name="lbl_load_hidden_folders">Load Hidden Folders</string>
<string name="lbl_extra_settings">Extra Settings</string>
@@ -241,6 +232,10 @@
<string name="lng_empty_artists">Your artists will show up here.</string>
<string name="lng_empty_genres">Your genres will show up here.</string>
<string name="lng_empty_playlists">Your playlists will show up here.</string>
<string name="lng_file_picker">Load music from the folders that you select. Slower, but more reliable. Requires the vanilla file manager app to be installed.</string>
<string name="lng_system_database">Load music that the Android OS automatically detects. Faster, but less reliable. Manufacturers might break this.</string>
<string name="lng_grant_storage_anyway">Granting external storage permissions can fix issues on some devices.</string>
<string name="lng_grant_storage_required">Grant external storage permissions to enable this option.</string>
<!-- Settings namespace | Settings-related labels -->
<eat-comment />