package cn.flightfeather.thirdappmodule.module.inspectioninfo
|
|
import android.content.Context
|
import android.os.Build
|
import android.os.Bundle
|
import android.support.annotation.RequiresApi
|
import android.support.v4.app.Fragment
|
import android.support.v4.app.FragmentManager
|
import android.support.v4.app.FragmentPagerAdapter
|
import android.support.v4.content.ContextCompat
|
import android.support.v4.view.ViewCompat
|
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.RecyclerView
|
import android.view.*
|
import android.widget.PopupWindow
|
import android.widget.TextView
|
import butterknife.ButterKnife
|
import butterknife.Unbinder
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.adapter.AllRecyclerViewAdapter
|
import cn.flightfeather.thirdappmodule.bean.vo.ProblemCategoryVo
|
import cn.flightfeather.thirdappmodule.bean.vo.ProblemlistVo
|
import cn.flightfeather.thirdappmodule.util.Constant
|
import cn.flightfeather.thirdappmodule.util.Domain
|
import kotlinx.android.synthetic.main.activity_problem_change_pollution_scene.*
|
import kotlinx.android.synthetic.main.layout_actionbar.*
|
import java.util.*
|
|
/**
|
* 2019.1.25
|
* @author riku
|
* 客户界面
|
* 整改情况界面,展示客户未整改和已整改的问题列表
|
*/
|
class ProblemChangeActivity : AppCompatActivity() {
|
private var problemlistVos: ArrayList<ProblemlistVo>? = null
|
private var problemCategories: ArrayList<ProblemCategoryVo>? = null
|
private var newSelectedTypes: MutableList<Int>? = null
|
private var curSelectedTypes: MutableList<Int>? = null
|
private val TITLE = "整改"
|
private val POPUP_TITLE = "问题类型"
|
private var unbinder: Unbinder? = null
|
|
//<editor-fold desc="lifecycle">
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
//设置允许使用转场动画
|
window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
|
setContentView(R.layout.activity_problem_change_pollution_scene)
|
unbinder = ButterKnife.bind(this)
|
val intent = intent
|
problemlistVos = intent.getSerializableExtra(ARG_PROBLEM) as ArrayList<ProblemlistVo>
|
problemCategories = intent.getSerializableExtra(ARG_TOTAL_PROBLEM) as ArrayList<ProblemCategoryVo>
|
newSelectedTypes = ArrayList()
|
curSelectedTypes = ArrayList()
|
initToolBar()
|
initTab()
|
initViewPager()
|
initPopup()
|
initClickListener()
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
if (unbinder != null) {
|
unbinder!!.unbind()
|
}
|
}
|
|
//</editor-fold>
|
|
//<editor-fold desc="标题栏">
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
private fun initToolBar() {
|
// action_bar.setElevation(0);
|
// action_bar.setBackgroundColor(Color.alpha(0));
|
action_bar!!.findViewById<View>(R.id.spinner_topclass_task).visibility = View.GONE
|
// action_bar.findViewById(R.id.img_left).setVisibility(View.GONE);
|
img_right!!.setImageResource(R.drawable.ic_filter_list_white_36dp)
|
action_bar!!.findViewById<View>(R.id.ll_menu_text).visibility = View.GONE
|
actionbar_title!!.text = TITLE
|
}
|
|
private fun initClickListener() {
|
img_left.setOnClickListener { finish() }
|
img_right.setOnClickListener {
|
popShow()
|
newSelectedTypes!!.clear()
|
newSelectedTypes!!.addAll(curSelectedTypes!!)
|
}
|
}
|
|
//</editor-fold>
|
|
//<editor-fold desc="ViewPager初始化">
|
private var tabIndicators = mutableListOf<String>()//tab标题
|
private var tabFragments = mutableListOf<Fragment>()//内容
|
private var contentAdapter: ContentPagerAdapter? = null//viewPager内容页面适配器
|
|
private fun initTab() {
|
// tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
tabLayout!!.tabGravity = Gravity.CENTER_HORIZONTAL
|
tabLayout!!.setTabTextColors(ContextCompat.getColor(this, R.color.unselected), ContextCompat.getColor(this, R.color.main_text_color))
|
tabLayout!!.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.main_text_color))
|
ViewCompat.setElevation(tabLayout!!, 2f)
|
tabLayout!!.setupWithViewPager(viewPager) //将tab和viewPager绑定
|
}
|
|
private val unChangedProblems = ArrayList<ProblemlistVo>()
|
private val changedProblems = ArrayList<ProblemlistVo>()
|
private fun initViewPager() {
|
changedProblems.clear()
|
unChangedProblems.clear()
|
for (i in problemlistVos!!.indices) {
|
val problemlistVoTemp = problemlistVos!![i]
|
if (!problemlistVoTemp.ischanged) {
|
unChangedProblems.add(problemlistVoTemp)
|
} else if (problemlistVoTemp.extension3 != Domain.CHANGE_CHECK_PASS) {
|
unChangedProblems.add(problemlistVoTemp)
|
} else {
|
changedProblems.add(problemlistVoTemp)
|
}
|
}
|
tabIndicators.add("待整改问题")
|
tabIndicators.add("已整改问题")
|
tabFragments.add(ProblemChangeFragment.newInstance(unChangedProblems, Constant.UNCHANGED))
|
tabFragments.add(ProblemChangeFragment.newInstance(changedProblems, Constant.CHANGED))
|
contentAdapter = ContentPagerAdapter(supportFragmentManager)
|
viewPager!!.adapter = contentAdapter
|
}
|
|
//刷新ViewPager
|
fun refreshViewPager() {
|
changedProblems.clear()
|
unChangedProblems.clear()
|
for (i in problemlistVos!!.indices) {
|
val problemlistVoTemp = problemlistVos!![i]
|
if (!problemlistVoTemp.ischanged) {
|
unChangedProblems.add(problemlistVoTemp)
|
} else if (problemlistVoTemp.extension3 != Domain.CHANGE_CHECK_PASS) {
|
unChangedProblems.add(problemlistVoTemp)
|
} else {
|
changedProblems.add(problemlistVoTemp)
|
}
|
}
|
val pf1 = tabFragments!![0] as ProblemChangeFragment
|
val pf2 = tabFragments!![1] as ProblemChangeFragment
|
pf1.notifyDataSetChanged()
|
pf2.notifyDataSetChanged()
|
}
|
|
//整改完成后,刷新问题列表
|
fun refreshProblemList(problemlistVo: ProblemlistVo?) {
|
if (problemlistVo == null) return
|
for (p in problemlistVos!!) {
|
if (p.guid == problemlistVo.guid) {
|
problemlistVos!!.remove(p)
|
break
|
}
|
}
|
problemlistVos!!.add(problemlistVo)
|
}
|
|
/**
|
* viewPager适配器
|
*/
|
internal inner class ContentPagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) {
|
override fun getItem(position: Int): Fragment {
|
return tabFragments!![position]
|
}
|
|
override fun getCount(): Int {
|
return tabIndicators!!.size
|
}
|
|
override fun getPageTitle(position: Int): CharSequence? {
|
return tabIndicators!![position]
|
}
|
}
|
|
//</editor-fold>
|
|
//<editor-fold desc="根据用户选择显示对应类型的问题">
|
private fun showSelectedProblemType(type: List<Int>?) {
|
problemlistVos!!.clear()
|
for (t in type!!) {
|
problemlistVos!!.addAll(problemCategories!![t].problemlistVos)
|
}
|
if (type.isEmpty()) {
|
for (p in problemCategories!!) {
|
problemlistVos!!.addAll(p.problemlistVos)
|
}
|
}
|
refreshViewPager()
|
}
|
|
//</editor-fold>
|
|
//<editor-fold desc="popupWindow">
|
private var popupWindow: FilterPopupWindow? = null
|
private var popupIsShowing = false
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
private fun initPopup() {
|
popupWindow = FilterPopupWindow(this, problemCategories)
|
}
|
|
private fun popShow() {
|
popupWindow!!.showAtLocation(action_bar, Gravity.BOTTOM, 0, 0)
|
popupIsShowing = true
|
setWindowAloha(0.6f)
|
}
|
|
private fun popDismiss() {
|
popupWindow!!.dismiss()
|
popupIsShowing = false
|
}
|
|
private fun setWindowAloha(f: Float) {
|
val window = window
|
val wl = window.attributes
|
wl.alpha = f
|
window.attributes = wl
|
}
|
|
private fun popupRefresh() {
|
popupWindow!!.notifyDataSetChanged()
|
}
|
|
internal inner class FilterPopupWindow @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) constructor(context: Context?, private val datas: List<ProblemCategoryVo>?) : PopupWindow(context) {
|
var rv_problem_type: RecyclerView? = null
|
var adapter: AllRecyclerViewAdapter<ProblemCategoryVo>? = null
|
private fun initView(view: View) {
|
rv_problem_type = view.findViewById(R.id.rv_problem_type_2)
|
adapter = object : AllRecyclerViewAdapter<ProblemCategoryVo>(
|
datas,
|
R.layout.item_problem_type,
|
this@ProblemChangeActivity
|
) {
|
override fun bindView(holder: MyViewHolder, obj: ProblemCategoryVo, isSelected: Boolean, position: Int) {
|
//填充问题类型名称
|
holder.setText(R.id.text_problem_type, obj.problemTypeName)
|
|
//根据问题数量设置点击事件
|
if (obj.totalCount == 0) {
|
holder.setAlpha(R.id.text_problem_type, 0.2f)
|
holder.setOnClickListener(R.id.text_problem_type, null)
|
} else {
|
holder.setOnClickListener(R.id.text_problem_type) { v ->
|
v.isSelected = !v.isSelected
|
if (v.isSelected) {
|
newSelectedTypes!!.add(position)
|
} else {
|
newSelectedTypes!!.remove(position)
|
}
|
}
|
holder.setAlpha(R.id.text_problem_type, 1f)
|
}
|
|
//根据用户的选择设置是否选择状态
|
if (curSelectedTypes!!.contains(position)) {
|
holder.setSelected(R.id.text_problem_type, true)
|
} else {
|
holder.setSelected(R.id.text_problem_type, false)
|
}
|
}
|
}
|
val layoutManager = GridLayoutManager(this@ProblemChangeActivity, 3)
|
layoutManager.orientation = LinearLayoutManager.VERTICAL
|
rv_problem_type?.setLayoutManager(layoutManager)
|
rv_problem_type?.setAdapter(adapter)
|
}
|
|
private fun setClickListener(v: View) {
|
val text_complete = v.findViewById<TextView>(R.id.text_complete)
|
val text_cancel = v.findViewById<TextView>(R.id.text_cancel)
|
text_complete.setOnClickListener {
|
popDismiss()
|
curSelectedTypes!!.clear()
|
curSelectedTypes!!.addAll(newSelectedTypes!!)
|
showSelectedProblemType(curSelectedTypes)
|
popupRefresh()
|
}
|
text_cancel.setOnClickListener { popDismiss() }
|
}
|
|
fun notifyDataSetChanged() {
|
adapter!!.notifyDataSetChanged()
|
}
|
|
init {
|
height = ViewGroup.LayoutParams.WRAP_CONTENT
|
width = ViewGroup.LayoutParams.MATCH_PARENT
|
elevation = 2f
|
setBackgroundDrawable(null)
|
isOutsideTouchable = true
|
isFocusable = true
|
animationStyle = R.style.popwin_anim_style
|
setOnDismissListener { setWindowAloha(1f) }
|
val contentView = LayoutInflater.from(this@ProblemChangeActivity).inflate(R.layout.popup_problem_selector, null, false)
|
initView(contentView)
|
setClickListener(contentView)
|
setContentView(contentView)
|
}
|
} //</editor-fold>
|
|
companion object {
|
//<editor-fold desc="全局变量">
|
const val ARG_PROBLEM = "problem"
|
const val ARG_TOTAL_PROBLEM = "totalProblem"
|
}
|
}
|