music: fix settings update insanity
For some reason StringSet updates will simply not go to the listener. Despite it working just fine in previous versions. I have to derialize all the location to a string and use that.
This commit is contained in:
parent
76eb98c3af
commit
a593f2874d
3 changed files with 16 additions and 17 deletions
|
@ -19,7 +19,6 @@
|
||||||
package org.oxycblt.auxio.music
|
package org.oxycblt.auxio.music
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -55,21 +54,19 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
||||||
|
|
||||||
class MusicSettingsImpl @Inject constructor(@ApplicationContext private val context: Context) :
|
class MusicSettingsImpl @Inject constructor(@ApplicationContext private val context: Context) :
|
||||||
Settings.Impl<MusicSettings.Listener>(context), MusicSettings {
|
Settings.Impl<MusicSettings.Listener>(context), MusicSettings {
|
||||||
|
|
||||||
override var musicLocations: List<MusicLocation>
|
override var musicLocations: List<MusicLocation>
|
||||||
get() {
|
get() {
|
||||||
val dirs =
|
val locations =
|
||||||
sharedPreferences.getStringSet(getString(R.string.set_key_music_locations), null) ?:
|
sharedPreferences.getString(getString(R.string.set_key_music_locations), null)
|
||||||
emptySet()
|
?: return emptyList()
|
||||||
return dirs.mapNotNull {
|
return MusicLocation.existing(context, locations)
|
||||||
MusicLocation.existing(context, Uri.parse(it))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
sharedPreferences.edit {
|
sharedPreferences.edit {
|
||||||
putStringSet(
|
putString(
|
||||||
getString(R.string.set_key_music_locations),
|
getString(R.string.set_key_music_locations), MusicLocation.toString(value))
|
||||||
value.map { it.toString() }.toSet())
|
this@edit.apply()
|
||||||
apply()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,12 +59,9 @@ class MusicSourcesDialog :
|
||||||
.setNegativeButton(R.string.lbl_cancel, null)
|
.setNegativeButton(R.string.lbl_cancel, null)
|
||||||
.setPositiveButton(R.string.lbl_save) { _, _ ->
|
.setPositiveButton(R.string.lbl_save) { _, _ ->
|
||||||
val newDirs = locationAdapter.locations
|
val newDirs = locationAdapter.locations
|
||||||
if (musicSettings.musicLocations != newDirs) {
|
|
||||||
L.d("Committing changes")
|
|
||||||
musicSettings.musicLocations = newDirs
|
musicSettings.musicLocations = newDirs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindingCreated(
|
override fun onBindingCreated(
|
||||||
binding: DialogMusicLocationsBinding,
|
binding: DialogMusicLocationsBinding,
|
||||||
|
|
|
@ -60,7 +60,12 @@ class MusicLocation internal constructor(val uri: Uri, val path: Path) {
|
||||||
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
|
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
|
||||||
return MusicLocation(uri, path)
|
return MusicLocation(uri, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toString(list: List<MusicLocation>) =
|
||||||
|
list.joinToString(";") { it.uri.toString().replace(";", "\\;") }
|
||||||
|
|
||||||
|
fun existing(context: Context, string: String): List<MusicLocation> {
|
||||||
|
return string.splitEscaped { it == ';' }.mapNotNull { existing(context, Uri.parse(it)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val VOLUME_INTERNAL = "internal"
|
|
||||||
|
|
Loading…
Reference in a new issue