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
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.content.edit
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
|
@ -55,21 +54,19 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
|||
|
||||
class MusicSettingsImpl @Inject constructor(@ApplicationContext private val context: Context) :
|
||||
Settings.Impl<MusicSettings.Listener>(context), MusicSettings {
|
||||
|
||||
override var musicLocations: List<MusicLocation>
|
||||
get() {
|
||||
val dirs =
|
||||
sharedPreferences.getStringSet(getString(R.string.set_key_music_locations), null) ?:
|
||||
emptySet()
|
||||
return dirs.mapNotNull {
|
||||
MusicLocation.existing(context, Uri.parse(it))
|
||||
}
|
||||
val locations =
|
||||
sharedPreferences.getString(getString(R.string.set_key_music_locations), null)
|
||||
?: return emptyList()
|
||||
return MusicLocation.existing(context, locations)
|
||||
}
|
||||
set(value) {
|
||||
sharedPreferences.edit {
|
||||
putStringSet(
|
||||
getString(R.string.set_key_music_locations),
|
||||
value.map { it.toString() }.toSet())
|
||||
apply()
|
||||
putString(
|
||||
getString(R.string.set_key_music_locations), MusicLocation.toString(value))
|
||||
this@edit.apply()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,12 +59,9 @@ class MusicSourcesDialog :
|
|||
.setNegativeButton(R.string.lbl_cancel, null)
|
||||
.setPositiveButton(R.string.lbl_save) { _, _ ->
|
||||
val newDirs = locationAdapter.locations
|
||||
if (musicSettings.musicLocations != newDirs) {
|
||||
L.d("Committing changes")
|
||||
musicSettings.musicLocations = newDirs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindingCreated(
|
||||
binding: DialogMusicLocationsBinding,
|
||||
|
|
|
@ -60,7 +60,12 @@ class MusicLocation internal constructor(val uri: Uri, val path: Path) {
|
|||
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
|
||||
return MusicLocation(uri, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val VOLUME_INTERNAL = "internal"
|
||||
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)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue