Pu Zhibing
2025-12-11 ab0c19e49fabdb8cc6eea454ea455bce2efbb718
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
85
86
87
88
89
90
91
92
93
94
95
96
package com.igo.user.ui.mine
 
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.view.SwipeRefreshRecyclerLayout
import com.igo.user.R
import com.igo.user.network.Apis
import com.igo.user.network.HttpManager
import com.igo.user.network.entity.WalletRecord
import com.igo.user.network.request
import com.igo.user.ui.TransparentStatusBarActivity
import com.igo.user.ui.mine.adapter.WalletAdapter
import com.igo.user.utils.showMoney
import org.jetbrains.anko.find
import kotlin.math.abs
 
class RecordActivity : TransparentStatusBarActivity(){
    override fun setContentView() = R.layout.activity_record
 
    private val type by lazy {
        intent.getIntExtra("type", TYPE_CONSUME)
    }
    private val lvRecord by lazy {
        find<SwipeRefreshRecyclerLayout>(R.id.swipeRefreshLayout)
    }
    private val tv_total by lazy { find<TextView>(R.id.tv_total) }
    private val tv_1 by lazy { find<TextView>(R.id.tv_1) }
    override fun initClick() {
    }
 
    private val datas = arrayListOf<WalletRecord>()
    private val adapter by lazy {
        WalletAdapter(datas,type)
    }
    override fun initView() {
        title = when (type){
            TYPE_CONSUME ->getString(R.string.消费记录)
            TYPE_RED_USE ->getString(R.string.使用记录)
            TYPE_WITHDRAW ->getString(R.string.record_commit)
            TYPE_SCORE ->{
                tv_1.gone()
                tv_total.gone()
                getString(R.string.兑换记录)
            }
            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(getString(R.string.暂无数据))
                    else if (isEmpty())
                        lvRecord.setLoadMoreText(getString(R.string.没有更多))
                    tv_total.text = (abs(datas.firstOrNull()?.total?:0.0)).showMoney(this@RecordActivity)
                }
            }){_,_->
                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//积分使用
        const val TYPE_RECHARGE = 5//充值记录
    }
}