|
@@ -1,9 +1,14 @@
|
|
|
package com.ys.bdtp.adm.mvvm.ui.screen.project
|
|
|
|
|
|
+import android.content.SharedPreferences
|
|
|
import android.net.ConnectivityManager
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
|
import androidx.compose.foundation.background
|
|
|
-import androidx.compose.foundation.layout.*
|
|
|
+import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
+import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.layout.wrapContentWidth
|
|
|
import androidx.compose.runtime.*
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
@@ -11,12 +16,9 @@ import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
import androidx.lifecycle.flowWithLifecycle
|
|
|
-import com.ys.bdtp.adm.app.tools.isNet
|
|
|
+import com.ys.bdtp.adm.app.Password
|
|
|
import com.ys.bdtp.adm.app.theme.underColor
|
|
|
-import com.ys.bdtp.adm.mvvm.model.nt.FailureResponse
|
|
|
-import com.ys.bdtp.adm.mvvm.model.nt.SuccessResponse
|
|
|
-import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
|
|
|
-import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
|
|
|
+import com.ys.bdtp.adm.app.tools.isNet
|
|
|
import com.ys.bdtp.adm.mvvm.ui.compose.*
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.Route
|
|
@@ -34,54 +36,24 @@ fun Project() {
|
|
|
val nav = LocalNavHostController.current!!
|
|
|
val vm by rememberViewModel<ProjectViewModel>()
|
|
|
val cm by rememberInstance<ConnectivityManager>()
|
|
|
+ val sp by rememberInstance<SharedPreferences>()
|
|
|
val scope = rememberCoroutineScope()
|
|
|
- // var user by remember { mutableStateOf<UserEntity?>(null) }
|
|
|
- var projects by remember { mutableStateOf<List<ProjectEntity>>(emptyList()) }
|
|
|
var popupState by remember { mutableStateOf(false) }
|
|
|
|
|
|
val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
- /*val userFlow = vm.userFlow
|
|
|
- val userFlowLifecycleAware = remember(vm.userFlow, lifecycleOwner) {
|
|
|
- userFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
+ val userFlowLifecycleAware = remember(vm.userWithsProjects, lifecycleOwner) {
|
|
|
+ vm.userWithsProjects.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
}
|
|
|
|
|
|
- val user by userFlowLifecycleAware.collectAsState(null, scope.coroutineContext)*/
|
|
|
- val user by vm.userFlow.collectAsState()
|
|
|
+ val userWithsProjects = userFlowLifecycleAware.collectAsState(null)
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
- // isNet 联网,进行网络通信,获取账号信息也判断 token是否能用
|
|
|
+ // isNet 联网,token 进行网络通信, 发起请求, 更新数据.
|
|
|
if (isNet(cm)) {
|
|
|
- when (val response = vm.getAccount()) {
|
|
|
- is SuccessResponse -> {
|
|
|
- val account = response.data
|
|
|
- vm.setCurrentAccount(account)
|
|
|
- val up = vm.getUserWithProjectsById(account.id)
|
|
|
-
|
|
|
- projects = up.projects
|
|
|
- }
|
|
|
-
|
|
|
- is FailureResponse -> {
|
|
|
- val fail = response.fail
|
|
|
- if (fail.code == "catch") {
|
|
|
- // 提示网络问题
|
|
|
- } else {
|
|
|
- // 根据不同 code 进行不同操作
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 离线暂时有问题
|
|
|
- val u = vm.currentUser()
|
|
|
- if (u == null) {
|
|
|
- nav.navigate(Route.Login) {
|
|
|
- popUpTo(Route.Project) {
|
|
|
- inclusive = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- val up = vm.getUserWithProjectsById(u.id)
|
|
|
- //user = up.user
|
|
|
- projects = up.projects
|
|
|
+ val password = sp.getString(Password, "") ?: ""
|
|
|
+ vm.requestAccount(password) { fail ->
|
|
|
+ // 不同 code 进行不同操作
|
|
|
+ Log.d("Project", "Project requestAccount fail :${fail}")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -89,8 +61,6 @@ fun Project() {
|
|
|
Column(
|
|
|
modifier = Modifier.fillMaxSize()
|
|
|
) {
|
|
|
- println("user:::::: $user ")
|
|
|
- println("user:::::: $user ")
|
|
|
Head(
|
|
|
left = {
|
|
|
ProjectHeadLeft()
|
|
@@ -129,11 +99,11 @@ fun Project() {
|
|
|
.background(underColor)
|
|
|
.padding(horizontal = 32.dp, vertical = 40.dp)
|
|
|
) {
|
|
|
- if (projects.isEmpty())
|
|
|
+ val projects = userWithsProjects.value?.projects
|
|
|
+ if (projects.isNullOrEmpty())
|
|
|
Blank()
|
|
|
else
|
|
|
ProjectContent(projects)
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|