Naming for code review

This commit is contained in:
Andrew 2024-06-07 16:36:46 +09:30
parent f66fbef0ad
commit 5459b1eb1d
3 changed files with 10 additions and 17 deletions

View File

@ -1,11 +1,8 @@
package org.thoughtcrime.securesms.onboarding package org.thoughtcrime.securesms.onboarding
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.camera.core.ExperimentalGetImage 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.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row 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.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.lifecycleScope 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 dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import network.loki.messenger.R import network.loki.messenger.R
@ -79,7 +73,7 @@ class LinkDeviceActivity : BaseActionBarActivity() {
setContent { setContent {
val state by viewModel.stateFlow.collectAsState() val state by viewModel.stateFlow.collectAsState()
AppTheme { AppTheme {
LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::scan) LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
} }
} }
}.let(::setContentView) }.let(::setContentView)

View File

@ -47,7 +47,7 @@ class LinkDeviceViewModel @Inject constructor(
} }
} }
fun scan(string: String) { fun onScanQrCode(string: String) {
viewModelScope.launch { viewModelScope.launch {
runDecodeCatching(string) runDecodeCatching(string)
.onSuccess(::onSuccess) .onSuccess(::onSuccess)

View File

@ -28,11 +28,10 @@ import kotlin.time.Duration.Companion.seconds
data class State(val duration: Duration) data class State(val duration: Duration)
private val DONE_TIME = 1.seconds private val ANIMATE_TO_DONE_TIME = 500.milliseconds
private val DONE_ANIMATE_TIME = 500.milliseconds private val IDLE_DONE_TIME = 1.seconds
private val TIMEOUT_TIME = 15.seconds
private val TOTAL_ANIMATE_TIME = 14.seconds private val TOTAL_ANIMATION_TIME = TIMEOUT_TIME - IDLE_DONE_TIME
private val TOTAL_TIME = 15.seconds
@HiltViewModel @HiltViewModel
class LoadingViewModel @Inject constructor( class LoadingViewModel @Inject constructor(
@ -40,7 +39,7 @@ class LoadingViewModel @Inject constructor(
private val prefs: TextSecurePreferences, private val prefs: TextSecurePreferences,
) : ViewModel() { ) : ViewModel() {
private val state = MutableStateFlow(State(TOTAL_ANIMATE_TIME)) private val state = MutableStateFlow(State(TOTAL_ANIMATION_TIME))
val stateFlow = state.asStateFlow() val stateFlow = state.asStateFlow()
private val event = Channel<Event>() private val event = Channel<Event>()
@ -77,7 +76,7 @@ class LoadingViewModel @Inject constructor(
} }
val skipJob = launch(Dispatchers.IO) { val skipJob = launch(Dispatchers.IO) {
delay(TOTAL_TIME) delay(TIMEOUT_TIME)
event.send(Event.TIMEOUT) event.send(Event.TIMEOUT)
} }
@ -87,8 +86,8 @@ class LoadingViewModel @Inject constructor(
// handle we've synced // handle we've synced
skipJob.cancel() skipJob.cancel()
state.value = State(DONE_ANIMATE_TIME) state.value = State(ANIMATE_TO_DONE_TIME)
delay(DONE_TIME) delay(IDLE_DONE_TIME)
event.send(Event.SUCCESS) event.send(Event.SUCCESS)
} }
} }