@@ -47,13 +47,12 @@ class MainActivity : ComponentActivity() {
4747 lateinit var loginRepository: LoginRepository
4848
4949 private val viewModel: MainActivityViewModel by viewModels()
50+ var uiState: MainActivityUiState by mutableStateOf(Loading )
5051
5152 override fun onCreate (savedInstanceState : Bundle ? ) {
5253 val splashScreen = installSplashScreen()
5354 super .onCreate(savedInstanceState)
5455
55- var uiState: MainActivityUiState by mutableStateOf(Loading )
56-
5756 viewModel.updateShouldNavigateToScanView(false )
5857 viewModel.updateShouldFetchItemTagForShowTagInfoScan(false )
5958 viewModel.updateShouldCompleteItemTagForCompleteScan(false )
@@ -67,9 +66,9 @@ class MainActivity : ComponentActivity() {
6766 // Update the uiState
6867 lifecycleScope.launch {
6968 lifecycle.repeatOnLifecycle(Lifecycle .State .STARTED ) {
70- viewModel.uiState
71- .onEach { uiState = it }
72- .collect()
69+ viewModel.uiState.collect {
70+ uiState = it
71+ }
7372 }
7473 }
7574
@@ -121,6 +120,8 @@ class MainActivity : ComponentActivity() {
121120 }
122121 }
123122
123+ if (! uiState.isLoggedIn) return
124+
124125 val intent = intent
125126 if (NfcAdapter .ACTION_NDEF_DISCOVERED == intent.action) {
126127 viewModel.updateShouldNavigateToScanView(false )
@@ -153,6 +154,9 @@ class MainActivity : ComponentActivity() {
153154
154155 override fun onNewIntent (intent : Intent ) {
155156 super .onNewIntent(intent)
157+
158+ if (! uiState.isLoggedIn) return
159+
156160 if (NfcAdapter .ACTION_NDEF_DISCOVERED == intent.action) {
157161 viewModel.updateShouldNavigateToScanView(false )
158162
0 commit comments