Extract and unit test MultipleTapToUnlock

This commit is contained in:
Benoit Marty 2025-06-26 17:44:08 +02:00
parent 9bd2c178f4
commit e806d07865
6 changed files with 95 additions and 8 deletions

View file

@ -15,6 +15,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import io.element.android.features.logout.api.direct.DirectLogoutState
import io.element.android.features.preferences.impl.utils.ShowDeveloperSettingsProvider
@ -49,6 +50,7 @@ class PreferencesRootPresenter @Inject constructor(
) : Presenter<PreferencesRootState> {
@Composable
override fun present(): PreferencesRootState {
val coroutineScope = rememberCoroutineScope()
val matrixUser = matrixClient.userProfile.collectAsState()
LaunchedEffect(Unit) {
// Force a refresh of the profile
@ -103,7 +105,7 @@ class PreferencesRootPresenter @Inject constructor(
fun handleEvent(event: PreferencesRootEvents) {
when (event) {
is PreferencesRootEvents.OnVersionInfoClick -> {
showDeveloperSettingsProvider.unlockDeveloperSettings()
showDeveloperSettingsProvider.unlockDeveloperSettings(coroutineScope)
}
}
}

View file

@ -9,6 +9,8 @@ package io.element.android.features.preferences.impl.utils
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.ui.utils.MultipleTapToUnlock
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject
@ -19,18 +21,15 @@ class ShowDeveloperSettingsProvider @Inject constructor(
companion object {
const val DEVELOPER_SETTINGS_COUNTER = 7
}
private var counter = DEVELOPER_SETTINGS_COUNTER
private val multipleTapToUnlock = MultipleTapToUnlock(DEVELOPER_SETTINGS_COUNTER)
private val isDeveloperBuild = buildMeta.buildType != BuildType.RELEASE
private val _showDeveloperSettings = MutableStateFlow(isDeveloperBuild)
val showDeveloperSettings: StateFlow<Boolean> = _showDeveloperSettings
fun unlockDeveloperSettings() {
if (counter == 0) {
return
}
counter--
if (counter == 0) {
fun unlockDeveloperSettings(scope: CoroutineScope) {
if (multipleTapToUnlock.unlock(scope)) {
_showDeveloperSettings.value = true
}
}