mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 04:47:56 +01:00
Convert source display mode preference to flow, remove RxPreferences
This commit is contained in:
@@ -4,8 +4,6 @@ import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.f2prateek.rx.preferences.Preference as RxPreference
|
||||
import com.f2prateek.rx.preferences.RxSharedPreferences
|
||||
import com.tfcporciuncula.flow.FlowSharedPreferences
|
||||
import com.tfcporciuncula.flow.Preference
|
||||
import eu.kanade.tachiyomi.R
|
||||
@@ -21,8 +19,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
fun <T> RxPreference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||
block(get())
|
||||
@@ -34,7 +30,6 @@ fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||
class PreferencesHelper(val context: Context) {
|
||||
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
private val rxPrefs = RxSharedPreferences.create(prefs)
|
||||
private val flowPrefs = FlowSharedPreferences(prefs)
|
||||
|
||||
private val defaultDownloadsDir = Uri.fromFile(
|
||||
@@ -143,7 +138,7 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
||||
|
||||
fun catalogueAsList() = rxPrefs.getBoolean(Keys.catalogueAsList, false)
|
||||
fun catalogueAsList() = flowPrefs.getBoolean(Keys.catalogueAsList, false)
|
||||
|
||||
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user