Browse Source

@fun: main

bai 3 years ago
parent
commit
de7f73144b

+ 3 - 3
app/src/main/java/com/ys/bdtp/adm/App.kt

@@ -9,8 +9,7 @@ import androidx.compose.ui.platform.LocalContext
 import com.google.accompanist.insets.ProvideWindowInsets
 import com.google.accompanist.systemuicontroller.rememberSystemUiController
 import com.ys.bdtp.adm.app.theme.AdmTheme
-import com.ys.bdtp.adm.mvvm.ui.screen.login.LoginScreen
-import com.ys.bdtp.adm.mvvm.ui.screen.main.MainScreen
+import com.ys.bdtp.adm.mvvm.ui.screen.main.Main
 import org.kodein.di.compose.onDIContext
 
 @Composable
@@ -33,7 +32,8 @@ fun App() = onDIContext(LocalContext.current) {
                     )
                 }
                 //LoginScreen()
-                MainScreen()
+                //MainScreen()
+                Main()
             }
         }
     }

+ 35 - 15
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/flash/FlashScreen.kt

@@ -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()
 }

+ 0 - 29
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/Login.kt

@@ -1,29 +0,0 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.login
-
-import android.annotation.SuppressLint
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.runtime.compositionLocalOf
-import androidx.navigation.NavHostController
-import androidx.navigation.compose.NavHost
-import androidx.navigation.compose.composable
-import androidx.navigation.compose.rememberNavController
-import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
-
-@SuppressLint("CompositionLocalNaming")
-val LoginNavHostController = compositionLocalOf<NavHostController?> { null }
-
-@Composable
-fun Login() {
-    val navController: NavHostController = rememberNavController()
-    CompositionLocalProvider(LoginNavHostController provides navController) {
-        NavHost(navController = navController, startDestination = "login") {
-            composable("login") {
-                LoginScreen()
-            }
-            composable("project") {
-                ProjectScreen()
-            }
-        }
-    }
-}

+ 7 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginContent.kt

@@ -24,6 +24,8 @@ import com.ys.bdtp.adm.app.theme.grayColor
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.mvvm.model.vo.request.Login
 import com.ys.bdtp.adm.mvvm.ui.compose.Alert
+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.login.LoginViewModel
 import kotlinx.coroutines.launch
 import org.kodein.di.compose.rememberInstance
@@ -48,7 +50,7 @@ fun LoginContent() {
     val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
     val scope = rememberCoroutineScope()
 
-    val nav = LoginNavHostController.current!!
+    val nav = LocalNavHostController.current!!
 
     Column(
         modifier = Modifier.fillMaxSize()
@@ -199,8 +201,10 @@ fun LoginContent() {
                     ),
                     success = { token ->
                         sp.edit { putString(Token, token) }
-                        nav.navigate("project") {
-                            popUpTo("login") { inclusive = true }
+                        nav.navigate(Zygote.Project) {
+                            popUpTo(Zygote.Login) {
+                                inclusive = true
+                            }
                         }
                     },
                     failure = { message ->

+ 42 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/Main.kt

@@ -0,0 +1,42 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.main
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.compositionLocalOf
+import androidx.navigation.NavHostController
+import androidx.navigation.compose.NavHost
+import androidx.navigation.compose.composable
+import androidx.navigation.compose.rememberNavController
+import com.ys.bdtp.adm.mvvm.ui.screen.flash.Flash
+import com.ys.bdtp.adm.mvvm.ui.screen.login.LoginScreen
+import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
+
+
+
+object Zygote {
+    const val Flash = "flash"
+    const val Login = "login"
+    const val Project = "project"
+    const val Task = "task"
+}
+
+val LocalNavHostController = compositionLocalOf<NavHostController?> { null }
+
+@Composable
+fun Main() {
+    val navController = rememberNavController()
+    CompositionLocalProvider(LocalNavHostController provides navController) {
+        NavHost(navController = navController, startDestination = Zygote.Flash) {
+            composable(Zygote.Flash) {
+                Flash()
+            }
+            composable(Zygote.Login) {
+                LoginScreen()
+            }
+            composable(Zygote.Project) {
+                ProjectScreen()
+            }
+        }
+
+    }
+}

+ 0 - 35
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/MainScreen.kt

@@ -1,35 +0,0 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.main
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.setValue
-import com.ys.bdtp.adm.mvvm.ui.screen.flash.FlashScreen
-import com.ys.bdtp.adm.mvvm.ui.screen.login.Login
-import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
-
-sealed interface Zygote {
-    object Flash : Zygote
-    object Login : Zygote
-    object Project : Zygote
-}
-
-@Composable
-fun MainScreen() {
-    var state by remember { mutableStateOf<Zygote>(Zygote.Flash) }
-    when (state) {
-        Zygote.Flash -> {
-            FlashScreen(
-                block = { new ->
-                    state = new
-                })
-        }
-        Zygote.Login -> {
-            Login()
-        }
-        Zygote.Project -> {
-            ProjectScreen()
-        }
-    }
-}

+ 9 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/Project.kt

@@ -0,0 +1,9 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.project
+
+import androidx.compose.runtime.Composable
+
+
+@Composable
+fun Project() {
+
+}

+ 0 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectHeadLeft.kt

@@ -19,7 +19,6 @@ fun ProjectHeadLeft() {
         verticalAlignment = Alignment.CenterVertically,
         horizontalArrangement = Arrangement.Start
     ) {
-
         Spacer(modifier = Modifier.width(32.dp))
         Text(text = "禹数数字化交付工具", fontSize = 16.sp, color = textBlackColor)
     }

+ 6 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectItem.kt

@@ -2,6 +2,7 @@ package com.ys.bdtp.adm.mvvm.ui.screen.project
 
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.Image
+import androidx.compose.foundation.clickable
 import androidx.compose.foundation.layout.*
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material.Card
@@ -29,7 +30,11 @@ fun ProjectItem(project: ProjectEntity) {
         elevation = 0.dp
     ) {
         Row(
-            modifier = Modifier.padding(20.dp),
+            modifier = Modifier
+                .clickable {
+
+                }
+                .padding(20.dp),
             verticalAlignment = Alignment.CenterVertically
         ) {
 

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectScreen.kt

@@ -44,7 +44,7 @@ fun ProjectScreen() {
                     }
 
                     is FailureResponse -> {
-                        // 纯联网问题
+
                     }
                 }
             }

+ 3 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskScreen.kt

@@ -32,7 +32,9 @@ fun TaskScreen(project: ProjectEntity) {
             left = {
                 TaskHeadLeft(
                     title = project.projectName,
-                    click = {})
+                    click = {
+
+                    })
             },
             right = {
                 HeadRight(