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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cn.flightfeather.thirdapp.module.inspection
 
import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import cn.flightfeather.thirdapp.R
import cn.flightfeather.thirdapp.activity.ProblemDetailActivity
import cn.flightfeather.thirdapp.adapter.ProblemListAdapter
import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener
import cn.flightfeather.thirdapp.bean.entity.Inspection
import cn.flightfeather.thirdapp.bean.entity.Scense
import cn.flightfeather.thirdapp.bean.entity.Subtask
import cn.flightfeather.thirdapp.model.event.ProblemEvent
import cn.flightfeather.thirdapp.module.base.BaseActivity
import kotlinx.android.synthetic.main.dialog_problem_list.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
 
/**
 * @author riku
 * Date: 2019/8/1
 */
abstract class BaseProblemListActivity:BaseActivity() {
    override fun getLayoutId(): Int = R.layout.dialog_problem_list
 
    lateinit var viewModel: BaseProblemListViewModel
 
    /**
     * @see [ProblemListAdapter.PROBLEM_LIST] or [ProblemListAdapter.RECHECK_LIST]
     */
    abstract var viewHolderType: Int
 
    /**
     * @see [InspectionDetailActivity.PROBLEM_LIST], [InspectionDetailActivity.PROBLEM_CHANGE], [InspectionDetailActivity.PROBLEM_RECHECK]
     */
    abstract var type: Int
 
    protected var subTaskSelected: Subtask? = null
    protected var inspection: Inspection? = null
    protected var scene: Scense? = null
    protected var lat: Double = 0.0
    protected var lng: Double = 0.0
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBus.getDefault().register(this)
 
        viewModel = ViewModelProviders.of(this).get(BaseProblemListViewModel::class.java)
 
        subTaskSelected = intent.getSerializableExtra("subTask") as Subtask?
        inspection = intent.getSerializableExtra("inspection") as Inspection?
        scene = intent.getSerializableExtra("scene") as Scense?
        lat = intent.getDoubleExtra("lat", 0.0)
        lng = intent.getDoubleExtra("lng", 0.0)
 
        initUI()
    }
 
    private fun initUI() {
        rv_dialog_problem_list_main.apply {
            layoutManager = LinearLayoutManager(this@BaseProblemListActivity)
            adapter = ProblemListAdapter(this@BaseProblemListActivity, viewModel.problemList.value, viewHolderType)
            addOnItemTouchListener(RecyclerItemClickListener(this@BaseProblemListActivity, this, object : RecyclerItemClickListener.OnItemClickListener {
                override fun onItemClick(view: View?, position: Int) {
                    val intent = Intent(this@BaseProblemListActivity, ProblemDetailActivity::class.java)
                    intent.putExtra("problemlistVo", viewModel.problemList.value?.get(position))
                    intent.putExtra("subTaskSelected", subTaskSelected)
                    intent.putExtra("scenseLat", lat)
                    intent.putExtra("scenseLng", lng)
                    intent.putExtra("editable", type != InspectionDetailActivity.PROBLEM_LIST)
                    intent.putExtra("type", type)
                    startActivity(intent)
                }
 
                override fun onItemLongClick(view: View?, position: Int) {
                    onItemViewLongClick(view, position)
                }
 
            }))
        }
 
        tv_title.text = when (type) {
            InspectionDetailActivity.PROBLEM_LIST -> "问题清单"
            InspectionDetailActivity.PROBLEM_CHANGE -> "现场整改"
            InspectionDetailActivity.PROBLEM_RECHECK -> "问题复核"
            InspectionDetailActivity.PROBLEM_CHECK -> "问题审核"
            InspectionDetailActivity.CHANGE_CHECK -> "整改审核"
            else -> ""
        }
 
        fab_problem_list_close.setOnClickListener {
            finish()
        }
    }
 
    open fun onItemViewLongClick(view: View?, position: Int) {
 
    }
 
    @Subscribe
    fun onPutProblem(problemEvent: ProblemEvent) {
        viewModel.getProblems(inspection?.guid)
    }
}