From 5459b1eb1d5c2f873fea30125e0477186cde01ec Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 7 Jun 2024 16:36:46 +0930 Subject: [PATCH] Naming for code review --- .../securesms/onboarding/LinkDeviceActivity.kt | 8 +------- .../securesms/onboarding/LinkDeviceViewModel.kt | 2 +- .../securesms/onboarding/LoadingViewModel.kt | 17 ++++++++--------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt index 246132b645..c4e7cca883 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt @@ -1,11 +1,8 @@ package org.thoughtcrime.securesms.onboarding -import android.annotation.SuppressLint import android.os.Bundle import androidx.activity.viewModels import androidx.camera.core.ExperimentalGetImage -import androidx.camera.core.ImageAnalysis.Analyzer -import androidx.camera.core.ImageProxy import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -30,9 +27,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.lifecycleScope -import com.google.mlkit.vision.barcode.BarcodeScanner -import com.google.mlkit.vision.barcode.common.Barcode -import com.google.mlkit.vision.common.InputImage import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch import network.loki.messenger.R @@ -79,7 +73,7 @@ class LinkDeviceActivity : BaseActionBarActivity() { setContent { val state by viewModel.stateFlow.collectAsState() AppTheme { - LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::scan) + LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode) } } }.let(::setContentView) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt index 8b075f2842..e737345c45 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt @@ -47,7 +47,7 @@ class LinkDeviceViewModel @Inject constructor( } } - fun scan(string: String) { + fun onScanQrCode(string: String) { viewModelScope.launch { runDecodeCatching(string) .onSuccess(::onSuccess) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt index bf50baa736..bf4aad1a4b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt @@ -28,11 +28,10 @@ import kotlin.time.Duration.Companion.seconds data class State(val duration: Duration) -private val DONE_TIME = 1.seconds -private val DONE_ANIMATE_TIME = 500.milliseconds - -private val TOTAL_ANIMATE_TIME = 14.seconds -private val TOTAL_TIME = 15.seconds +private val ANIMATE_TO_DONE_TIME = 500.milliseconds +private val IDLE_DONE_TIME = 1.seconds +private val TIMEOUT_TIME = 15.seconds +private val TOTAL_ANIMATION_TIME = TIMEOUT_TIME - IDLE_DONE_TIME @HiltViewModel class LoadingViewModel @Inject constructor( @@ -40,7 +39,7 @@ class LoadingViewModel @Inject constructor( private val prefs: TextSecurePreferences, ) : ViewModel() { - private val state = MutableStateFlow(State(TOTAL_ANIMATE_TIME)) + private val state = MutableStateFlow(State(TOTAL_ANIMATION_TIME)) val stateFlow = state.asStateFlow() private val event = Channel() @@ -77,7 +76,7 @@ class LoadingViewModel @Inject constructor( } val skipJob = launch(Dispatchers.IO) { - delay(TOTAL_TIME) + delay(TIMEOUT_TIME) event.send(Event.TIMEOUT) } @@ -87,8 +86,8 @@ class LoadingViewModel @Inject constructor( // handle we've synced skipJob.cancel() - state.value = State(DONE_ANIMATE_TIME) - delay(DONE_TIME) + state.value = State(ANIMATE_TO_DONE_TIME) + delay(IDLE_DONE_TIME) event.send(Event.SUCCESS) } }