Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId = "com.nativeapptemplate.nativeapptemplatefree"
targetSdk = 35
minSdk = 26
versionCode = 2
versionName = "2.0.0"
versionCode = 3
versionName = "2.0.1"

vectorDrawables {
useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import com.nativeapptemplate.nativeapptemplatefree.ui.app_root.rememberNatAppSta
import com.nativeapptemplate.nativeapptemplatefree.utils.NetworkMonitor
import com.nativeapptemplate.nativeapptemplatefree.utils.Utility
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import java.util.Date
import javax.inject.Inject
Expand All @@ -47,13 +45,12 @@ class MainActivity : ComponentActivity() {
lateinit var loginRepository: LoginRepository

private val viewModel: MainActivityViewModel by viewModels()
var uiState: MainActivityUiState by mutableStateOf(Loading)

override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)

var uiState: MainActivityUiState by mutableStateOf(Loading)

viewModel.updateShouldNavigateToScanView(false)
viewModel.updateShouldFetchItemTagForShowTagInfoScan(false)
viewModel.updateShouldCompleteItemTagForCompleteScan(false)
Expand All @@ -67,9 +64,9 @@ class MainActivity : ComponentActivity() {
// Update the uiState
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState
.onEach { uiState = it }
.collect()
viewModel.uiState.collect {
uiState = it
}
}
}

Expand Down Expand Up @@ -121,6 +118,8 @@ class MainActivity : ComponentActivity() {
}
}

if (!uiState.isLoggedIn) return

val intent = intent
if (NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action) {
viewModel.updateShouldNavigateToScanView(false)
Expand Down Expand Up @@ -153,6 +152,9 @@ class MainActivity : ComponentActivity() {

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)

if (!uiState.isLoggedIn) return

if (NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action) {
viewModel.updateShouldNavigateToScanView(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@ class MainActivityViewModel @Inject constructor(

sealed interface MainActivityUiState {
data object Loading : MainActivityUiState
data class Success(val userData: UserData) : MainActivityUiState
data class Success(val userData: UserData) : MainActivityUiState {
override val isLoggedIn = userData.isLoggedIn
}

val isLoggedIn: Boolean get() = false
}