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//积分使用
|
}
|
}
|