@ -15,12 +15,17 @@ import androidx.core.os.LocaleListCompat
import androidx.documentfile.provider.DocumentFile
import androidx.preference.PreferenceManager
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onStart
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.ZoomMode
import org.koitharu.kotatsu.core.network.DoHProvider
import org.koitharu.kotatsu.core.util.ext.connectivityManager
import org.koitharu.kotatsu.core.util.ext.getEnumValue
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.observe Changes
import org.koitharu.kotatsu.core.util.ext.putAll
import org.koitharu.kotatsu.core.util.ext.putEnumValue
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
@ -82,6 +87,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
val isNavBarPinned : Boolean
get ( ) = prefs . getBoolean ( KEY _NAV _PINNED , false )
val isMainFabEnabled : Boolean
get ( ) = prefs . getBoolean ( KEY _MAIN _FAB , true )
var gridSize : Int
get ( ) = prefs . getInt ( KEY _GRID _SIZE , 100 )
set ( value ) = prefs . edit { putInt ( KEY _GRID _SIZE , value ) }
@ -598,7 +606,12 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
prefs . unregisterOnSharedPreferenceChangeListener ( listener )
}
fun observe ( ) = prefs . observe ( )
fun observeChanges ( ) = prefs . observeChanges ( )
fun observe ( vararg keys : String ) : Flow < String ? > = prefs . observeChanges ( )
. filter { key -> key == null || key in keys }
. onStart { emit ( null ) }
. flowOn ( Dispatchers . IO )
fun getAllValues ( ) : Map < String , * > = prefs . all
@ -743,6 +756,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY _NAV _MAIN = " nav_main "
const val KEY _NAV _LABELS = " nav_labels "
const val KEY _NAV _PINNED = " nav_pinned "
const val KEY _MAIN _FAB = " main_fab "
const val KEY _32BIT _COLOR = " enhanced_colors "
const val KEY _SOURCES _ORDER = " sources_sort_order "
const val KEY _SOURCES _CATALOG = " sources_catalog "