music: improve dialog/fix bugs
This commit is contained in:
@@ -145,4 +145,12 @@ object IntegerTable {
|
|||||||
const val COVER_MODE_SAVE_SPACE = 0xA125
|
const val COVER_MODE_SAVE_SPACE = 0xA125
|
||||||
/** CoverMode.AsIs */
|
/** CoverMode.AsIs */
|
||||||
const val COVER_MODE_AS_IS = 0xA126
|
const val COVER_MODE_AS_IS = 0xA126
|
||||||
|
/** LocationMode.SAF */
|
||||||
|
const val LOCATION_MODE_SAF = 0xA127
|
||||||
|
/** LocationMode.MediaStore */
|
||||||
|
const val LOCATION_MODE_MEDIA_STORE = 0xA128
|
||||||
|
/** LocationMode.FileSystem */
|
||||||
|
const val FILTER_MODE_INCLUDE = 0xA129
|
||||||
|
/** LocationMode.FileSystem */
|
||||||
|
const val FILTER_MODE_EXCLUDE = 0xA12A
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import kotlinx.coroutines.withContext
|
|||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.oxycblt.auxio.image.covers.SettingCovers
|
import org.oxycblt.auxio.image.covers.SettingCovers
|
||||||
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
|
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
|
||||||
|
import org.oxycblt.auxio.music.locations.LocationMode
|
||||||
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
|
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
|
||||||
import org.oxycblt.musikr.Config
|
import org.oxycblt.musikr.Config
|
||||||
import org.oxycblt.musikr.IndexingProgress
|
import org.oxycblt.musikr.IndexingProgress
|
||||||
@@ -394,9 +395,9 @@ constructor(
|
|||||||
val covers = settingCovers.mutate(context, newRevision)
|
val covers = settingCovers.mutate(context, newRevision)
|
||||||
val fs =
|
val fs =
|
||||||
when (musicSettings.locationMode) {
|
when (musicSettings.locationMode) {
|
||||||
MusicLocationMode.SAF -> SAF.from(context, musicSettings.safQuery ?: return)
|
LocationMode.SAF -> SAF.from(context, musicSettings.safQuery)
|
||||||
MusicLocationMode.SYSTEM ->
|
LocationMode.MEDIA_STORE ->
|
||||||
MediaStoreFS.from(context, musicSettings.mediaStoreQuery ?: return)
|
MediaStoreFS.from(context, musicSettings.mediaStoreQuery)
|
||||||
}
|
}
|
||||||
val storage = Storage(cache, covers, storedPlaylists)
|
val storage = Storage(cache, covers, storedPlaylists)
|
||||||
val interpretation = Interpretation(nameFactory, separators)
|
val interpretation = Interpretation(nameFactory, separators)
|
||||||
|
|||||||
@@ -24,21 +24,16 @@ import androidx.core.net.toUri
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import org.oxycblt.auxio.IntegerTable
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
|
import org.oxycblt.auxio.music.locations.LocationMode
|
||||||
import org.oxycblt.auxio.settings.Settings
|
import org.oxycblt.auxio.settings.Settings
|
||||||
|
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||||
import org.oxycblt.musikr.fs.Location
|
import org.oxycblt.musikr.fs.Location
|
||||||
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||||
import org.oxycblt.musikr.fs.saf.SAF
|
import org.oxycblt.musikr.fs.saf.SAF
|
||||||
import timber.log.Timber as L
|
import timber.log.Timber as L
|
||||||
|
|
||||||
/** Represents the mode for loading music locations. */
|
|
||||||
enum class MusicLocationMode {
|
|
||||||
/** Use Storage Access Framework (file picker) to select specific folders */
|
|
||||||
SAF,
|
|
||||||
/** Use system MediaStore database to load all music */
|
|
||||||
SYSTEM
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User configuration specific to music system.
|
* User configuration specific to music system.
|
||||||
*
|
*
|
||||||
@@ -47,12 +42,12 @@ enum class MusicLocationMode {
|
|||||||
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). */
|
||||||
|
var locationMode: LocationMode
|
||||||
/** The currently configured SAF query (if any) * */
|
/** The currently configured SAF query (if any) * */
|
||||||
val safQuery: SAF.Query?
|
var safQuery: SAF.Query
|
||||||
/** The currently configured MediaStore query (if any) * */
|
/** The currently configured MediaStore query (if any) * */
|
||||||
val mediaStoreQuery: MediaStoreFS.Query?
|
var mediaStoreQuery: MediaStoreFS.Query
|
||||||
/** Whether to ignore hidden files and directories during music loading. */
|
|
||||||
val withHidden: Boolean
|
|
||||||
/** 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. */
|
||||||
@@ -61,14 +56,6 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
|||||||
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
|
||||||
/** The mode for loading music locations (SAF or System database). */
|
|
||||||
var locationMode: MusicLocationMode
|
|
||||||
/** The list of music locations to include when using SAF mode. */
|
|
||||||
var musicLocations: List<Location.Opened>
|
|
||||||
/** The list of locations to exclude. */
|
|
||||||
var excludedLocations: List<Location.Unopened>
|
|
||||||
/** Whether to exclude non-music files when using MediaStore. */
|
|
||||||
val excludeNonMusic: Boolean
|
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
/** Called when the current music locations changed. */
|
/** Called when the current music locations changed. */
|
||||||
@@ -95,9 +82,6 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val withHidden: Boolean
|
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_with_hidden), false)
|
|
||||||
|
|
||||||
override val shouldBeObserving: Boolean
|
override val shouldBeObserving: Boolean
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_observing), false)
|
get() = sharedPreferences.getBoolean(getString(R.string.set_key_observing), false)
|
||||||
|
|
||||||
@@ -118,81 +102,82 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
override val useFileTreeCache: Boolean
|
override val useFileTreeCache: Boolean
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_fs_cache), false)
|
get() = sharedPreferences.getBoolean(getString(R.string.set_key_fs_cache), false)
|
||||||
|
|
||||||
override var locationMode: MusicLocationMode
|
override var locationMode: LocationMode
|
||||||
get() {
|
get() {
|
||||||
val ordinal = sharedPreferences.getInt(getString(R.string.set_key_saf_mode), 0)
|
val mode =
|
||||||
return MusicLocationMode.values().getOrNull(ordinal) ?: MusicLocationMode.SAF
|
sharedPreferences.getInt(
|
||||||
|
getString(R.string.set_key_saf_mode), IntegerTable.LOCATION_MODE_SAF)
|
||||||
|
return LocationMode.fromInt(mode) ?: LocationMode.SAF
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
sharedPreferences.edit {
|
sharedPreferences.edit {
|
||||||
putInt(getString(R.string.set_key_saf_mode), value.ordinal)
|
putInt(getString(R.string.set_key_saf_mode), value.intCode)
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val safQuery: SAF.Query?
|
override var safQuery: SAF.Query
|
||||||
get() {
|
get() {
|
||||||
// SAF query is used when in SAF mode and we have music locations configured
|
val locations =
|
||||||
if (locationMode != MusicLocationMode.SAF) return null
|
unlikelyToBeNull(
|
||||||
val locations = musicLocations
|
sharedPreferences
|
||||||
if (locations.isEmpty()) return null
|
.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), ""))
|
||||||
|
.toUnopenedLocations()
|
||||||
|
val withHidden =
|
||||||
|
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) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val mediaStoreQuery: MediaStoreFS.Query?
|
override var mediaStoreQuery: MediaStoreFS.Query
|
||||||
get() {
|
get() {
|
||||||
// MediaStore query is used when in system database mode
|
|
||||||
if (locationMode != MusicLocationMode.SYSTEM) return null
|
|
||||||
|
|
||||||
// Determine filter mode based on whether we have excluded locations
|
|
||||||
val filterMode =
|
val filterMode =
|
||||||
if (excludedLocations.isEmpty()) {
|
sharedPreferences.getInt(
|
||||||
MediaStoreFS.FilterMode.INCLUDE
|
getString(R.string.set_key_filter_mode), IntegerTable.FILTER_MODE_EXCLUDE)
|
||||||
} else {
|
val filteredLocations =
|
||||||
MediaStoreFS.FilterMode.EXCLUDE
|
unlikelyToBeNull(
|
||||||
}
|
sharedPreferences.getString(
|
||||||
|
getString(R.string.set_key_filtered_locations), ""))
|
||||||
|
.toUnopenedLocations()
|
||||||
|
val excludeNonMusic =
|
||||||
|
sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
|
||||||
return MediaStoreFS.Query(
|
return MediaStoreFS.Query(
|
||||||
mode = filterMode, filtered = excludedLocations, excludeNonMusic = excludeNonMusic)
|
mode =
|
||||||
}
|
when (filterMode) {
|
||||||
|
IntegerTable.FILTER_MODE_INCLUDE -> MediaStoreFS.FilterMode.INCLUDE
|
||||||
override var musicLocations: List<Location.Opened>
|
IntegerTable.FILTER_MODE_EXCLUDE -> MediaStoreFS.FilterMode.EXCLUDE
|
||||||
get() {
|
else -> MediaStoreFS.FilterMode.EXCLUDE
|
||||||
val locations =
|
},
|
||||||
sharedPreferences.getString(getString(R.string.set_key_music_locations), null)
|
filtered = filteredLocations,
|
||||||
?: return emptyList()
|
excludeNonMusic = excludeNonMusic)
|
||||||
return locations.toOpenedLocations()
|
|
||||||
}
|
|
||||||
set(value) {
|
|
||||||
sharedPreferences.edit {
|
|
||||||
putString(getString(R.string.set_key_music_locations), value.stringify())
|
|
||||||
commit()
|
|
||||||
// Sometimes changing this setting just won't actually trigger the listener.
|
|
||||||
// Only this one. No idea why.
|
|
||||||
listener?.onMusicLocationsChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override var excludedLocations: List<Location.Unopened>
|
|
||||||
get() {
|
|
||||||
val locations =
|
|
||||||
sharedPreferences.getString(getString(R.string.set_key_excluded_locations), null)
|
|
||||||
?: return emptyList()
|
|
||||||
return locations.toUnopenedLocations()
|
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
sharedPreferences.edit {
|
sharedPreferences.edit {
|
||||||
|
val filterMode =
|
||||||
|
when (value.mode) {
|
||||||
|
MediaStoreFS.FilterMode.INCLUDE -> IntegerTable.FILTER_MODE_INCLUDE
|
||||||
|
MediaStoreFS.FilterMode.EXCLUDE -> IntegerTable.FILTER_MODE_EXCLUDE
|
||||||
|
}
|
||||||
|
putInt(getString(R.string.set_key_filter_mode), filterMode)
|
||||||
putString(
|
putString(
|
||||||
getString(R.string.set_key_excluded_locations), value.stringifyLocations())
|
getString(R.string.set_key_filtered_locations), value.filtered.stringify())
|
||||||
commit()
|
putBoolean(getString(R.string.set_key_exclude_non_music), value.excludeNonMusic)
|
||||||
listener?.onMusicLocationsChanged()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val excludeNonMusic: Boolean
|
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
|
|
||||||
|
|
||||||
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
||||||
// 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)
|
||||||
@@ -216,16 +201,13 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Location.Opened>.stringify(): String =
|
private fun List<Location>.stringify(): String =
|
||||||
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
|
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
|
||||||
|
|
||||||
private fun String.toOpenedLocations(): List<Location.Opened> =
|
private fun String.toOpenedLocations(): List<Location.Opened> =
|
||||||
splitEscaped { it == ';' }
|
splitEscaped { it == ';' }
|
||||||
.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) }
|
.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) }
|
||||||
|
|
||||||
private fun List<Location>.stringifyLocations(): String =
|
|
||||||
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
|
|
||||||
|
|
||||||
private fun String.toUnopenedLocations(): List<Location.Unopened> =
|
private fun String.toUnopenedLocations(): List<Location.Unopened> =
|
||||||
splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri()) }
|
splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri()) }
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,20 @@ class LocationAdapter<T : Location>(private val listener: Listener) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
L.d("Clearing all locations")
|
||||||
|
val wasEmpty = _locations.isEmpty()
|
||||||
|
val oldSize = _locations.size
|
||||||
|
_locations.clear()
|
||||||
|
if (!wasEmpty) {
|
||||||
|
if (oldSize == 1) {
|
||||||
|
notifyItemChanged(0)
|
||||||
|
} else {
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
fun onRemoveLocation(location: Location)
|
fun onRemoveLocation(location: Location)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* LocationMode.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* 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.locations
|
||||||
|
|
||||||
|
import org.oxycblt.auxio.IntegerTable
|
||||||
|
|
||||||
|
/** Represents the mode for loading music locations. */
|
||||||
|
enum class LocationMode {
|
||||||
|
/** Use Storage Access Framework (file picker) to select specific folders */
|
||||||
|
SAF,
|
||||||
|
/** Use system MediaStore database to load all music */
|
||||||
|
MEDIA_STORE;
|
||||||
|
|
||||||
|
val intCode: Int
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
SAF -> IntegerTable.LOCATION_MODE_SAF
|
||||||
|
MEDIA_STORE -> IntegerTable.LOCATION_MODE_MEDIA_STORE
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromInt(int: Int): LocationMode? {
|
||||||
|
return when (int) {
|
||||||
|
IntegerTable.LOCATION_MODE_SAF -> SAF
|
||||||
|
IntegerTable.LOCATION_MODE_MEDIA_STORE -> MEDIA_STORE
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,19 +29,19 @@ import androidx.activity.result.ActivityResultLauncher
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.edit
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.google.android.material.R as MR
|
import com.google.android.material.R as MR
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.DialogMusicLocationsBinding
|
import org.oxycblt.auxio.databinding.DialogMusicLocationsBinding
|
||||||
import org.oxycblt.auxio.music.MusicLocationMode
|
|
||||||
import org.oxycblt.auxio.music.MusicSettings
|
import org.oxycblt.auxio.music.MusicSettings
|
||||||
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
||||||
import org.oxycblt.auxio.util.getAttrColorCompat
|
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||||
import org.oxycblt.auxio.util.showToast
|
import org.oxycblt.auxio.util.showToast
|
||||||
import org.oxycblt.musikr.fs.Location
|
import org.oxycblt.musikr.fs.Location
|
||||||
|
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||||
|
import org.oxycblt.musikr.fs.saf.SAF
|
||||||
import timber.log.Timber as L
|
import timber.log.Timber as L
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -222,26 +222,15 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
|||||||
|
|
||||||
private fun loadInitialState(binding: DialogMusicLocationsBinding) {
|
private fun loadInitialState(binding: DialogMusicLocationsBinding) {
|
||||||
// Determine mode based on the locationMode setting
|
// Determine mode based on the locationMode setting
|
||||||
isFilePickerMode = musicSettings.locationMode == MusicLocationMode.SAF
|
isFilePickerMode = musicSettings.locationMode == LocationMode.SAF
|
||||||
|
|
||||||
|
// Load data for the initial mode
|
||||||
|
loadModeData(binding)
|
||||||
|
|
||||||
|
// Set the initial toggle button selection
|
||||||
if (isFilePickerMode) {
|
if (isFilePickerMode) {
|
||||||
// File picker mode - load music locations and excluded locations
|
|
||||||
includeLocationAdapter.addAll(musicSettings.musicLocations)
|
|
||||||
excludeLocationAdapter.addAll(musicSettings.excludedLocations)
|
|
||||||
binding.configSwitchFilePicker.isChecked = musicSettings.withHidden
|
|
||||||
binding.folderModeGroup.check(R.id.locations_mode_exclude)
|
binding.folderModeGroup.check(R.id.locations_mode_exclude)
|
||||||
} else {
|
} else {
|
||||||
// System database mode - load excluded locations
|
|
||||||
// Filter locations come from exclude list
|
|
||||||
filterLocationAdapter.addAll(musicSettings.excludedLocations)
|
|
||||||
binding.configSwitchSystem.isChecked = !musicSettings.excludeNonMusic
|
|
||||||
|
|
||||||
// Determine include/exclude mode based on whether we have exclude locations
|
|
||||||
// If we have exclude locations, we're in exclude mode
|
|
||||||
isIncludeMode = musicSettings.excludedLocations.isEmpty()
|
|
||||||
binding.locationsExcludeModeGroup.check(
|
|
||||||
if (isIncludeMode) R.id.locations_exclude_mode_exclude
|
|
||||||
else R.id.locations_exclude_mode_include)
|
|
||||||
binding.folderModeGroup.check(R.id.locations_mode_include)
|
binding.folderModeGroup.check(R.id.locations_mode_include)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,6 +238,25 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
|||||||
hasStoragePermission = checkStoragePermission()
|
hasStoragePermission = checkStoragePermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadModeData(binding: DialogMusicLocationsBinding) {
|
||||||
|
// Load SAF data
|
||||||
|
musicSettings.safQuery.let { query ->
|
||||||
|
includeLocationAdapter.addAll(query.source)
|
||||||
|
excludeLocationAdapter.addAll(query.exclude)
|
||||||
|
binding.configSwitchFilePicker.isChecked = query.withHidden
|
||||||
|
}
|
||||||
|
// Load MediaStore data
|
||||||
|
musicSettings.mediaStoreQuery.let { query ->
|
||||||
|
filterLocationAdapter.addAll(query.filtered)
|
||||||
|
binding.configSwitchSystem.isChecked = query.excludeNonMusic
|
||||||
|
|
||||||
|
isIncludeMode = query.mode == MediaStoreFS.FilterMode.INCLUDE
|
||||||
|
binding.locationsExcludeModeGroup.check(
|
||||||
|
if (isIncludeMode) R.id.locations_exclude_mode_exclude
|
||||||
|
else R.id.locations_exclude_mode_include)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
// Update save button state after dialog is shown
|
// Update save button state after dialog is shown
|
||||||
@@ -486,42 +494,31 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
|||||||
|
|
||||||
// Save the mode setting
|
// Save the mode setting
|
||||||
musicSettings.locationMode =
|
musicSettings.locationMode =
|
||||||
if (isFilePickerMode) MusicLocationMode.SAF else MusicLocationMode.SYSTEM
|
if (isFilePickerMode) LocationMode.SAF else LocationMode.MEDIA_STORE
|
||||||
|
|
||||||
if (isFilePickerMode) {
|
if (isFilePickerMode) {
|
||||||
// File picker mode - save include and exclude locations
|
// File picker mode - create and save SAF query
|
||||||
musicSettings.musicLocations = includeLocationAdapter.locations
|
val safQuery =
|
||||||
musicSettings.excludedLocations = excludeLocationAdapter.locations
|
SAF.Query(
|
||||||
|
source = includeLocationAdapter.locations,
|
||||||
// Update withHidden setting
|
exclude = excludeLocationAdapter.locations,
|
||||||
val withHidden = binding.configSwitchFilePicker.isChecked
|
withHidden = binding.configSwitchFilePicker.isChecked)
|
||||||
if (musicSettings.withHidden != withHidden) {
|
musicSettings.safQuery = safQuery
|
||||||
binding.root.context.getSharedPreferences("auxio_preferences", 0).edit {
|
|
||||||
putBoolean(getString(R.string.set_key_with_hidden), withHidden)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// System database mode - clear music locations and save filter locations
|
// System database mode - create and save MediaStore query
|
||||||
musicSettings.musicLocations = emptyList()
|
val filterMode =
|
||||||
|
|
||||||
// In include mode, we don't have any excluded locations
|
|
||||||
// In exclude mode, we save the filter locations as excluded
|
|
||||||
musicSettings.excludedLocations =
|
|
||||||
if (isIncludeMode) {
|
if (isIncludeMode) {
|
||||||
emptyList()
|
MediaStoreFS.FilterMode.INCLUDE
|
||||||
} else {
|
} else {
|
||||||
filterLocationAdapter.locations
|
MediaStoreFS.FilterMode.EXCLUDE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update excludeNonMusic setting
|
val mediaStoreQuery =
|
||||||
val excludeNonMusic = !binding.configSwitchSystem.isChecked
|
MediaStoreFS.Query(
|
||||||
if (musicSettings.excludeNonMusic != excludeNonMusic) {
|
mode = filterMode,
|
||||||
binding.root.context.getSharedPreferences("auxio_preferences", 0).edit {
|
filtered = filterLocationAdapter.locations,
|
||||||
putBoolean(getString(R.string.set_key_exclude_non_music), excludeNonMusic)
|
excludeNonMusic = !binding.configSwitchSystem.isChecked)
|
||||||
apply()
|
musicSettings.mediaStoreQuery = mediaStoreQuery
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,13 +159,12 @@ private constructor(
|
|||||||
|
|
||||||
private fun startTracking() {
|
private fun startTracking() {
|
||||||
stopTracking()
|
stopTracking()
|
||||||
val locations = musicSettings.musicLocations
|
val safQuery = musicSettings.safQuery
|
||||||
if (locations.isEmpty()) return
|
if (safQuery == null || safQuery.source.isEmpty()) return
|
||||||
|
|
||||||
trackingJob =
|
trackingJob =
|
||||||
indexScope.launch {
|
indexScope.launch {
|
||||||
val query = SAF.Query(source = locations, exclude = emptyList(), withHidden = false)
|
SAF.from(workerContext, safQuery).track().collect {
|
||||||
SAF.from(workerContext, query).track().collect {
|
|
||||||
if (musicSettings.shouldBeObserving) {
|
if (musicSettings.shouldBeObserving) {
|
||||||
musicRepository.requestIndex(true)
|
musicRepository.requestIndex(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
<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_excluded_locations" translatable="false">auxio_excluded_locations</string>
|
||||||
|
<string name="set_key_filter_mode" translatable="false">auxio_filter_mode</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_saf_mode" translatable="false">auxio_saf_mode</string>
|
||||||
|
|||||||
@@ -9,18 +9,6 @@
|
|||||||
app:summary="@string/set_observing_desc"
|
app:summary="@string/set_observing_desc"
|
||||||
app:title="@string/set_observing" />
|
app:title="@string/set_observing" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
app:defaultValue="true"
|
|
||||||
app:key="@string/set_key_exclude_non_music"
|
|
||||||
app:summary="@string/set_exclude_non_music_desc"
|
|
||||||
app:title="@string/set_exclude_non_music" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
app:defaultValue="false"
|
|
||||||
app:key="@string/set_key_with_hidden"
|
|
||||||
app:summary="@string/set_with_hidden_desc"
|
|
||||||
app:title="@string/set_with_hidden" />
|
|
||||||
|
|
||||||
<org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
<org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
||||||
app:key="@string/set_key_separators"
|
app:key="@string/set_key_separators"
|
||||||
app:summary="@string/set_separators_desc"
|
app:summary="@string/set_separators_desc"
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ private constructor(
|
|||||||
|
|
||||||
data class Query(
|
data class Query(
|
||||||
val mode: FilterMode,
|
val mode: FilterMode,
|
||||||
val filtered: List<Location>,
|
val filtered: List<Location.Unopened>,
|
||||||
val excludeNonMusic: Boolean
|
val excludeNonMusic: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user