diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt deleted file mode 100644 index f6b85b33e..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt +++ /dev/null @@ -1,42 +0,0 @@ -package eu.kanade.tachiyomi.util - -import android.content.SharedPreferences -import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.channels.awaitClose -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.channelFlow -import kotlinx.coroutines.flow.flowOn - -@ExperimentalCoroutinesApi -inline fun SharedPreferences.getKey(key: String, default: T, dispatcher: CoroutineContext = Dispatchers.Default): Flow { - val flow: Flow = channelFlow { - offer(getItem(key, default)) - - val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k -> - if (key == k) { - offer(getItem(key, default)!!) - } - } - - registerOnSharedPreferenceChangeListener(listener) - awaitClose { unregisterOnSharedPreferenceChangeListener(listener) } - } - return flow - .flowOn(dispatcher) -} - -inline fun SharedPreferences.getItem(key: String, default: T): T { - @Suppress("UNCHECKED_CAST") - return when (default) { - is String -> getString(key, default) as T - is Int -> getInt(key, default) as T - is Long -> getLong(key, default) as T - is Boolean -> getBoolean(key, default) as T - is Float -> getFloat(key, default) as T - is Set<*> -> getStringSet(key, default as Set) as T - is MutableSet<*> -> getStringSet(key, default as MutableSet) as T - else -> throw IllegalArgumentException("Generic type not handled: ${T::class.java.name}") - } -}