lmw
2024-06-19 046174d13aeee8ed585ab2d4e28b8bce272e0217
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
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
        }
    }
}