更新
This commit is contained in:
@@ -32,6 +32,7 @@ import androidx.core.view.WindowCompat
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.ServiceException
|
||||
import com.aiosman.riderpro.data.TestAccountServiceImpl
|
||||
import com.aiosman.riderpro.data.TestUserServiceImpl
|
||||
import com.aiosman.riderpro.data.UserService
|
||||
@@ -43,17 +44,20 @@ import com.google.android.libraries.places.api.Places
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.HttpException
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val scope = CoroutineScope(Dispatchers.Main)
|
||||
suspend fun getAccount() {
|
||||
//TODO apply token to client
|
||||
if (!AppStore.rememberMe) {
|
||||
return
|
||||
}
|
||||
suspend fun getAccount(): Boolean {
|
||||
val accountService: AccountService = TestAccountServiceImpl()
|
||||
accountService.getMyAccount()
|
||||
try {
|
||||
val resp = accountService.getMyAccount()
|
||||
return true
|
||||
} catch (e: ServiceException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
@@ -64,9 +68,9 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
|
||||
scope.launch {
|
||||
getAccount()
|
||||
val isAccountValidate = getAccount()
|
||||
var startDestination = NavigationRoute.Login.route
|
||||
if (AppStore.token != null && AppStore.rememberMe) {
|
||||
if (AppStore.token != null && AppStore.rememberMe && isAccountValidate) {
|
||||
startDestination = NavigationRoute.Index.route
|
||||
}
|
||||
setContent {
|
||||
|
||||
Reference in New Issue
Block a user