1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cn.flightfeather.thirdapp.module.inspection
 
import android.arch.lifecycle.MutableLiveData
import cn.flightfeather.thirdapp.bean.Mediafile
import cn.flightfeather.thirdapp.common.net.ResultCallBack
import cn.flightfeather.thirdapp.model.enumreation.MediaFileType
import cn.flightfeather.thirdapp.module.base.BaseViewModel
import cn.flightfeather.thirdapp.repository.InspectionRepository
import cn.flightfeather.thirdapp.repository.ProblemRepository
 
/**
 * @author riku
 * Date: 2019/8/2
 */
class MenuCameraViewModel : BaseViewModel() {
 
    private val inspectionRepository = InspectionRepository()
    private val problemRepository = ProblemRepository()
 
    //常规记录图片
    val routineRecordList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
    //铭牌图片
    val nameplateList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
    //监测设备图片
    val monitorDeviceList = MutableLiveData<ArrayList<Mediafile>>().apply { value = ArrayList() }
 
    private val dataSet = listOf(
            Pair(MediaFileType.RoutineRecord, routineRecordList),
            Pair(MediaFileType.Nameplate, nameplateList),
            Pair(MediaFileType.MonitorDevice, monitorDeviceList)
    )
 
    /**
     * 获取任意拍照图片
     */
    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)
                        }
                        p.second.value = p.second.value
                    }
                }
 
                override fun onFailure() {
 
                }
 
            })
        }
    }
 
    /**
     * 新增本地多媒体文件记录
     */
    fun putMediaFile(mediaFile: Mediafile) {
        problemRepository.putMediaFileLocal(mediaFile, object : ResultCallBack<Int> {
            override fun onSuccess(result: Int?) {
 
            }
 
            override fun onFailure() {
 
            }
 
        })
    }
}