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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.oxycblt.auxio.music package org.oxycblt.auxio.music
import android.content.Context import android.content.Context
@@ -42,26 +42,35 @@ import timber.log.Timber as L
interface MusicSettings : Settings<MusicSettings.Listener> { interface MusicSettings : Settings<MusicSettings.Listener> {
/** The current library revision. */ /** The current library revision. */
var revision: UUID? var revision: UUID?
/** The mode for loading music locations (SAF or System database). */ /** The mode for loading music locations (SAF or System database). */
var locationMode: LocationMode var locationMode: LocationMode
/** The currently configured SAF query (if any) * */ /** The currently configured SAF query (if any) * */
var safQuery: SAF.Query var safQuery: SAF.Query
/** The currently configured MediaStore query (if any) * */ /** The currently configured MediaStore query (if any) * */
var mediaStoreQuery: MediaStoreFS.Query var mediaStoreQuery: MediaStoreFS.Query
/** Whether to be actively watching for changes in the music library. */ /** Whether to be actively watching for changes in the music library. */
val shouldBeObserving: Boolean val shouldBeObserving: Boolean
/** A [String] of characters representing the desired characters to denote multi-value tags. */ /** A [String] of characters representing the desired characters to denote multi-value tags. */
var separators: String var separators: String
/** Whether to enable more advanced sorting by articles and numbers. */ /** Whether to enable more advanced sorting by articles and numbers. */
val intelligentSorting: Boolean val intelligentSorting: Boolean
/** Whether to use the file-system cache for improved loading times. */ /** Whether to use the file-system cache for improved loading times. */
val useFileTreeCache: Boolean val useFileTreeCache: Boolean
interface Listener { interface Listener {
/** Called when the current music locations changed. */ /** Called when the current music locations changed. */
fun onMusicLocationsChanged() {} fun onMusicLocationsChanged() {}
/** Called when a setting controlling how music is loaded has changed. */ /** Called when a setting controlling how music is loaded has changed. */
fun onIndexingSettingChanged() {} fun onIndexingSettingChanged() {}
/** Called when the [shouldBeObserving] configuration has changed. */ /** Called when the [shouldBeObserving] configuration has changed. */
fun onObservingChanged() {} fun onObservingChanged() {}
} }
@@ -106,12 +115,13 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() { get() {
val mode = val mode =
sharedPreferences.getInt( 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 return LocationMode.fromInt(mode) ?: LocationMode.SAF
} }
set(value) { set(value) {
sharedPreferences.edit { sharedPreferences.edit {
putInt(getString(R.string.set_key_saf_mode), value.intCode) putInt(getString(R.string.set_key_locations_mode), value.intCode)
apply() apply()
} }
} }
@@ -120,25 +130,29 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() { get() {
val locations = val locations =
unlikelyToBeNull( unlikelyToBeNull(
sharedPreferences sharedPreferences
.getString(getString(R.string.set_key_music_locations), "") .getString(getString(R.string.set_key_music_locations), "")
.also { L.d("$it") }) .also { L.d("$it") })
.toOpenedLocations() .toOpenedLocations()
val excludedLocations = val excludedLocations =
unlikelyToBeNull( unlikelyToBeNull(
sharedPreferences.getString( sharedPreferences.getString(
getString(R.string.set_key_excluded_locations), "")) getString(R.string.set_key_excluded_locations), ""
)
)
.toUnopenedLocations() .toUnopenedLocations()
val withHidden = val withHidden =
sharedPreferences.getBoolean(getString(R.string.set_key_with_hidden), false) sharedPreferences.getBoolean(getString(R.string.set_key_with_hidden), false)
return SAF.Query( return SAF.Query(
source = locations, exclude = excludedLocations, withHidden = withHidden) source = locations, exclude = excludedLocations, withHidden = withHidden
)
} }
set(value) { set(value) {
sharedPreferences.edit { sharedPreferences.edit {
putString(getString(R.string.set_key_music_locations), value.source.stringify()) putString(getString(R.string.set_key_music_locations), value.source.stringify())
putString(getString(R.string.set_key_excluded_locations), value.exclude.stringify()) putString(getString(R.string.set_key_excluded_locations), value.exclude.stringify())
putBoolean(getString(R.string.set_key_with_hidden), value.withHidden) putBoolean(getString(R.string.set_key_with_hidden), value.withHidden)
apply()
} }
} }
@@ -146,14 +160,18 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
get() { get() {
val filterMode = val filterMode =
sharedPreferences.getInt( 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 = val filteredLocations =
unlikelyToBeNull( unlikelyToBeNull(
sharedPreferences.getString( sharedPreferences.getString(
getString(R.string.set_key_filtered_locations), "")) getString(R.string.set_key_filtered_locations), ""
)
)
.toUnopenedLocations() .toUnopenedLocations()
val excludeNonMusic = val excludeNonMusic =
sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true) sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
L.d("${excludeNonMusic}")
return MediaStoreFS.Query( return MediaStoreFS.Query(
mode = mode =
when (filterMode) { when (filterMode) {
@@ -162,7 +180,8 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
else -> MediaStoreFS.FilterMode.EXCLUDE else -> MediaStoreFS.FilterMode.EXCLUDE
}, },
filtered = filteredLocations, filtered = filteredLocations,
excludeNonMusic = excludeNonMusic) excludeNonMusic = excludeNonMusic
)
} }
set(value) { set(value) {
sharedPreferences.edit { sharedPreferences.edit {
@@ -173,8 +192,10 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
} }
putInt(getString(R.string.set_key_filter_mode), filterMode) putInt(getString(R.string.set_key_filter_mode), filterMode)
putString( 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) 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" // 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_locations_mode),
getString(R.string.set_key_excluded_locations) -> { getString(R.string.set_key_music_locations) -> {
L.d("Dispatching music locations change") L.d("Dispatching music locations change")
listener.onMusicLocationsChanged() 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_separators),
getString(R.string.set_key_auto_sort_names), 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") L.d("Dispatching indexing setting change for $key")
listener.onIndexingSettingChanged() listener.onIndexingSettingChanged()
} }
getString(R.string.set_key_observing) -> { getString(R.string.set_key_observing) -> {
L.d("Dispatching observing setting change") L.d("Dispatching observing setting change")
listener.onObservingChanged() listener.onObservingChanged()
@@ -243,12 +243,13 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
musicSettings.safQuery.let { query -> musicSettings.safQuery.let { query ->
includeLocationAdapter.addAll(query.source) includeLocationAdapter.addAll(query.source)
excludeLocationAdapter.addAll(query.exclude) excludeLocationAdapter.addAll(query.exclude)
binding.configSwitchFilePicker.isChecked = query.withHidden binding.locationsWithHidden.isChecked = query.withHidden
} }
// Load MediaStore data // Load MediaStore data
musicSettings.mediaStoreQuery.let { query -> musicSettings.mediaStoreQuery.let { query ->
filterLocationAdapter.addAll(query.filtered) filterLocationAdapter.addAll(query.filtered)
binding.configSwitchSystem.isChecked = query.excludeNonMusic L.d("${query.excludeNonMusic}")
binding.locationsExcludeNonMusic.isChecked = query.excludeNonMusic
isIncludeMode = query.mode == MediaStoreFS.FilterMode.INCLUDE isIncludeMode = query.mode == MediaStoreFS.FilterMode.INCLUDE
binding.locationsExcludeModeGroup.check( binding.locationsExcludeModeGroup.check(
@@ -310,20 +311,20 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
with(binding) { with(binding) {
if (isFilePickerMode) { if (isFilePickerMode) {
// File Picker mode // File Picker mode
locationsModeDesc.setText(R.string.desc_file_picker) locationsModeDesc.setText(R.string.lng_file_picker)
// Update permission section // Update permission section
locationsPermsDesc.setText(R.string.lbl_grant_storage_anyway) 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 // File Picker mode - no need to update switch text as it's set in XML
} else { } else {
// System Database mode // System Database mode
locationsModeDesc.setText(R.string.desc_system_database) locationsModeDesc.setText(R.string.lng_system_database)
// Update permission section // Update permission section
locationsPermsDesc.setText(R.string.lbl_grant_storage) 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 // Update exclude mode description based on selection
updateExcludeModeUI(binding) updateExcludeModeUI(binding)
@@ -376,8 +377,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
locationsFilterAdd.isEnabled = isEnabled locationsFilterAdd.isEnabled = isEnabled
locationsFilterRecycler.isEnabled = isEnabled locationsFilterRecycler.isEnabled = isEnabled
configSwitchFilePicker.isEnabled = isEnabled locationsWithHidden.isEnabled = isEnabled
configSwitchSystem.isEnabled = isEnabled locationsExcludeNonMusic.isEnabled = isEnabled
} }
} }
@@ -456,8 +457,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
// Config section // Config section
configDivider.isVisible = isExtrasExpanded configDivider.isVisible = isExtrasExpanded
configSwitchFilePicker.isVisible = isExtrasExpanded locationsWithHidden.isVisible = isExtrasExpanded
configSwitchSystem.isVisible = false locationsExcludeNonMusic.isVisible = false
} else { } else {
// System Database mode - show filter mode when expanded // System Database mode - show filter mode when expanded
// Hide include section // Hide include section
@@ -483,8 +484,8 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
// Config section // Config section
configDivider.isVisible = isExtrasExpanded configDivider.isVisible = isExtrasExpanded
configSwitchFilePicker.isVisible = false locationsWithHidden.isVisible = false
configSwitchSystem.isVisible = isExtrasExpanded locationsExcludeNonMusic.isVisible = isExtrasExpanded
} }
} }
} }
@@ -502,7 +503,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
SAF.Query( SAF.Query(
source = includeLocationAdapter.locations, source = includeLocationAdapter.locations,
exclude = excludeLocationAdapter.locations, exclude = excludeLocationAdapter.locations,
withHidden = binding.configSwitchFilePicker.isChecked) withHidden = binding.locationsWithHidden.isChecked)
musicSettings.safQuery = safQuery musicSettings.safQuery = safQuery
} else { } else {
// System database mode - create and save MediaStore query // System database mode - create and save MediaStore query
@@ -517,7 +518,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
MediaStoreFS.Query( MediaStoreFS.Query(
mode = filterMode, mode = filterMode,
filtered = filterLocationAdapter.locations, filtered = filterLocationAdapter.locations,
excludeNonMusic = !binding.configSwitchSystem.isChecked) excludeNonMusic = binding.locationsExcludeNonMusic.isChecked)
musicSettings.mediaStoreQuery = mediaStoreQuery musicSettings.mediaStoreQuery = mediaStoreQuery
} }
} }
@@ -353,10 +353,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/locations_exclude_recycler" /> app:layout_constraintTop_toBottomOf="@+id/locations_exclude_recycler" />
<!-- "Load Hidden Folders" for File Picker mode -->
<com.google.android.material.materialswitch.MaterialSwitch <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" style="@style/Widget.Auxio.RecyclerView.Linear"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
@@ -366,6 +364,7 @@
android:layout_weight="1" android:layout_weight="1"
android:clipToPadding="false" android:clipToPadding="false"
android:overScrollMode="never" android:overScrollMode="never"
android:textAppearance="@style/TextAppearance.Auxio.BodyLarge"
android:text="@string/lbl_load_hidden_folders" android:text="@string/lbl_load_hidden_folders"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@@ -373,10 +372,8 @@
tools:itemCount="1" tools:itemCount="1"
tools:listitem="@layout/item_music_location" /> tools:listitem="@layout/item_music_location" />
<!-- "Exclude non-music" for System Database mode -->
<com.google.android.material.materialswitch.MaterialSwitch <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" style="@style/Widget.Auxio.RecyclerView.Linear"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
@@ -387,6 +384,7 @@
android:clipToPadding="false" android:clipToPadding="false"
android:overScrollMode="never" android:overScrollMode="never"
android:text="@string/lbl_exclude_non_music" android:text="@string/lbl_exclude_non_music"
android:textAppearance="@style/TextAppearance.Auxio.BodyLarge"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/config_divider" 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_filtered_locations" translatable="false">auxio_filtered_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>
<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_headset_autoplay" translatable="false">auxio_headset_autoplay</string>
<string name="set_key_replay_gain" translatable="false">auxio_replay_gain</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 --> <!-- As in to retry loading music -->
<string name="lbl_retry">Retry</string> <string name="lbl_retry">Retry</string>
<string name="lbl_music_sources">Music Sources</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_load_from">Load From</string>
<string name="lbl_file_picker">File Picker</string> <string name="lbl_file_picker">File Picker</string>
<string name="lbl_system_database">System</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="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="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_load">Folders to Load</string>
<string name="lbl_folders_to_ignore">Folders to Ignore</string> <string name="lbl_folders_to_ignore">Folders to Ignore</string>
<string name="lbl_filtered_folders">Filtered Folders</string> <string name="lbl_filtered_folders">Filtered Folders</string>
<string name="lbl_filter_mode">Filter Mode</string> <string name="lbl_filter_mode">Filter Mode</string>
<string name="lbl_include">Include</string> <string name="lbl_include">Include</string>
<string name="lbl_exclude">Exclude</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_include_folders">Music 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_exclude_folders">Music inside the selected folders will be ignored.</string>
<string name="lbl_exclude_non_music">Exclude Non-Music</string> <string name="lbl_exclude_non_music">Exclude Non-Music</string>
<string name="lbl_load_hidden_folders">Load Hidden Folders</string> <string name="lbl_load_hidden_folders">Load Hidden Folders</string>
<string name="lbl_extra_settings">Extra Settings</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_artists">Your artists will show up here.</string>
<string name="lng_empty_genres">Your genres 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_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 --> <!-- Settings namespace | Settings-related labels -->
<eat-comment /> <eat-comment />