Browse Source

@task: handle data by user

bai 3 years ago
parent
commit
3f50862f9f

+ 30 - 24
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -12,7 +12,6 @@ import com.framework.app.timestamp
 import com.framework.mvvm.model.db.entity.ObjectEntity
 import com.framework.mvvm.model.repository.AdmRepository
 import com.framework.mvvm.model.vo.AdmRequest
-import com.framework.mvvm.model.vo.Building
 import com.framework.mvvm.model.vo.FloorInfo
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
@@ -45,31 +44,38 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         }
     }
 
-   /* 请求建筑数据
+    fun requestFrameAndDict(request: AdmRequest, block: (() -> Unit)? = null) {
+        viewModelScope.launch {
+            repository.requestFrame(request)
+            repository.requestDict(request)
+            block?.invoke()
+        }
+    }
+    /* 请求建筑数据
 
-    fun requestBuilding(request: AdmRequest, block: ((Building) -> Unit)? = null) {
-        viewModelScope.launch(Dispatchers.IO) {
-            repository.requestBuilding(request, block)
-            val floors = repository.getFloors()
-            floors.forEach {
-                val strInfo = it.strInfos
-                if (!strInfo.isNullOrEmpty() && strInfo.contains("floorMap")) {
-                    try {
-                        val info = Json.decodeFromString<FloorInfo>(strInfo)
-                        val map = info.floorMap
-                        val floorMap =
-                            OkhttpUtil.getGzipMap("$IP$pathDownloadMap${map!!}")
-                        it.floorMap = floorMap
-                        repository.updateObject(it)
-                    } catch (e: Exception) {
-                        println("floor map Exception: $e")
-                    }
-                }
-            }
+     fun requestBuilding(request: AdmRequest, block: ((Building) -> Unit)? = null) {
+         viewModelScope.launch(Dispatchers.IO) {
+             repository.requestBuilding(request, block)
+             val floors = repository.getFloors()
+             floors.forEach {
+                 val strInfo = it.strInfos
+                 if (!strInfo.isNullOrEmpty() && strInfo.contains("floorMap")) {
+                     try {
+                         val info = Json.decodeFromString<FloorInfo>(strInfo)
+                         val map = info.floorMap
+                         val floorMap =
+                             OkhttpUtil.getGzipMap("$IP$pathDownloadMap${map!!}")
+                         it.floorMap = floorMap
+                         repository.updateObject(it)
+                     } catch (e: Exception) {
+                         println("floor map Exception: $e")
+                     }
+                 }
+             }
 
-            println("floor map over !!!, floors: ${floors.size}")
-        }
-    }*/
+             println("floor map over !!!, floors: ${floors.size}")
+         }
+     }*/
 
     /**
      * 上传建筑数据

+ 16 - 17
demo/src/main/java/com/sybotan/android/demo/activities/PocActivity.kt

@@ -15,8 +15,8 @@ import com.framework.mvvm.mv.AdmViewModel
 import com.sybotan.android.demo.R
 import com.sybotan.android.demo.activities.poc.SceneActivity
 import com.sybotan.android.demo.activities.poc.SpaceActivity
-import com.sybotan.android.demo.tools.ToastUtils
 import com.sybotan.android.demo.tools.LocalDataOperation
+import com.sybotan.android.demo.tools.ToastUtils
 import org.jetbrains.anko.startActivity
 import org.kodein.di.DI
 import org.kodein.di.DIAware
@@ -37,12 +37,15 @@ class PocActivity : AppCompatActivity(), DIAware {
 
     private lateinit var uploadBtn: Button
 
+    private lateinit var frontBtn: Button
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_poc)
         checkStoragePermission()
         downloadBtn = findViewById(R.id.downloadBtn)
         uploadBtn = findViewById(R.id.uploadBtn)
+        frontBtn = findViewById(R.id.frontBtn)
 
         downloadBtn.setOnClickListener {
             mVm.downloadBuilding(sp) {
@@ -57,6 +60,18 @@ class PocActivity : AppCompatActivity(), DIAware {
             }
         }
 
+        frontBtn.setOnClickListener {
+            mVm.requestFrameAndDict(
+                AdmRequest(
+                    userId = "bdtp",
+                    projectId = "Pj0002220011",
+                    groupCode = "BR"
+                )
+            ) {
+                ToastUtils.showMyToast("框架数据和数据字典下载成功")
+            }
+        }
+
         val spaceCL = findViewById<ConstraintLayout>(R.id.spaceCL)
         spaceCL.setOnClickListener {
             startActivity<SpaceActivity>()
@@ -67,22 +82,6 @@ class PocActivity : AppCompatActivity(), DIAware {
             startActivity<SceneActivity>()
         }
 
-        mVm.requestFrame(
-            AdmRequest(
-                userId = "bdtp",
-                projectId = "Pj0002220011",
-                groupCode = "BR"
-            )
-        )
-
-        mVm.requestDict(
-            AdmRequest(
-                userId = "bdtp",
-                projectId = "Pj000222001",
-                groupCode = "BR"
-            )
-        )
-
 //        mVm.requestBuilding(
 //            AdmRequest(
 //                userId = "bdtp",

+ 15 - 2
demo/src/main/res/layout/activity_poc.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
@@ -97,12 +98,12 @@
         android:id="@+id/downloadBtn"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
         android:text="下载建筑数据"
         android:textSize="18sp"
-        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toBottomOf="@+id/frontBtn" />
 
     <Button
         android:id="@+id/uploadBtn"
@@ -115,5 +116,17 @@
         app:layout_constraintStart_toStartOf="@+id/downloadBtn"
         app:layout_constraintTop_toBottomOf="@+id/downloadBtn" />
 
+    <Button
+        android:id="@+id/frontBtn"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="下载先导数据"
+        android:textSize="18sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.498"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
 
 </androidx.constraintlayout.widget.ConstraintLayout>