diff --git a/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt b/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt index 89d40bd51..4d1b5c6c9 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package org.oxycblt.auxio.music import android.content.Context @@ -42,26 +42,35 @@ import timber.log.Timber as L interface MusicSettings : Settings { /** 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() diff --git a/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt index e77e308fc..2714d56f0 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt @@ -243,12 +243,13 @@ class LocationsDialog : ViewBindingMaterialDialogFragment 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 - - - - auxio_filtered_locations auxio_separators auxio_auto_sort_names - auxio_saf_mode + auxio_locations_mode auxio_headset_autoplay auxio_replay_gain diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1eb5ee534..1e20963dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,28 +17,19 @@ Retry Music Sources - - - Grant - - Load From File Picker System - Load music from the folders that you select. Slower, but more reliable. Requires the vanilla file manager app to be installed. - Load music that the Android OS automatically detects. Faster, but less reliable. Manufacturers might break this. Storage Access Recommended - Granting external storage permissions can fix issues on some devices. Storage Access Required - Grant external storage permissions to enable this option. Folders to Load Folders to Ignore Filtered Folders Filter Mode Include Exclude - Audio files outside of the selected folders will be ignored. - Audio files in the selected folders will be ignored. + Music outside of the selected folders will be ignored. + Music inside the selected folders will be ignored. Exclude Non-Music Load Hidden Folders Extra Settings @@ -241,6 +232,10 @@ Your artists will show up here. Your genres will show up here. Your playlists will show up here. + Load music from the folders that you select. Slower, but more reliable. Requires the vanilla file manager app to be installed. + Load music that the Android OS automatically detects. Faster, but less reliable. Manufacturers might break this. + Granting external storage permissions can fix issues on some devices. + Grant external storage permissions to enable this option.