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
74
75
76
77
78
79
80
81
82
83
84
package cn.flightfeather.thirdapp.module.inspection
 
import android.arch.lifecycle.Observer
import android.os.Bundle
import cn.flightfeather.thirdapp.adapter.ProblemListAdapter
import cn.flightfeather.thirdapp.bean.vo.ProblemlistVo
import cn.flightfeather.thirdapp.fragment.InspectionFragment
import cn.flightfeather.thirdapp.model.event.InspectionEvent
import cn.flightfeather.thirdapp.model.event.ProblemEvent
import cn.flightfeather.thirdapp.util.Constant
import cn.flightfeather.thirdapp.util.DateFormatter
import kotlinx.android.synthetic.main.dialog_problem_list.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.util.*
 
/**
 * @author riku
 * Date: 2019/8/1
 * 问题复核activity
 */
class MenuRecheckActivity : BaseProblemListActivity() {
    override var viewHolderType: Int = ProblemListAdapter.RECHECK_LIST
 
    override var type: Int = InspectionDetailActivity.PROBLEM_RECHECK
 
    var totalProblemCount = 0
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
 
        viewModel.subTaskPack.observe(this, Observer {
            it?.let {
                val changedList = ArrayList<ProblemlistVo>()
                var rechecked = 0
                it.problemlistVo?.forEach {p ->
                    if (p.ischanged) {
                        changedList.add(p)
                    }
                    if (p.isrechecked) {
                        rechecked++
                    }
                }
 
 
                viewModel.problemList.value?.run {
                    clear()
                    addAll(it.problemlistVo ?: emptyList())
                    removeAll(changedList)
                    rv_dialog_problem_list_main.adapter?.notifyDataSetChanged()
                }
 
                val t1 = it.subtaskVo?.executorrealtimes?.replace(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW)
                val t2 = it.subtaskVo?.executionstarttime?.let { time -> DateFormatter.dateTimeFormat.format(time)}
 
                val t11 = "${if (t1 != null) t1 + "\n" else ""} 共${viewModel.problemList.value?.size ?: 0}个问题"
                val t22 = "${if (t2 != null) t2 + "\n" else ""} ${rechecked}个已复核"
 
                totalProblemCount = viewModel.problemList.value?.size ?: 0
 
                tv_executors.text = t11
                tv_start_time.text = t22
            }
        })
 
        viewModel.getLastProblems(subTaskSelected)
    }
 
    @Subscribe(threadMode = ThreadMode.BACKGROUND)
    fun onUpdateRecheck(problemEvent: ProblemEvent) {
        if (problemEvent.type == InspectionDetailActivity.PROBLEM_RECHECK) {
            inspection?.apply {
                recheckcount = recheckcount?.plus(1) ?: 1
 
                if (recheckcount == totalProblemCount) {
                    isrechecked = true
                }
 
                EventBus.getDefault().post(InspectionEvent(this))
            }
        }
    }
}