ref: ece2d164cf08f2544955a5a1b367e0030707302a
app/src/main/java/xyz/apiote/bimba/czwek/settings/feeds/FeedsViewModel.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package xyz.apiote.bimba.czwek.settings.feeds import android.content.Context import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import xyz.apiote.bimba.czwek.api.Server class FeedsViewModel : ViewModel() { private val _settings = MutableLiveData<FeedsSettings>() val settings: LiveData<FeedsSettings> = _settings fun loadSettings(context: Context) { _settings.value = FeedsSettings.load(context, Server.get(context).apiPath) } fun setSettings(feedID: String, feedSettings: FeedSettings) { val feedsSettings = _settings.value ?: FeedsSettings(mutableMapOf()) feedsSettings.settings[feedID] = feedSettings _settings.value = feedsSettings Log.i("Settings", "${_settings.value}") } fun setEnabled(feedID: String, enabled: Boolean) { val feedSettings = (_settings.value ?: FeedsSettings(mutableMapOf())).settings[feedID] setSettings(feedID, feedSettings?.copy(enabled = enabled) ?: FeedSettings(enabled, true)) } } |