mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Migrate some RxSharedPreferences to FlowSharedPreferences
This commit is contained in:
		| @@ -7,6 +7,7 @@ import android.os.Environment | ||||
| import androidx.preference.PreferenceManager | ||||
| import com.f2prateek.rx.preferences.Preference | ||||
| import com.f2prateek.rx.preferences.RxSharedPreferences | ||||
| import com.tfcporciuncula.flow.FlowSharedPreferences | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys | ||||
| import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values | ||||
| @@ -15,6 +16,7 @@ import java.io.File | ||||
| import java.text.DateFormat | ||||
| import java.text.SimpleDateFormat | ||||
| import java.util.Locale | ||||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||||
|  | ||||
| fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!! | ||||
|  | ||||
| @@ -36,10 +38,12 @@ private class DateFormatConverter : Preference.Adapter<DateFormat> { | ||||
|     } | ||||
| } | ||||
|  | ||||
| @OptIn(ExperimentalCoroutinesApi::class) | ||||
| 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( | ||||
|             File(Environment.getExternalStorageDirectory().absolutePath + File.separator + | ||||
| @@ -51,13 +55,13 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun startScreen() = prefs.getInt(Keys.startScreen, 1) | ||||
|  | ||||
|     fun useBiometricLock() = rxPrefs.getBoolean(Keys.useBiometricLock, false) | ||||
|     fun useBiometricLock() = flowPrefs.getBoolean(Keys.useBiometricLock, false) | ||||
|  | ||||
|     fun lockAppAfter() = rxPrefs.getInteger(Keys.lockAppAfter, 0) | ||||
|     fun lockAppAfter() = flowPrefs.getInt(Keys.lockAppAfter, 0) | ||||
|  | ||||
|     fun lastAppUnlock() = rxPrefs.getLong(Keys.lastAppUnlock, 0) | ||||
|     fun lastAppUnlock() = flowPrefs.getLong(Keys.lastAppUnlock, 0) | ||||
|  | ||||
|     fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false) | ||||
|     fun secureScreen() = flowPrefs.getBoolean(Keys.secureScreen, false) | ||||
|  | ||||
|     fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user