|
@@ -2,7 +2,6 @@ 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.Column
|
|
@@ -16,12 +15,13 @@ 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.Password
|
|
|
import com.ys.bdtp.adm.app.theme.underColor
|
|
|
import com.ys.bdtp.adm.app.tools.isNet
|
|
|
+import com.ys.bdtp.adm.mvvm.model.Data
|
|
|
+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
|
|
|
-import com.ys.bdtp.adm.mvvm.ui.screen.main.Route
|
|
|
+import com.ys.bdtp.adm.mvvm.ui.screen.main.projectToLogin
|
|
|
import com.ys.bdtp.adm.mvvm.vm.project.ProjectViewModel
|
|
|
import kotlinx.coroutines.launch
|
|
|
import org.kodein.di.compose.rememberInstance
|
|
@@ -45,16 +45,16 @@ fun Project() {
|
|
|
vm.userWithsProjects.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
}
|
|
|
|
|
|
- val userWithsProjects = userFlowLifecycleAware.collectAsState(null)
|
|
|
+ val dataState = userFlowLifecycleAware.collectAsState(Data.loading())
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
// isNet 联网,token 进行网络通信, 发起请求, 更新数据.
|
|
|
if (isNet(cm)) {
|
|
|
- val password = sp.getString(Password, "") ?: ""
|
|
|
+ /*val password = sp.getString(Password, "") ?: ""
|
|
|
vm.requestAccount(password) { fail ->
|
|
|
// 不同 code 进行不同操作
|
|
|
Log.d("Project", "Project requestAccount fail :${fail}")
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -82,11 +82,6 @@ fun Project() {
|
|
|
vm.logout()
|
|
|
}
|
|
|
popupState = false
|
|
|
- nav.navigate(Route.Login) {
|
|
|
- popUpTo(Route.Project) {
|
|
|
- inclusive = true
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
)
|
|
|
}
|
|
@@ -99,11 +94,25 @@ fun Project() {
|
|
|
.background(underColor)
|
|
|
.padding(horizontal = 32.dp, vertical = 40.dp)
|
|
|
) {
|
|
|
- val projects = userWithsProjects.value?.projects
|
|
|
- if (projects.isNullOrEmpty())
|
|
|
- Blank()
|
|
|
- else
|
|
|
- ProjectContent(projects)
|
|
|
+ val userWithProjects = dataState.value
|
|
|
+ when (userWithProjects.state) {
|
|
|
+ is State.Loading -> {
|
|
|
+ // TODO 给与加载提示
|
|
|
+ }
|
|
|
+ is State.Success -> {
|
|
|
+ val uwp = userWithProjects.data
|
|
|
+ if (uwp == null) {
|
|
|
+ nav.projectToLogin()
|
|
|
+ } else if (uwp.projects.isEmpty()) {
|
|
|
+ Blank()
|
|
|
+ } else {
|
|
|
+ ProjectContent(uwp.projects)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is State.Failure -> {
|
|
|
+ // TODO 给与失败提示
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|