From a5d862051462a5fcc2717b405896a6d424002e54 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 22 十二月 2020 15:43:06 +0800
Subject: [PATCH] 1. 调整了数控实体的存储位置; 2. 新增数据表“媒体文件类型别名表”; 3. 修改任意拍模块,将图片分类改为根据场景类型动态生成,同时新增修改分类别名功能; 4. 优化子任务选择界面的任务排序方式,按照“待开始”、“执行中”、“未执行”的顺序进行排序;

---
 app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt |  122 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 107 insertions(+), 15 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt
index 8d93bcd..323d502 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt
@@ -1,12 +1,17 @@
 package cn.flightfeather.thirdapp.module.inspection
 
 import android.arch.lifecycle.MutableLiveData
-import cn.flightfeather.thirdapp.bean.Mediafile
+import cn.flightfeather.thirdapp.bean.entity.Mediafile
 import cn.flightfeather.thirdapp.common.net.ResultCallBack
 import cn.flightfeather.thirdapp.model.enumreation.MediaFileType
+import cn.flightfeather.thirdapp.model.enumreation.SceneType
 import cn.flightfeather.thirdapp.module.base.BaseViewModel
+import cn.flightfeather.thirdapp.repository.CommonRepository
 import cn.flightfeather.thirdapp.repository.InspectionRepository
 import cn.flightfeather.thirdapp.repository.ProblemRepository
+import org.jetbrains.anko.collections.forEachByIndex
+import org.jetbrains.anko.collections.forEachWithIndex
+import org.jetbrains.anko.toast
 
 /**
  * @author riku
@@ -14,8 +19,15 @@
  */
 class MenuCameraViewModel : BaseViewModel() {
 
+    class MediaData {
+        var type: MediaFileType? = null
+        var alias: String? = null
+        var dataList = ArrayList<Mediafile>()
+    }
+
     private val inspectionRepository = InspectionRepository()
     private val problemRepository = ProblemRepository()
+    private val commonRepository = CommonRepository()
 
     //甯歌璁板綍鍥剧墖
     val routineRecordList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
@@ -23,6 +35,9 @@
     val nameplateList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
     //鐩戞祴璁惧鍥剧墖
     val monitorDeviceList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
+
+    val fileList = MutableLiveData<MutableList<MediaData>>().apply { value = mutableListOf() }
+    private var loadedCount = 0
 
     private val dataSet = listOf(
             Pair(MediaFileType.RoutineRecord, routineRecordList),
@@ -33,25 +48,48 @@
     /**
      * 鑾峰彇浠绘剰鎷嶇収鍥剧墖
      */
-    fun getMediaFile(inspectionId: String) {
-        dataSet.forEach {p ->
-            inspectionRepository.getMediaFile(inspectionId, p.first.value, object : ResultCallBack<ArrayList<Mediafile>> {
-                override fun onSuccess(result: ArrayList<Mediafile>?) {
-                    result?.let {
-                        p.second.value?.run {
-                            clear()
-                            add(0, Mediafile())//鍦ㄥ垪琛ㄥご娣诲姞鍥剧墖鎷嶆憚鎸夐挳
-                            addAll(it)
+    fun getMediaFile(inspectionId: String, sceneTypeId: Int) {
+        commonRepository.getMediaFileTypes(sceneTypeId, object : ResultCallBack<List<MediaFileType>> {
+            override fun onSuccess(types: List<MediaFileType>?) {
+                fileList.value?.clear()
+                loadedCount = 0
+                types?.forEachWithIndex { i, type ->
+                    inspectionRepository.getMediaFile(inspectionId, type.value, object : ResultCallBack<ArrayList<Mediafile>> {
+                        override fun onSuccess(result: ArrayList<Mediafile>?) {
+                            commonRepository.getAlias(sceneTypeId, type, object : ResultCallBack<String> {
+                                override fun onSuccess(alias: String?) {
+                                    result?.let {
+                                        fileList.value?.add(MediaData().apply {
+                                            this.type = type
+                                            this.alias = if (alias.isNullOrBlank()) null else alias
+                                            dataList = it
+                                            dataList.add(0, Mediafile())
+                                        })
+                                        onMediaFileGet(types.size, sceneTypeId)
+                                    }
+                                }
+
+                                override fun onFailure() {
+                                }
+                            })
                         }
-                        p.second.value = p.second.value
-                    }
+
+                        override fun onFailure() {
+
+                        }
+
+                    })
                 }
+            }
 
-                override fun onFailure() {
+            override fun onFailure() {
 
-                }
+            }
+        })
 
-            })
+
+        dataSet.forEach { p ->
+
         }
     }
 
@@ -70,4 +108,58 @@
 
         })
     }
+
+    fun updateAlias(sceneTypeId: Int, mediaFileType: MediaFileType, alias: String, s: (s: String) -> Unit) {
+        commonRepository.updateAlias(sceneTypeId, mediaFileType, alias, object : ResultCallBack<Boolean> {
+            override fun onSuccess(result: Boolean?) {
+                application.toast("淇敼鎴愬姛")
+                s(alias)
+            }
+
+            override fun onFailure() {
+                application.toast("淇敼澶辫触")
+            }
+        })
+    }
+
+    private fun onMediaFileGet(total: Int, sceneTypeId: Int) {
+        loadedCount++
+        if (loadedCount == total) {
+            val list = fileList.value?.sortedBy {
+                it.type?.value
+            }?.toMutableList() ?: mutableListOf()
+            if (sceneTypeId == SceneType.Construction.value
+                    || sceneTypeId == SceneType.Wharf.value
+                    || sceneTypeId == SceneType.MixingPlant.value
+                    || sceneTypeId == SceneType.StorageYard.value) {
+                fileList.value?.clear()
+                for (i in list.indices) {
+                    if (list[i].type == MediaFileType.RoutineRecord) {
+                        fileList.value?.add(list[i])
+                        list.removeAt(i)
+                        break
+                    }
+                }
+                for (i in list.indices) {
+                    if (list[i].type == MediaFileType.MonitorDevice) {
+                        fileList.value?.add(list[i])
+                        list.removeAt(i)
+                        break
+                    }
+                }
+                for (i in list.indices) {
+                    if (list[i].type == MediaFileType.Nameplate) {
+                        fileList.value?.add(list[i])
+                        list.removeAt(i)
+                        break
+                    }
+                }
+                fileList.value?.addAll(list)
+                fileList.value = fileList.value
+            } else {
+                fileList.value = list
+            }
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3