Migrate some RxSharedPreferences to FlowSharedPreferences

(cherry picked from commit beb81b657ea8c1297ea86ed0fc98122066947c84)
This commit is contained in:
Jobobby04 2020-04-20 16:18:17 -04:00
parent 85723b975b
commit 8bc5a7d746

View File

@ -6,11 +6,17 @@ import com.bluelinelabs.conductor.Router
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
object LockActivityDelegate { object LockActivityDelegate {
private val preferences by injectLazy<PreferencesHelper>() private val preferences by injectLazy<PreferencesHelper>()
val uiScope = CoroutineScope(Dispatchers.Main)
var willLock: Boolean = true var willLock: Boolean = true
fun doLock(router: Router, animate: Boolean = false) { fun doLock(router: Router, animate: Boolean = false) {
@ -19,14 +25,15 @@ object LockActivityDelegate {
} }
fun onCreate(activity: FragmentActivity) { fun onCreate(activity: FragmentActivity) {
preferences.secureScreen().asObservable() preferences.secureScreen().asFlow()
.subscribe { .onEach {
if (it) { if (it) {
activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else { } else {
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
} }
} }
.launchIn(uiScope)
} }
fun onResume(activity: FragmentActivity, router: Router) { fun onResume(activity: FragmentActivity, router: Router) {