From 979d9cff22806f213b420452ab4a68fcbaf021b6 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 31 五月 2021 17:43:49 +0800
Subject: [PATCH] 1. 修复多项可能引起空指针崩溃的bug; 2. 新建子任务时默认执行人员从全体人员改为当前用户; 3. 新建子任务时默认执行时间强制固定为总任务对应的时段内,确保子任务执行时间不会超出总任务范围。
---
app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraViewModel.kt | 132 ++++++++++++++++++++++++++++++++++++++++----
1 files changed, 120 insertions(+), 12 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 eae0b61..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,11 +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
@@ -13,30 +19,78 @@
*/
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 mediaFileList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
+ //甯歌璁板綍鍥剧墖
+ val routineRecordList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
+ //閾墝鍥剧墖
+ 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),
+ Pair(MediaFileType.Nameplate, nameplateList),
+ Pair(MediaFileType.MonitorDevice, monitorDeviceList)
+ )
+
/**
* 鑾峰彇浠绘剰鎷嶇収鍥剧墖
*/
- fun getMediaFile(inspectionId: String) {
- inspectionRepository.getMediaFile(inspectionId, BUSINESS_TYPE_CAMERA, object : ResultCallBack<ArrayList<Mediafile>> {
- override fun onSuccess(result: ArrayList<Mediafile>?) {
- result?.let {
- mediaFileList.value?.run {
- clear()
- addAll(it)
- }
- mediaFileList.value = mediaFileList.value
+ 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() {
+ }
+ })
+ }
+
+ override fun onFailure() {
+
+ }
+
+ })
}
}
override fun onFailure() {
}
-
})
+
+
+ dataSet.forEach { p ->
+
+ }
}
/**
@@ -54,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