package cn.flightfeather.thirdappmodule.module.inspection
|
|
import android.arch.lifecycle.Observer
|
import android.arch.lifecycle.ViewModelProviders
|
import android.content.Intent
|
import android.os.Bundle
|
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.StaggeredGridLayoutManager
|
import android.view.View
|
import android.widget.ImageView
|
import cn.flightfeather.thirdappmodule.CommonApplication
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.model.bean.LedgerRecord
|
import cn.flightfeather.thirdappmodule.module.base.BaseFragment
|
import cn.flightfeather.thirdappmodule.module.common.PhotoViewerActivity2
|
import cn.flightfeather.thirdappmodule.view.recyclerview.*
|
import com.bumptech.glide.Glide
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
import com.chad.library.adapter.base.BaseViewHolder
|
import kotlinx.android.synthetic.main.layout_recycler_view_refresh.*
|
import org.jetbrains.anko.support.v4.toast
|
import java.util.ArrayList
|
|
/**
|
* @author riku
|
* Date:2022/4/12
|
*
|
*/
|
class PicEvidenceFragment : BaseFragment() {
|
|
companion object {
|
const val ARG_PROBLEM = "ledgerList"
|
|
fun newInstance(ledgerRecords: ArrayList<LedgerRecord>): PicEvidenceFragment {
|
return PicEvidenceFragment().apply {
|
arguments = Bundle().apply {
|
putParcelableArrayList(ARG_PROBLEM, ledgerRecords)
|
}
|
}
|
}
|
}
|
|
lateinit var viewModel: PicEvidenceViewModel
|
|
private var ledgerRecords: List<LedgerRecord>? = null
|
private lateinit var recyclerViewPanel: RecyclerViewPanel<LedgerRecord>
|
|
override fun getLayoutId(): Int = R.layout.layout_recycler_view_refresh
|
|
override fun onCreateView() {
|
super.onCreateView()
|
ledgerRecords = arguments?.getParcelableArrayList(ARG_PROBLEM)
|
viewModel = ViewModelProviders.of(activity!!).get(PicEvidenceViewModel::class.java)
|
}
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
super.onViewCreated(view, savedInstanceState)
|
initUI()
|
initObserver()
|
}
|
|
private fun initUI() {
|
val dataModel = object : DataLoadModel<LedgerRecord>(context!!) {
|
override fun loadDataByRefresh() {
|
onSuccess(ledgerRecords)
|
}
|
|
override fun loadDataByLoadMore(page: Int) {
|
onPage(2, 1)
|
onSuccess(emptyList())
|
}
|
}
|
recyclerViewPanel = object : RecyclerViewPanel<LedgerRecord>(dataModel, recycler_view, context, refresh_layout) {
|
override fun getItemLayoutId(): Int? = R.layout.item_image_chose
|
|
override fun addSection(dataList: MutableList<MySection<LedgerRecord>>) {
|
super.addSection(dataList)
|
//每个LedgerRecord代表一项台账,其中包含所有的图片
|
// 将每项台账的名称作为分隔标题
|
val result = mutableListOf<MySection<LedgerRecord>>()
|
dataList.forEach {
|
// 分割标题
|
result.add(MySection(true, it.t.ledgerName, LedgerRecord()))
|
// 台账图片
|
it.t.path1?.split(";")?.forEach { url ->
|
result.add(MySection(LedgerRecord(
|
path1 = viewModel.application.ROOT_URL_RELEASE_IMAGE_2 + url,
|
// FIXME: 2022/4/13 此处借用该字段记录图片是否被选中,对应界面展示相应选中效果
|
upLoad = false
|
)))
|
}
|
}
|
dataList.clear()
|
dataList.addAll(result)
|
}
|
|
override fun onBindSectionView(holder: BaseCustomViewHolder?, item: MySection<LedgerRecord>?) {
|
super.onBindSectionView(holder, item)
|
item?.let {
|
holder?.setText(R.id.tv_section_head, it.header)
|
}
|
}
|
|
override fun onBindView(holder: BaseCustomViewHolder, item: MySection<LedgerRecord>?) {
|
item?.let {
|
holder.addOnClickListener(R.id.img_photo)
|
.addOnClickListener(R.id.fl_chose)
|
//图片是否选中判断
|
.setImageResource(R.id.img_chose, if (it.t.upLoad == true) R.drawable.ic_check_green_a700_24dp else R.color.white)
|
.getView<ImageView>(R.id.img_photo).let { i ->
|
Glide.with(this@PicEvidenceFragment).load(it.t.path1).into(i)
|
}
|
}
|
}
|
|
override fun onItemChildClick(adapter: BaseQuickAdapter<Any?, BaseViewHolder>, view: View, position: Int, dataList: List<LedgerRecord>) {
|
super.onItemChildClick(adapter, view, position, dataList)
|
when (view.id) {
|
// 放大图片
|
R.id.img_photo -> {
|
val paths = ArrayList<String>()
|
var pos = position
|
for (i in dataList.indices) {
|
val d = dataList[i]
|
if (d.path1 == null) {
|
if (position > i) pos--
|
} else {
|
paths.add(d.path1!!)
|
}
|
}
|
PhotoViewerActivity2.goto(activity, paths, pos)
|
}
|
// 选择图片
|
R.id.fl_chose -> {
|
val d = dataList[position]
|
viewModel.chosePic(d.path1 ?: "",{
|
d.upLoad = it
|
adapter.notifyItemChanged(position)
|
},{ toast(it) })
|
}
|
}
|
}
|
|
|
override fun getMyLayoutManager(): RecyclerView.LayoutManager = StaggeredGridLayoutManager(3, LinearLayoutManager.VERTICAL)
|
// GridLayoutManager(activity, 3, LinearLayoutManager.VERTICAL, false).apply {
|
// spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
// override fun getSpanSize(p0: Int): Int {
|
// return if (adapter?.getItemViewType(p0) == BaseRecyclerAdapter.SECTION_HEADER_VIEW) {
|
// spanCount
|
// } else {
|
// 1
|
// }
|
// }
|
// }
|
// }
|
|
override fun needSwipeRefresh(): Boolean = false
|
}.also {
|
it.init()
|
it.startRefresh()
|
}
|
}
|
|
private fun initObserver() {
|
// 监听清空按钮事件
|
viewModel.selectedImgUrls.observe(this, Observer {
|
if (it?.size == 0) {
|
recyclerViewPanel.adapter?.apply {
|
data.forEach {s ->
|
s.t.upLoad = false
|
}
|
notifyDataSetChanged()
|
}
|
}
|
})
|
}
|
}
|