|
@@ -2,7 +2,6 @@ package com.ys.bdtp.adm.mvvm.ui.screen.flash
|
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
import android.net.ConnectivityManager
|
|
|
-import android.util.Log
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.*
|
|
@@ -22,44 +21,65 @@ import com.ys.bdtp.adm.R
|
|
|
import com.ys.bdtp.adm.app.Token
|
|
|
import com.ys.bdtp.adm.app.isNet
|
|
|
import com.ys.bdtp.adm.app.theme.textBlackColor
|
|
|
+import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.Zygote
|
|
|
import com.ys.bdtp.adm.mvvm.vm.flash.FlashViewModel
|
|
|
-import kotlinx.coroutines.delay
|
|
|
import org.kodein.di.compose.rememberInstance
|
|
|
import org.kodein.di.compose.rememberViewModel
|
|
|
|
|
|
@Composable
|
|
|
-fun FlashScreen(block: (Zygote) -> Unit) {
|
|
|
+fun Flash() {
|
|
|
val vm by rememberViewModel<FlashViewModel>()
|
|
|
val cm by rememberInstance<ConnectivityManager>()
|
|
|
- val zygote by rememberUpdatedState(block)
|
|
|
val sp by rememberInstance<SharedPreferences>()
|
|
|
- LaunchedEffect(Unit) {
|
|
|
|
|
|
+ val nav = LocalNavHostController.current!!
|
|
|
+
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
val user = vm.getCurrentUser()
|
|
|
val isNet = isNet(cm)
|
|
|
|
|
|
when {
|
|
|
user == null -> { // 未登录
|
|
|
- zygote(Zygote.Login)
|
|
|
+ nav.navigate(Zygote.Login) {
|
|
|
+ popUpTo(Zygote.Flash) {
|
|
|
+ inclusive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
!isNet -> { // 登录 && 未联网
|
|
|
- zygote(Zygote.Project)
|
|
|
+ nav.navigate(Zygote.Project) {
|
|
|
+ popUpTo(Zygote.Flash) {
|
|
|
+ inclusive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- else -> { // 未登录 && 未联网
|
|
|
+ else -> { // 登录 && 联网
|
|
|
val token = sp.getString(Token, "")
|
|
|
- if (token == "")
|
|
|
- zygote(Zygote.Login)
|
|
|
- else
|
|
|
+ if (token == "") {
|
|
|
+ nav.navigate(Zygote.Login) {
|
|
|
+ popUpTo(Zygote.Flash) {
|
|
|
+ inclusive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
vm.getAccount(
|
|
|
success = {
|
|
|
- zygote(Zygote.Project)
|
|
|
+ nav.navigate(Zygote.Project) {
|
|
|
+ popUpTo(Zygote.Flash) {
|
|
|
+ inclusive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
failure = {
|
|
|
- zygote(Zygote.Login)
|
|
|
- Log.d("failure", it)
|
|
|
+ nav.navigate(Zygote.Login) {
|
|
|
+ popUpTo(Zygote.Flash) {
|
|
|
+ inclusive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -82,5 +102,5 @@ fun FlashScreen(block: (Zygote) -> Unit) {
|
|
|
@Preview
|
|
|
@Composable
|
|
|
fun PreviewFlashScreen() {
|
|
|
- FlashScreen(block = { })
|
|
|
+ Flash()
|
|
|
}
|