Przeglądaj źródła

@fun: update Compose and Project

bai 2 lat temu
rodzic
commit
8fff452fba

+ 5 - 8
app/build.gradle.kts

@@ -67,9 +67,12 @@ dependencies {
 
     // google
     implementation(Deps.Google.Material)
-    implementation(Deps.Google.Accompanist.Coil)
-    implementation(Deps.Google.Accompanist.Insets)
     implementation(Deps.Google.Gson)
+    implementation(Deps.Google.Accompanist.Insets)
+    implementation(Deps.Google.Accompanist.InsetsUI)
+    implementation(Deps.Google.Accompanist.FlowLayout)
+    implementation(Deps.Google.Accompanist.SystemUiController)
+    implementation(Deps.Google.Accompanist.SwipeRefresh)
 
     // lifecycle
     implementation(Deps.Lifecycle.Runtime)
@@ -119,12 +122,6 @@ dependencies {
     implementation(Deps.Lifecycle.Compose)
     implementation(Deps.Navigation.Compose)
 
-    // Accompanist
-    implementation(Deps.Accompanist.Insets)
-    implementation(Deps.Accompanist.InsetsUI)
-    implementation(Deps.Accompanist.FlowLayout)
-    implementation(Deps.Accompanist.SystemUiController)
-
     // Coil
     implementation(Deps.Coil.Compose)
 

+ 27 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/CircularProgress.kt

@@ -0,0 +1,27 @@
+package com.ys.bdtp.adm.mvvm.ui.compose
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.size
+import androidx.compose.material.CircularProgressIndicator
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.ys.bdtp.adm.app.theme.blueColor
+
+/**
+ * 进度条
+ */
+@Composable
+fun CircularProgress() {
+    Box(
+        modifier = Modifier.fillMaxSize(),
+        contentAlignment = Alignment.Center
+    ) {
+        CircularProgressIndicator(
+            modifier = Modifier.size(72.dp),
+            color = blueColor
+        )
+    }
+}

+ 22 - 20
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/LogoutPopup.kt

@@ -3,10 +3,10 @@ package com.ys.bdtp.adm.mvvm.ui.compose
 import androidx.compose.foundation.background
 import androidx.compose.foundation.clickable
 import androidx.compose.foundation.layout.*
-import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material.Card
 import androidx.compose.material.Icon
 import androidx.compose.material.Text
-import androidx.compose.runtime.*
+import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
@@ -36,26 +36,28 @@ fun LogoutPopup(click: () -> Unit) {
         alignment = Alignment.TopEnd,
         offset = IntOffset(-24, y),
     ) {
-        Row(
-            modifier = Modifier
-                .size(116.dp, 50.dp)
-                .background(color = whiteColor, shape = RoundedCornerShape(4.dp))
-                .clickable {
-                    click()
-                },
-            verticalAlignment = Alignment.CenterVertically,
-            horizontalArrangement = Arrangement.Center
-        ) {
-            Icon(
-                modifier = Modifier.size(16.dp),
-                painter = painterResource(R.drawable.logout),
-                contentDescription = "",
-                tint = Color(0xFF1F2429)
-            )
+        Card(elevation = 2.dp) {
+            Row(
+                modifier = Modifier
+                    .size(116.dp, 50.dp)
+                    .background(color = whiteColor)
+                    .clickable {
+                        click()
+                    },
+                verticalAlignment = Alignment.CenterVertically,
+                horizontalArrangement = Arrangement.Center
+            ) {
+                Icon(
+                    modifier = Modifier.size(16.dp),
+                    painter = painterResource(R.drawable.logout),
+                    contentDescription = "",
+                    tint = Color(0xFF1F2429)
+                )
 
-            Spacer(modifier = Modifier.width(12.dp))
+                Spacer(modifier = Modifier.width(12.dp))
 
-            Text(text = "退出登录", fontSize = 14.sp, color = textBlackColor)
+                Text(text = "退出登录", fontSize = 14.sp, color = textBlackColor)
+            }
         }
     }
 }

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

@@ -7,16 +7,13 @@ import androidx.compose.material.Text
 import androidx.compose.runtime.*
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.text.font.FontWeight
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.underColor
-import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.app.tools.lifecycleState
 import com.ys.bdtp.adm.mvvm.model.State
 import com.ys.bdtp.adm.mvvm.ui.compose.*
 import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
@@ -36,12 +33,7 @@ fun Project() {
     val scope = rememberCoroutineScope()
     var popupState by remember { mutableStateOf(false) }
 
-    val lifecycleOwner = LocalLifecycleOwner.current
-    val userFlowLifecycleAware = remember(vm.userWithsProjects, lifecycleOwner) {
-        vm.userWithsProjects.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
-    }
-
-    val dataState = userFlowLifecycleAware.collectAsState(Data.loading())
+    val userWithProjectsState = lifecycleState(vm.userWithsProjectsFlow)
 
     Column(
         modifier = Modifier.fillMaxSize()
@@ -85,28 +77,25 @@ fun Project() {
         Column(
             modifier = Modifier
                 .fillMaxSize()
-                .wrapContentWidth()
                 .background(underColor)
-                .padding(horizontal = 32.dp, vertical = 40.dp)
+                .padding(horizontal = 32.dp, vertical = 40.dp),
         ) {
-            val userWithProjects = dataState.value
+            val userWithProjects = userWithProjectsState.value
             when (userWithProjects.state) {
                 is State.Loading -> {
-                    // TODO 给与加载提示
+                    CircularProgress()
                 }
                 is State.Success -> {
-                    val uwp = userWithProjects.data
-                    if (uwp == null) {
+                    val data = userWithProjects.data
+                    if (data == null) {
                         nav.projectToLogin()
-                    } else if (uwp.projects.isEmpty()) {
+                    } else if (data.projects.isEmpty()) {
                         Blank()
                     } else {
-                        ProjectContent(uwp.projects)
+                        ProjectContent(data.projects)
                     }
                 }
-                is State.Failure -> {
-                    // TODO 给与失败提示
-                }
+                is State.Failure -> {}
             }
         }
     }

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectViewModel.kt

@@ -18,7 +18,7 @@ class ProjectViewModel(private val repo: ProjectRepository) : ViewModel() {
     /**
      * 当前用于和项目
      */
-    val userWithsProjects = repo.getUserWithProjects().stateIn(
+    val userWithsProjectsFlow = repo.getUserWithProjects().stateIn(
         scope = viewModelScope,
         started = WhileSubscribed(5000),
         initialValue = Data.loading()

+ 9 - 16
buildSrc/src/main/kotlin/Build.kt

@@ -1,6 +1,6 @@
 object Sdk {
-    const val kotlin = "1.5.31"
-    const val compose = "1.0.5"
+    const val kotlin = "1.6.10"
+    const val compose = "1.1.0"
     const val compileSdk = 31
     const val minSdk = 28
     const val targetSdk = 31
@@ -17,7 +17,7 @@ object Deps {
     }
 
     object Compose {
-        private const val compose = "1.0.5"
+        private const val compose = Sdk.compose
 
         const val Animation = "androidx.compose.animation:animation:$compose"
         const val Compiler = "androidx.compose.compiler:compiler:$compose"
@@ -62,11 +62,12 @@ object Deps {
         const val Gson = "com.google.code.gson:gson:2.8.9"
 
         object Accompanist {
-            private const val accompanist = "0.10.0"
-            const val Coil =
-                "com.google.accompanist:accompanist-coil:$accompanist"
-            const val Insets =
-                "com.google.accompanist:accompanist-insets:$accompanist"
+            private const val accompanist = "0.23.0"
+            const val Insets = "com.google.accompanist:accompanist-insets:$accompanist"
+            const val InsetsUI = "com.google.accompanist:accompanist-insets-ui:$accompanist"
+            const val SystemUiController = "com.google.accompanist:accompanist-systemuicontroller:$accompanist"
+            const val FlowLayout = "com.google.accompanist:accompanist-flowlayout:$accompanist"
+            const val SwipeRefresh = "com.google.accompanist:accompanist-swiperefresh:$accompanist"
         }
     }
 
@@ -142,14 +143,6 @@ object Deps {
         }
     }
 
-    object Accompanist {
-        private const val accompanist = "0.22.0-rc"
-        const val Insets = "com.google.accompanist:accompanist-insets:$accompanist"
-        const val InsetsUI = "com.google.accompanist:accompanist-insets-ui:$accompanist"
-        const val SystemUiController = "com.google.accompanist:accompanist-systemuicontroller:$accompanist"
-        const val FlowLayout = "com.google.accompanist:accompanist-flowlayout:$accompanist"
-    }
-
     object Coil {
         private const val coil = "1.4.0"
         const val Compose = "io.coil-kt:coil-compose:$coil"