Browse Source

@task: Modify Basic URL

bai 3 years ago
parent
commit
f7b4c212f5

+ 1 - 1
demo/src/main/java/com/framework/app/Constants.kt

@@ -9,7 +9,7 @@ const val test2IP = "http://192.168.0.11:8876/"
 
 const val tencentIP = "http://82.157.28.170:8876/"
 
-const val JdIP = "http://82.157.151.123/adm-poc-backend/"
+const val JdIP = "http://www.ysbdtp.com/adm-poc-backend/"
 
 const val IP = JdIP
 

+ 2 - 2
demo/src/main/java/com/framework/app/api/Api.kt

@@ -87,13 +87,13 @@ interface Api {
     /**
      * 登录
      */
-    @POST("http://82.157.151.123/login-service")
+    @POST("http://www.ysbdtp.com/login-service")
     suspend fun login(@Query("jsonString") json: String): Model<List<User>>
 
     /**
      * 获取项目
      */
-    @POST("http://82.157.151.123/getUserById")
+    @POST("http://www.ysbdtp.com/getUserById")
     suspend fun getProjects(@Query("jsonString") json: String): Model<List<User>>
 
 }

+ 10 - 0
demo/src/main/java/com/framework/di/Di.kt

@@ -8,15 +8,25 @@ import com.framework.app.http.GzipRequestInterceptor
 import com.framework.mvvm.model.db.AdmDatabase
 import com.framework.mvvm.model.repository.AdmRepository
 import com.framework.mvvm.mv.AdmViewModel
+import com.sybotan.android.demo.DemoApp
 import com.sybotan.android.demo.tools.LogUtil
 import okhttp3.OkHttpClient
 import okhttp3.logging.HttpLoggingInterceptor
 import org.kodein.di.*
+import org.kodein.di.android.x.androidXModule
 import retrofit2.Retrofit
 import retrofit2.converter.gson.GsonConverterFactory
 import java.io.UnsupportedEncodingException
 import java.util.concurrent.TimeUnit
 
+fun di(context: Context) = DI {
+    import(androidXModule(context.applicationContext as DemoApp))
+    import(databaseModule)
+    import(httpModule)
+    import(repositoryModule)
+    import(viewModelModule)
+    import(androidModule)
+}
 
 val httpModule = DI.Module("netModule") {
     // 构建 Retrofit 对象

+ 18 - 13
demo/src/main/java/com/framework/mvvm/ui/AdmApp.kt

@@ -3,31 +3,36 @@ package com.framework.mvvm.ui
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.CompositionLocalProvider
 import androidx.compose.runtime.compositionLocalOf
+import androidx.compose.ui.platform.LocalContext
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
 import androidx.navigation.compose.rememberNavController
+import com.framework.di.di
 import com.framework.mvvm.ui.screen.FlashScreen
 import com.framework.mvvm.ui.screen.LoginScreen
 import com.framework.mvvm.ui.screen.ProjectScreen
+import org.kodein.di.compose.onDIContext
+import org.kodein.di.compose.withDI
 
 val LocalNavHostController = compositionLocalOf<NavHostController?> { null }
 
 @Composable
-fun AdmApp() {
-    val navController: NavHostController = rememberNavController()
-    CompositionLocalProvider(LocalNavHostController provides navController) {
-        NavHost(navController = navController, startDestination = "flash") {
-            composable("flash") {
-                FlashScreen()
-            }
-            composable("login") {
-                LoginScreen()
-            }
-            composable("project") {
-                ProjectScreen()
+fun AdmApp() = withDI(di(LocalContext.current)) {
+    onDIContext(LocalContext.current) {
+        val navController: NavHostController = rememberNavController()
+        CompositionLocalProvider(LocalNavHostController provides navController) {
+            NavHost(navController = navController, startDestination = "flash") {
+                composable("flash") {
+                    FlashScreen()
+                }
+                composable("login") {
+                    LoginScreen()
+                }
+                composable("project") {
+                    ProjectScreen()
+                }
             }
         }
     }
-
 }

+ 2 - 4
demo/src/main/java/com/framework/mvvm/ui/screen/FlashScreen.kt

@@ -15,13 +15,11 @@ import androidx.constraintlayout.compose.ConstraintSet
 import com.framework.mvvm.mv.AdmViewModel
 import com.framework.mvvm.ui.LocalNavHostController
 import kotlinx.coroutines.delay
-import org.kodein.di.compose.localDI
-import org.kodein.di.instance
+import org.kodein.di.compose.rememberInstance
 
 @Composable
 fun FlashScreen() {
-    val di = localDI()
-    val vm by di.instance<AdmViewModel>()
+    val vm by rememberInstance<AdmViewModel>()
     val nav = LocalNavHostController.current!!
 
     BoxWithConstraints(

+ 0 - 1
demo/src/main/java/com/framework/mvvm/ui/screen/ProjectScreen.kt

@@ -27,7 +27,6 @@ fun ProjectScreen() {
     val di = localDI()
     val vm by di.instance<AdmViewModel>()
     val context = LocalContext.current
-
     var projects by remember { mutableStateOf<List<ProjectEntity>>(emptyList()) }
     var user by remember { mutableStateOf<UserEntity?>(null) }