Bimba.git

ref: e5c7dc933fba208aba52c3dcb305b522120b4b2c

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
30
// SPDX-FileCopyrightText: Adam Evyčędo
//
// SPDX-License-Identifier: GPL-3.0-or-later

package xyz.apiote.bimba.czwek.settings.feeds

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class FeedsViewModel : ViewModel() {
	private val _settings = MutableLiveData<FeedsSettings>()
	val settings: LiveData<FeedsSettings> = _settings

	fun loadSettings(context: Context) {
		_settings.value = FeedsSettings.load(context)
	}

	fun setSettings(feedID: String, feedSettings: FeedSettings) {
		val feedsSettings = _settings.value ?: FeedsSettings(mutableMapOf())
		feedsSettings.settings[feedID] = feedSettings
		_settings.value = feedsSettings
	}

	fun setEnabled(feedID: String, enabled: Boolean) {
		val feedSettings = (_settings.value ?: FeedsSettings(mutableMapOf())).settings[feedID]
		setSettings(feedID, feedSettings?.copy(enabled = enabled) ?: FeedSettings(enabled, true))
	}
}