package com.example.smart.ui.project.correct
|
|
import android.R
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.widget.AdapterView
|
import android.widget.ArrayAdapter
|
import androidx.core.view.isVisible
|
import androidx.fragment.app.viewModels
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import com.example.smart.databinding.ProjectIssuePageLayoutBinding
|
import com.example.smart.ui.project.correct.adapter.CorrectAdapter
|
import com.example.smart.ui.project.correct.bean.CorrectStyleBean
|
import com.example.smart.ui.project.frag.ProjectBasePage
|
import com.example.smart.ui.project.provider.ProjectPageFactory.PAGE_CORRECT
|
import razerdp.basepopup.BasePopupWindow.OnDismissListener
|
|
|
class CorrectPageFragment : ProjectBasePage() {
|
|
private val mDataList = ArrayList<CorrectStyleBean>()
|
|
private lateinit var adapter : CorrectAdapter
|
|
private val viewModel: CorrectViewModel by viewModels()
|
|
private var mineIssues = false
|
|
override fun callList() {
|
viewModel.callList(param.taskId, mineIssues) {
|
binding.loadingLayout.isVisible = true
|
binding.loadingLayout.loadError()
|
}
|
}
|
|
override fun onBindObserver() {
|
super.onBindObserver()
|
super.onBindObserver()
|
viewModel.correctBean.observe(this) {
|
if(it.isEmpty()) {
|
binding.loadingLayout.isVisible = true
|
binding.loadingLayout.loadEmpty()
|
} else{
|
binding.loadingLayout.isVisible = false
|
adapter.notifyData(it)
|
}
|
}
|
}
|
|
|
override fun initView() {
|
binding.recyclerView.layoutManager =
|
LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)
|
adapter = CorrectAdapter(mContext!!, mDataList, param)
|
adapter.setDismissListener(object : OnDismissListener() {
|
override fun onDismiss() {
|
callList()
|
}
|
})
|
binding.recyclerView.adapter = adapter
|
|
initSpinner()
|
}
|
|
private fun initSpinner() {
|
val creatorOptions = listOf("全部人员", "我创建的")
|
val adapter = ArrayAdapter(requireContext(), R.layout.simple_spinner_item, creatorOptions)
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
binding.creatorSpinner.adapter = adapter
|
// 调整字体大小
|
binding.creatorSpinner.setPopupBackgroundResource(com.example.smart.R.color.white)
|
binding.deviceSpinner.visibility = View.GONE
|
|
binding.creatorSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
mineIssues = position == 1
|
|
callList()
|
}
|
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
}
|
}
|
}
|
|
override fun initData() {}
|
|
override fun getPageId() = PAGE_CORRECT
|
|
private val binding by lazy {
|
ProjectIssuePageLayoutBinding.inflate(LayoutInflater.from(context))
|
}
|
|
companion object {
|
fun newInstance() = CorrectPageFragment()
|
}
|
|
override fun getRootView() = binding.root
|
|
|
}
|