package com.dollearn.student.ui.welfare
|
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.fragment.BaseFragment
|
import com.dollearn.student.R
|
import com.dollearn.student.dialog.CheckShopsDialog
|
import com.dollearn.student.dialog.LoginRuleDialog
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.Coupon
|
import com.dollearn.student.network.requestByF
|
import com.dollearn.student.ui.welfare.adapter.CouponDetailAdapter
|
import com.dollearn.student.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.layout_common_list.*
|
|
class CouponFragment:BaseFragment() {
|
override fun contentViewId() = R.layout.layout_common_list
|
|
private val type by lazy { arguments?.getInt("type", TYPE_ALL)?: TYPE_ALL }
|
private val list = arrayListOf<Coupon>()
|
private val adapter = CouponDetailAdapter(list)
|
|
override fun onFirstVisibleToUser() {
|
refreshLayout.setEnableLoadMore(false)
|
refreshLayout.setOnRefreshListener {
|
getData()
|
}
|
rv_list.layoutManager = LinearLayoutManager(requireContext())
|
rv_list.adapter = adapter
|
adapter.callback = object :StringCallback{
|
override fun onResult(rst: String) {
|
val coupon = list[rst.toInt()]
|
if (coupon.useCondition == "3")
|
CheckShopsDialog.show(childFragmentManager, coupon.cityOrStore?:"",CheckShopsDialog.TYPE_COUPON_USAGE)
|
else if (coupon.useCondition == "2")
|
CheckShopsDialog.show(childFragmentManager, coupon.cityOrStore?:"",CheckShopsDialog.TYPE_COUPON_CITY)
|
}
|
}
|
getData()
|
}
|
|
fun refresh(){
|
refreshLayout.autoRefresh()
|
}
|
|
private fun getData(){
|
HttpManager.queryCouponPackage((requireActivity() as CouponActivity).state,if (type == TYPE_ALL) null else type).requestByF(this,success = {_,data->
|
refreshLayout.finishRefresh()
|
list.clear()
|
list.addAll(data?: arrayListOf())
|
adapter.notifyDataSetChanged()
|
}){_,_->
|
refreshLayout.finishRefresh(false)
|
}
|
}
|
|
companion object{
|
const val TYPE_ALL = 0 //全部
|
const val TYPE_FULL = 1 //满减
|
const val TYPE_MONEY = 2 //代金券
|
const val TYPE_FREE = 3 //体验
|
|
fun newInstance(type:Int):CouponFragment{
|
val couponFragment = CouponFragment()
|
couponFragment.arguments = bundleOf("type" to type)
|
return couponFragment
|
}
|
}
|
}
|