浏览代码

@task: request floor map

bai 3 年之前
父节点
当前提交
d1993ad080

+ 22 - 21
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -45,9 +45,8 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         }
     }
 
-    /**
-     * 请求建筑数据
-     */
+   /* 请求建筑数据
+
     fun requestBuilding(request: AdmRequest, block: ((Building) -> Unit)? = null) {
         viewModelScope.launch(Dispatchers.IO) {
             repository.requestBuilding(request, block)
@@ -70,7 +69,7 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
 
             println("floor map over !!!, floors: ${floors.size}")
         }
-    }
+    }*/
 
     /**
      * 上传建筑数据
@@ -109,27 +108,29 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
                     sp.edit { putString(it.buildingId, it.timestamp) }
                 }
             }
+
+            // 下载地图
+            val floors = repository.getFloors()
+            floors.forEach {
+                val strInfo = it.strInfos
+                if (!strInfo.isNullOrEmpty()) {
+                    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")
+                    }
+                }
+            }
+
             withContext(Dispatchers.Main) {
                 block?.invoke()
             }
         }
-        /*val buildings = mVm.getBuildings()
-        println("download buildings: ${buildings.size} $buildings")
-        for (building in buildings) {
-            mVm.requestBuilding(
-                AdmRequest(
-                    userId = "bdtp",
-                    projectId = building.projectId,
-                    groupCode = "BR",
-                    buildingId = building.id,
-                    uploadFlag = sp.getString(deviceId, "") ?: "",
-                    lastDownloadTime = sp.getString(timestamp, "") ?: ""
-                )
-            ) {
-                println("buildingIdTimestamp  -> ${it.buildingId}, ${it.timestamp}")
-                sp.edit { putString(it.buildingId, it.timestamp) }
-            }
-        }*/
     }
 
     /**

+ 2 - 1
demo/src/main/java/com/sybotan/android/demo/activities/PocActivity.kt

@@ -44,9 +44,10 @@ class PocActivity : AppCompatActivity(), DIAware {
         LocalDataOperation.getInstance().offlineSendRequest.uploadImageNew(this)
         downloadBtn = findViewById(R.id.downloadBtn)
         uploadBtn = findViewById(R.id.uploadBtn)
+
         downloadBtn.setOnClickListener {
             mVm.downloadBuilding(sp) {
-                ToastUtils.showMyToast("下载建筑数据")
+                ToastUtils.showMyToast("下载建筑数据完成")
             }
         }