package cn.flightfeather.thirdappmodule.module.inspection
|
|
import android.arch.lifecycle.MutableLiveData
|
import cn.flightfeather.thirdappmodule.bean.entity.Mediafile
|
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
|
import cn.flightfeather.thirdappmodule.model.enumreation.MediaFileType
|
import cn.flightfeather.thirdappmodule.model.enumreation.SceneType
|
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
|
import cn.flightfeather.thirdappmodule.repository.CommonRepository
|
import cn.flightfeather.thirdappmodule.repository.InspectionRepository
|
import cn.flightfeather.thirdappmodule.repository.ProblemRepository
|
import org.jetbrains.anko.collections.forEachWithIndex
|
import org.jetbrains.anko.toast
|
|
/**
|
* @author riku
|
* Date: 2019/8/2
|
*/
|
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.instance
|
|
//常规记录图片
|
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
|
|
/**
|
* 获取任意拍照图片
|
*/
|
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?.forEach { t ->
|
inspectionRepository.getMediaFile(inspectionId, t.value, object : ResultCallBack<ArrayList<Mediafile>> {
|
override fun onSuccess(result: ArrayList<Mediafile>?) {
|
commonRepository.getAlias(sceneTypeId, t.value, object : ResultCallBack<String> {
|
override fun onSuccess(alias: String?) {
|
result?.let {
|
fileList.value?.add(MediaData().apply {
|
this.type = t
|
this.alias = if (alias.isNullOrBlank()) null else alias
|
dataList = it
|
dataList.add(0, Mediafile())
|
})
|
onMediaFileGet(types.size, types)
|
}
|
}
|
|
override fun onFailure() {
|
}
|
})
|
}
|
|
override fun onFailure() {
|
|
}
|
|
})
|
}
|
}
|
|
override fun onFailure() {
|
|
}
|
})
|
}
|
|
/**
|
* 新增本地多媒体文件记录
|
*/
|
fun putMediaFile(mediaFile: Mediafile) {
|
problemRepository.putMediaFileLocal(mediaFile, object : ResultCallBack<Int> {
|
override fun onSuccess(result: Int?) {
|
|
}
|
|
override fun onFailure() {
|
|
}
|
|
})
|
}
|
|
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, types: List<MediaFileType>) {
|
loadedCount++
|
// 当每种类型的数据都获取完毕后,进行重排序操作
|
if (loadedCount == total) {
|
val tempList = mutableListOf<MediaData>()
|
types.forEach { t ->
|
fileList.value?.find { it.type?.value == t.value }?.let { tempList.add(it) }
|
}
|
fileList.value = tempList
|
|
// 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
|
// }
|
}
|
}
|
|
}
|