1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 20:12:39 +01:00

Remove koincomponent from BiometricUtils

This commit is contained in:
Allan Wang 2020-02-23 17:00:57 -08:00
parent f45f3503ee
commit 166dc46c24
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
6 changed files with 11 additions and 14 deletions

View File

@ -75,7 +75,7 @@ class StartActivity : KauBaseActivity() {
launch {
try {
val authDefer = BiometricUtils.authenticate(this@StartActivity)
val authDefer = BiometricUtils.authenticate(this@StartActivity, prefs)
fbCookie.switchBackUser()
val cookies = ArrayList(cookieDao.selectAll())
L.i { "Cookies loaded at time ${System.currentTimeMillis()}" }

View File

@ -756,7 +756,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
lastAccessTime = System.currentTimeMillis() // precaution to avoid loops
controlWebview?.resumeTimers()
launch {
val authDefer = BiometricUtils.authenticate(this@BaseMainActivity)
val authDefer = BiometricUtils.authenticate(this@BaseMainActivity, prefs)
fbCookie.switchBackUser()
authDefer.await()
if (shouldReload && prefs.autoRefreshFeed) {

View File

@ -225,7 +225,7 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT
userAgentString = userAgent
prefs.prevId = prefs.userId
launch {
val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase)
val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase, prefs)
if (userId != prefs.userId) {
fbCookie.switchUser(userId)
}

View File

@ -40,7 +40,6 @@ import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.REQUEST_REFRESH
import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM
import com.pitchedapps.frost.utils.frostEvent
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
@ -48,8 +47,8 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.koin.core.KoinComponent
import org.koin.core.inject
import org.koin.android.ext.android.inject
import kotlin.coroutines.CoroutineContext
/**
* Created by Allan Wang on 2017-11-07.
@ -58,7 +57,7 @@ import org.koin.core.inject
* Must be attached to activities implementing [MainActivityContract]
*/
@UseExperimental(ExperimentalCoroutinesApi::class)
abstract class BaseFragment : Fragment(), CoroutineScope, KoinComponent, FragmentContract,
abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract,
DynamicUiContract {
companion object {

View File

@ -38,7 +38,7 @@ fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = {
* - enabling to ensure that it is supported
* - disabling to ensure that it is permitted
*/
BiometricUtils.authenticate(this@getSecurityPrefs, force = true).await()
BiometricUtils.authenticate(this@getSecurityPrefs, prefs, force = true).await()
prefs.biometricsEnabled = it
reloadByTitle(R.string.enable_biometrics)
}

View File

@ -39,13 +39,11 @@ typealias BiometricDeferred = CompletableDeferred<BiometricPrompt.CryptoObject?>
* Container for [BiometricPrompt]
* Inspired by coroutine's CommonPool
*/
object BiometricUtils : KoinComponent {
object BiometricUtils {
private val executor: Executor
get() = pool ?: getOrCreatePoolSync()
private val prefs: Prefs by inject()
@Volatile
private var pool: ExecutorService? = null
@ -68,7 +66,7 @@ object BiometricUtils : KoinComponent {
private fun getOrCreatePoolSync(): Executor =
pool ?: Executors.newSingleThreadExecutor().also { pool = it }
private fun shouldPrompt(context: Context): Boolean {
private fun shouldPrompt(context: Context, prefs: Prefs): Boolean {
return prefs.biometricsEnabled && System.currentTimeMillis() - lastUnlockTime > UNLOCK_TIME_INTERVAL
}
@ -77,9 +75,9 @@ object BiometricUtils : KoinComponent {
* Note that the underlying request will call [androidx.fragment.app.FragmentTransaction.commit],
* so this cannot happen after onSaveInstanceState.
*/
fun authenticate(activity: FragmentActivity, force: Boolean = false): BiometricDeferred {
fun authenticate(activity: FragmentActivity, prefs: Prefs, force: Boolean = false): BiometricDeferred {
val deferred: BiometricDeferred = CompletableDeferred()
if (!force && !shouldPrompt(activity)) {
if (!force && !shouldPrompt(activity, prefs)) {
deferred.complete(null)
return deferred
}