| | |
| | | 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 |
| | |
| | | */ |
| | | 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() } |
| | |
| | | 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), |
| | |
| | | /** |
| | | * 获取任意拍照图片 |
| | | */ |
| | | 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 -> |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | }) |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |