lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
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
76
77
78
79
80
81
82
83
84
package com.fuban.user.ui.mine
 
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.view.SwipeRefreshRecyclerLayout
import com.fuban.user.R
import com.fuban.user.network.Apis
import com.fuban.user.network.HttpManager
import com.fuban.user.network.entity.WalletRecord
import com.fuban.user.network.request
import com.fuban.user.ui.TransparentStatusBarActivity
import com.fuban.user.ui.mine.adapter.WalletAdapter
import org.jetbrains.anko.find
 
class RecordActivity : TransparentStatusBarActivity(){
    override fun setContentView() = R.layout.base_recyclerview_layout
 
    private val type by lazy {
        intent.getIntExtra("type", TYPE_CONSUME)
    }
    private val lvRecord by lazy {
        find<SwipeRefreshRecyclerLayout>(R.id.swipeRefreshLayout)
    }
    override fun initClick() {
    }
 
    private val datas = arrayListOf<WalletRecord>()
    private val adapter by lazy {
        WalletAdapter(datas,type)
    }
    override fun initView() {
        title = when (type){
            TYPE_CONSUME ->"消费记录"
            TYPE_RED_USE ->"使用记录"
            TYPE_WITHDRAW ->"提现记录"
            TYPE_SCORE ->"兑换纪录"
            else ->""
        }
        lvRecord.setOnRefreshListener(object :SwipeRefreshRecyclerLayout.OnRefreshListener{
            override fun onRefresh() {
                page = 1
                getData()
            }
 
            override fun onLoadMore() {
                page++
                getData()
            }
        })
        lvRecord.setLayoutManager(LinearLayoutManager(this))
        lvRecord.setAdapter(adapter)
        getData()
    }
 
    private var page = 1
    private fun getData(){
            HttpManager.walletRecord(when(type){
                TYPE_CONSUME->Apis.useRecord
                TYPE_RED_USE->Apis.queryRedEnvelope
                TYPE_SCORE->Apis.queryConvertHistory
                else->Apis.queryWithdrawal
            },page).request(this,success = { _, data->
                lvRecord.isRefreshing = false
                data?.run {
                    if (page == 1)
                        datas.clear()
                    datas.addAll(this)
                    adapter.notifyDataSetChanged()
                    if (datas.isEmpty())
                        lvRecord.setLoadMoreText("暂无数据")
                    else if (isEmpty())
                        lvRecord.setLoadMoreText("没有更多")
                }
            }){_,_->
                lvRecord.isRefreshing = false
            }
    }
 
    companion object{
        const val TYPE_CONSUME = 1//消费记录
        const val TYPE_RED_USE = 2//红包使用
        const val TYPE_WITHDRAW = 3//提现使用
        const val TYPE_SCORE = 4//积分使用
    }
}