lmw
2023-06-16 03972ad1d3ce6ffe0be0395c0a4d5dcb4474031f
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
70
71
72
73
74
75
package com.kuanzhai.user.ui.mine
 
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.fragment.BaseFragment
import cn.sinata.xldutils.view.SwipeRefreshRecyclerLayout
import com.kuanzhai.user.R
import com.kuanzhai.user.dialog.CardDetailDialog
import com.kuanzhai.user.network.HttpManager
import com.kuanzhai.user.network.entity.Card
import com.kuanzhai.user.network.requestByF
import com.kuanzhai.user.ui.mine.adapter.MyCardAdapter
import com.kuanzhai.user.utils.Const
import org.jetbrains.anko.support.v4.find
import org.jetbrains.anko.support.v4.startActivity
 
class MyCardFragment :BaseFragment() {
    override fun contentViewId() = R.layout.base_recyclerview_layout
    private val type by lazy {
        arguments?.getInt("type", Const.OrderType.TYPE_TAXI)?: Const.OrderType.TYPE_TAXI
    }
    private val lvList by lazy {
        find(R.id.swipeRefreshLayout) as SwipeRefreshRecyclerLayout
    }
    private val datas = arrayListOf<Card>()
    private val adapter by lazy { MyCardAdapter(datas,type) }
    private var page = 1
    override fun onFirstVisibleToUser() {
        lvList.setLayoutManager(LinearLayoutManager(activity))
        lvList.setAdapter(adapter)
        lvList.setOnRefreshListener(object :SwipeRefreshRecyclerLayout.OnRefreshListener{
            override fun onRefresh() {
                page = 1
                getData()
            }
 
            override fun onLoadMore() {
                page ++
                getData()
            }
        })
        lvList.setMode(SwipeRefreshRecyclerLayout.Mode.Top)
        lvList.isRefreshing = true
        getData()
        adapter.setOnItemClickListener { _, position ->
            startActivity<MyCardDetailActivity>("card" to datas[position],"type" to type)
        }
    }
 
    private fun getData(){
        HttpManager.getMyTaxiCardList(type).requestByF(this,success = { _, data->
            lvList.isRefreshing = false
            if (page == 1)
                datas.clear()
            data?.let {
                datas.addAll(it)
                if (datas.isEmpty())
                    lvList.setLoadMoreText("暂无数据")
                else if (it.isEmpty())
                    lvList.setLoadMoreText("没有更多")
            }
            adapter.notifyDataSetChanged()
        },error = {_,_->
            lvList.isRefreshing = false
        })
    }
 
    companion object{
        fun newInstance(type:Int):MyCardFragment{
            val fragment = MyCardFragment()
            fragment.arguments = bundleOf("type" to type)
            return fragment
        }
    }
}