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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package cn.flightfeather.thirdappmodule.module.nightwork
 
import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import cn.flightfeather.thirdappmodule.R
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
import cn.flightfeather.thirdappmodule.model.bean.NightWorkFileVo
import cn.flightfeather.thirdappmodule.module.base.BaseActivity
import cn.flightfeather.thirdappmodule.module.common.OfficeFileManageActivity
import cn.flightfeather.thirdappmodule.util.CommonUtils
import cn.flightfeather.thirdappmodule.view.recyclerview.BaseCustomViewHolder
import cn.flightfeather.thirdappmodule.view.recyclerview.MySection
import cn.flightfeather.thirdappmodule.view.recyclerview.RecyclerViewPanel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.loadmore.LoadMoreView
import kotlinx.android.synthetic.main.activity_night_work.*
import kotlinx.android.synthetic.main.layout_toolbar_2.*
 
/**
 * @author riku
 * Date: 2020/12/24
 */
class NightWorkRecordActivity : BaseActivity() {
 
    inner class FileLoadMoreView : LoadMoreView() {
        override fun getLayoutId(): Int = R.layout.item_night_work_no_more
 
        override fun getLoadingViewId(): Int = R.id.no_more
 
        override fun getLoadFailViewId(): Int = R.id.no_more
 
        override fun getLoadEndViewId(): Int = R.id.no_more
    }
 
    lateinit var viewModel: NightWorkViewModel
 
    private lateinit var recyclerViewPanel1: RecyclerViewPanel<NightWorkFileVo>
 
    private lateinit var recyclerViewPanel2: RecyclerViewPanel<NightWorkFileVo>
 
    override fun getLayoutId(): Int = R.layout.activity_night_work
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel = ViewModelProviders.of(this).get(NightWorkViewModel::class.java)
 
        initToolbar()
        initRecyclerView1()
        initRecyclerView2()
        initObserver()
    }
 
    private fun initToolbar() {
        img_back.setOnClickListener { finish() }
        tv_main_title.text = "夜间施工许可"
    }
 
    /**
     * 最新未读文件
     */
    private fun initRecyclerView1() {
        recyclerViewPanel1 = object : RecyclerViewPanel<NightWorkFileVo>(viewModel.dataLoadModel1, recycler_view, this) {
            private val TYPE_ITEM = 1
            private val TYPE_EMPTY = 2
 
            override fun getItemLayoutId(): Int? = R.layout.item_night_work
 
//            override fun getItemLayoutIdMap(): Map<Int, Int> = mapOf(
//                    Pair(TYPE_ITEM, R.layout.item_night_work),
//                    Pair(TYPE_EMPTY, R.layout.item_night_work_no_more)
//            )
 
//            override fun convertToSection(list: List<NightWorkFileVo>): MutableList<MySection<NightWorkFileVo>> {
//                val resultList = mutableListOf<MySection<NightWorkFileVo>>()
//                list.forEach {
//                    if (it.id != null) {
//                        resultList.add(MySection(it, TYPE_ITEM))
//                    }
//                }
//                resultList.add(MySection(NightWorkFileVo(), TYPE_EMPTY))
//                return resultList
//            }
 
            override fun onBindView(holder: BaseCustomViewHolder, item: MySection<NightWorkFileVo>?) {
                item?.t?.let { vo ->
//                    when (holder.itemViewType) {
//                        TYPE_ITEM -> {
//
//                        }
//                        TYPE_EMPTY -> Unit
//                        else -> Unit
//                    }
                    val time = CommonUtils.getStartEndDate(vo.startDate, vo.endDate)
                    holder.setText(R.id.txt_night_work_num, vo.num)
                            .setText(R.id.txt_content, vo.applyContent)
                            .setText(R.id.txt_time, time)
                            .addOnClickListener(R.id.txt_sign)
                }
            }
 
            override fun onItemClick(adapter: BaseQuickAdapter<Any?, BaseViewHolder>, view: View, position: Int, dataList: List<NightWorkFileVo>) {
                super.onItemClick(adapter, view, position, dataList)
                val d = dataList[position]
                openDetail(d)
                d.id?.let { id ->
                    d.num?.let { num ->
                        viewModel.signFile(id, num, object : ResultCallBack<Int> {
                            override fun onSuccess(result: Int?) {
                                adapter.remove(position)
                                recyclerViewPanel2.addData(0, listOf(d))
                            }
 
                            override fun onFailure() {
                            }
                        })
                    }
                }
            }
 
            override fun onItemChildClick(adapter: BaseQuickAdapter<Any?, BaseViewHolder>, view: View, position: Int, dataList: List<NightWorkFileVo>) {
                super.onItemChildClick(adapter, view, position, dataList)
                val d = dataList[position]
                when (view.id) {
                    R.id.txt_sign -> {
                        d.id?.let { id ->
                            d.num?.let { num ->
                                viewModel.signFile(id, num, object : ResultCallBack<Int> {
                                    override fun onSuccess(result: Int?) {
                                        adapter.remove(position)
                                        recyclerViewPanel2.addData(0, listOf(d))
                                    }
 
                                    override fun onFailure() {
                                    }
                                })
                            }
                        }
                    }
                }
            }
 
            override fun getMyLayoutManager(): RecyclerView.LayoutManager = LinearLayoutManager(this@NightWorkRecordActivity, LinearLayoutManager.HORIZONTAL, false)
 
            override fun needSwipeRefresh(): Boolean = false
 
            override fun getLoadMoreView(): LoadMoreView? = FileLoadMoreView()
 
            override fun getMyEmptyView(): View? = LayoutInflater.from(this@NightWorkRecordActivity).inflate(R.layout.layout_night_work_empty, null)
 
        }.also {
            it.init()
            it.startRefresh()
        }
    }
 
    /**
     * 历史文件
     */
    private fun initRecyclerView2() {
        recyclerViewPanel2 = object : RecyclerViewPanel<NightWorkFileVo>(viewModel.dataLoadModel2, recycler_view_2, this) {
            override fun getItemLayoutId(): Int? = R.layout.item_night_work_2
 
            override fun onBindView(holder: BaseCustomViewHolder, item: MySection<NightWorkFileVo>?) {
                item?.t?.let { vo ->
                    val time = CommonUtils.getStartEndDate(vo.startDate, vo.endDate)
                    holder.setText(R.id.txt_content, vo.applyContent)
                            .setText(R.id.txt_time, time)
                }
            }
 
            override fun onItemClick(adapter: BaseQuickAdapter<Any?, BaseViewHolder>, view: View, position: Int, dataList: List<NightWorkFileVo>) {
                super.onItemClick(adapter, view, position, dataList)
                openDetail(dataList[position])
            }
        }.also {
            it.init()
            it.startRefresh()
        }
    }
 
    private fun initObserver() {
 
    }
 
    private fun openDetail(nightWorkFileVo: NightWorkFileVo) {
        val intent = Intent(this, OfficeFileManageActivity::class.java)
        intent.putExtra("filePath", nightWorkFileVo.url)
        intent.putExtra("fileName", nightWorkFileVo.fileName)
        intent.putExtra("isRemoteFile", nightWorkFileVo.url?.contains("http") == true)
        startActivity(intent)
    }
}