4 次代码提交 555ca78190 ... a0cb1f6297

作者 SHA1 备注 提交日期
  bai a0cb1f6297 @fun: ProjectContent 2 年之前
  bai e63c618188 @fun: add is_record_origin 2 年之前
  bai 8fff452fba @fun: update Compose and Project 2 年之前
  bai 1f7b2812fa @fun: Login 2 年之前

+ 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)
 

+ 13 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/config/ProblemInfoConfigEntity.kt

@@ -8,6 +8,18 @@ import androidx.room.PrimaryKey
  * 问题信息表
  *
  * @author bai
+ *
+ * @param id
+ * @param code 信息点编码
+ * @param name 信息点名称
+ * @param dataSource 数据源取值范围(枚举等),根据dataType的不同而不同
+ * @param dataType 数据类型
+ * @param isMultiple 是否复数,1 是,0 否
+ * @param isRecordOrigin 是否记录原值,1 记录,0 不记
+ * @param unit 单位
+ * @param valid 合法标识
+ * @param ts 时间戳
+ *
  */
 @Entity(tableName = "problem_info_config")
 data class ProblemInfoConfigEntity(
@@ -18,6 +30,7 @@ data class ProblemInfoConfigEntity(
     @ColumnInfo(name = "data_type") val dataType: String? = "",
     @ColumnInfo(name = "is_multiple") val isMultiple: Int = -1,
     @ColumnInfo(name = "problem_type_code") val problemTypeCode: String? = "",
+    @ColumnInfo(name = "is_record_origin") var isRecordOrigin: Int = 0,
     @ColumnInfo(name = "unit") val unit: String? = "",
     @ColumnInfo(name = "valid") val valid: Int = -1,
     @ColumnInfo(name = "ts") val ts: String? = ""

+ 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
+        )
+    }
+}

+ 38 - 36
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Login.kt

@@ -43,22 +43,33 @@ fun Login() {
     var password by remember { mutableStateOf("123456") }
     var visualState: VisualTransformation by remember { mutableStateOf(PasswordVisualTransformation()) }
 
-    var usernameLeadingIconColor by remember { mutableStateOf(Color(0xFFC3C7CB)) }
-    var passwordLeadingIconColor by remember { mutableStateOf(Color(0xFFC3C7CB)) }
+    var usernameLeadingIconColor by remember { mutableStateOf(grayColor) }
+    var passwordLeadingIconColor by remember { mutableStateOf(grayColor) }
 
     val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
     val scope = rememberCoroutineScope()
 
     val nav = LocalNavHostController.current!!
 
+    val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
+        textColor = textBlackColor,
+        cursorColor = blueColor,
+        focusedBorderColor = blueColor,
+        unfocusedBorderColor = grayColor,
+        focusedLabelColor = blueColor,
+        unfocusedLabelColor = grayColor,
+        backgroundColor = Color.Transparent
+    )
+
     OutlinedTextField(
         value = username,
-        modifier = Modifier.fillMaxWidth().onFocusChanged { focusState: FocusState ->
-            usernameLeadingIconColor = if (focusState.isFocused)
-                blueColor
-            else
-                grayColor
-        },
+        modifier = Modifier.fillMaxWidth()
+            .onFocusChanged { focusState: FocusState ->
+                usernameLeadingIconColor = if (focusState.isFocused)
+                    blueColor
+                else
+                    grayColor
+            },
         onValueChange = {
             username = it
             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
@@ -66,15 +77,7 @@ fun Login() {
         label = {
             Text(text = "请输入账号")
         },
-        colors = TextFieldDefaults.outlinedTextFieldColors(
-            textColor = textBlackColor,
-            cursorColor = blueColor,
-            focusedBorderColor = blueColor,
-            unfocusedBorderColor = grayColor,
-            focusedLabelColor = blueColor,
-            unfocusedLabelColor = grayColor,
-            backgroundColor = Color.Transparent
-        ),
+        colors = textFieldColors,
         leadingIcon = {
             Icon(
                 painter = painterResource(R.drawable.login_user),
@@ -90,6 +93,7 @@ fun Login() {
                         isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
                     },
                     enabled = username.isNotEmpty(),
+                    modifier = Modifier.size(32.dp)
                 ) {
                     Icon(
                         painter = painterResource(R.drawable.login_delete),
@@ -119,15 +123,7 @@ fun Login() {
             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
         },
         label = { Text(text = "请输入密码") },
-        colors = TextFieldDefaults.outlinedTextFieldColors(
-            textColor = textBlackColor,
-            cursorColor = blueColor,
-            focusedBorderColor = blueColor,
-            unfocusedBorderColor = grayColor,
-            focusedLabelColor = blueColor,
-            unfocusedLabelColor = grayColor,
-            backgroundColor = Color.Transparent
-        ),
+        colors = textFieldColors,
         visualTransformation = visualState,
         leadingIcon = {
             Icon(
@@ -138,12 +134,12 @@ fun Login() {
         },
         trailingIcon = {
             Row(
-                horizontalArrangement = Arrangement.End,
                 verticalAlignment = Alignment.CenterVertically
             ) {
                 if (password.isNotBlank()) {
                     IconButton(
-                        onClick = { isShowPassword = !isShowPassword }
+                        onClick = { isShowPassword = !isShowPassword },
+                        modifier = Modifier.size(32.dp)
                     ) {
                         val icon =
                             if (isShowPassword) R.drawable.login_eye_open else R.drawable.login_eye_close
@@ -153,33 +149,33 @@ fun Login() {
                         Icon(
                             painter = painterResource(icon),
                             contentDescription = description,
-                            modifier = Modifier.size(18.dp).padding(0.dp),
+                            modifier = Modifier.size(16.dp),
                             tint = grayColor
                         )
                     }
-
                     IconButton(
                         onClick = {
                             password = ""
                             isShowPassword = false
                             isLoginBtnEnable = username.isNotEmpty() && password.isNotEmpty()
                         },
-                        enabled = password.isNotEmpty()
+                        enabled = password.isNotEmpty(),
+                        modifier = Modifier.size(32.dp)
                     ) {
                         Icon(
                             painter = painterResource(R.drawable.login_delete),
                             contentDescription = "",
-                            modifier = Modifier.size(18.dp),
+                            modifier = Modifier.size(16.dp),
                             tint = grayColor
                         )
                     }
+                    Spacer(modifier = Modifier.width(8.dp))
                 }
             }
         }
     )
 
-
-    Spacer(modifier = Modifier.height(32.dp))
+    Spacer(modifier = Modifier.height(40.dp))
 
     Button(
         onClick = {
@@ -215,7 +211,14 @@ fun Login() {
         },
         enabled = isLoginBtnEnable,
         modifier = Modifier.fillMaxWidth().height(48.dp),
-        shape = RoundedCornerShape(4),
+        shape = RoundedCornerShape(8),
+        elevation = ButtonDefaults.elevation(
+            defaultElevation = 0.dp,
+            pressedElevation = 0.dp,
+            disabledElevation = 0.dp,
+            hoveredElevation = 0.dp,
+            focusedElevation = 0.dp
+        ),
         colors = ButtonDefaults.buttonColors(
             backgroundColor = Color(0xFF0091FF),
             disabledBackgroundColor = Color(0xFFEFF0F1)
@@ -229,7 +232,6 @@ fun Login() {
     }
 
     Spacer(modifier = Modifier.fillMaxWidth().height(24.dp))
-
     SnackbarHost(
         hostState = snackbarHostState
     ) { data ->

+ 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 -> {}
             }
         }
     }

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

@@ -20,7 +20,12 @@ import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
 @Composable
 fun ProjectContent(projects: List<ProjectEntity>) {
     Column {
-        Text(text = "可进入的项目(${projects.size})", fontSize = 18.sp, fontWeight = FontWeight.Bold, color = textBlackColor)
+        Text(
+            text = "可进入的项目(${projects.size})",
+            color = textBlackColor,
+            fontSize = 18.sp,
+            fontWeight = FontWeight.Medium
+        )
         Spacer(modifier = Modifier.height(14.dp))
         LazyVerticalGrid(
             cells = GridCells.Fixed(2),

+ 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"