This commit is contained in:
2024-08-11 17:15:17 +08:00
parent 2dc0ee3307
commit 19527f17c3
32 changed files with 1082 additions and 417 deletions

View File

@@ -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 {