riku
2025-07-02 3013b813e5df6977c0be921928f73b1a3adde290
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
package cn.flightfeather.thirdappmodule.module.inspection
 
import android.arch.lifecycle.Observer
import android.os.Bundle
import cn.flightfeather.thirdappmodule.adapter.ProblemListAdapter
import cn.flightfeather.thirdappmodule.model.event.InspectionEvent
import cn.flightfeather.thirdappmodule.model.event.ProblemEvent
import kotlinx.android.synthetic.main.dialog_problem_list.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
 
/**
 * @author riku
 * Date: 2019/8/1
 * 整改清单
 */
class MenuChangeActivity : BaseProblemListActivity() {
 
    override var viewHolderType: Int = ProblemListAdapter.PROBLEM_LIST
 
    override var type: Int = InspectionDetailActivity.PROBLEM_CHANGE
 
    var totalProblemCount = 0
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
 
        viewModel.problemList.observe(this, Observer {
            it?.let {
                rv_dialog_problem_list_main.adapter?.notifyDataSetChanged()
 
                val t1 = "共${it.size}个问题"
                tv_executors.text = t1
 
                var changed = 0
                it.forEach {p ->
                    if (p.ischanged) changed++
                }
                val t2 = "${changed}已整改"
                tv_start_time.text = t2
 
                totalProblemCount = it.size
            }
        })
 
        viewModel.getProblems(inspection?.guid)
    }
 
    @Subscribe(threadMode = ThreadMode.BACKGROUND)
    fun onUpdateChange(problemEvent: ProblemEvent) {
        if (problemEvent.type == InspectionDetailActivity.PROBLEM_CHANGE) {
            inspection?.apply {
                changednum = changednum?.plus(1) ?: 1
 
                if (changednum == totalProblemCount) {
                    ischanged = true
                }
                viewModel.getProblems(guid)
                EventBus.getDefault().post(InspectionEvent(this))
            }
        }
    }
}