package com.dollearn.student.ui.welfare
|
|
import android.app.Activity
|
import android.content.Intent
|
import android.view.View
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import cn.sinata.xldutils.utils.toTime
|
import com.dollearn.student.R
|
import com.dollearn.student.dialog.ChooseMonthDialog
|
import com.dollearn.student.dialog.FilterPop
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.CoinRecord
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.ui.mine.RechargeActivity
|
import com.dollearn.student.ui.welfare.adapter.CoinAdapter
|
import com.dollearn.student.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.activity_recharge_record.*
|
import org.jetbrains.anko.startActivityForResult
|
|
class RechargeRecordActivity : TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_recharge_record
|
|
private val type by lazy { intent.getIntExtra("type", TYPE_RECHARGE) }
|
private var date = ""
|
private var typeId:Int? = null
|
private var page = 1
|
private val datas = arrayListOf<CoinRecord>()
|
private val adapter = CoinAdapter(datas)
|
|
override fun initClick() {
|
tv_month.setOnClickListener {
|
val chooseMonthDialog = ChooseMonthDialog()
|
chooseMonthDialog.setCallback(object : StringCallback {
|
override fun onResult(rst: String) {
|
tv_month.text = "$rst >"
|
date = rst.replace("年","-").replace("月","")
|
refreshLayout.autoRefresh()
|
}
|
})
|
chooseMonthDialog.showAllowingStateLoss(supportFragmentManager,"date")
|
}
|
|
tv_filter.setOnClickListener {
|
val menuPop = FilterPop(this)
|
menuPop.setCallback(object :StringCallback{
|
override fun onResult(rst: String) {
|
tv_filter.text = rst
|
typeId = when(rst){
|
"增加"-> 1
|
"扣除"-> 2
|
else -> null
|
}
|
refreshLayout.autoRefresh()
|
}
|
})
|
menuPop.contentView
|
.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
|
menuPop.showAsDropDown(tv_filter,0,0,0)
|
}
|
|
tv_action.setOnClickListener {
|
startActivityForResult<RechargeActivity>(1)
|
}
|
}
|
|
override fun initView() {
|
if (type == TYPE_SCORE){
|
title = "积分明细"
|
refreshLayout.setEnableLoadMore(false)
|
tv_action.gone()
|
cl_list.elevation = 0f
|
}
|
tv_month.text = System.currentTimeMillis().toTime("yyyy年MM月")+" >"
|
date = System.currentTimeMillis().toTime("yyyy-MM")
|
rv_record.layoutManager = LinearLayoutManager(this)
|
rv_record.adapter = adapter
|
refreshLayout.setOnRefreshListener {
|
page = 1
|
getRecord()
|
getCoin()
|
}
|
refreshLayout.setOnLoadMoreListener {
|
page++
|
getRecord()
|
}
|
getCoin()
|
getRecord()
|
}
|
|
private fun getCoin(){
|
|
}
|
|
private fun getRecord(){
|
HttpManager.voucherDetail(date,typeId,page,type).request(this,success = {_,data->
|
if (page == 1)
|
datas.clear()
|
datas.addAll(data?: arrayListOf())
|
adapter.notifyDataSetChanged()
|
if (datas.isEmpty())
|
refreshLayout.finishRefreshWithNoMoreData()
|
else if (data.isNullOrEmpty())
|
refreshLayout.finishLoadMoreWithNoMoreData()
|
else if (page == 1)
|
refreshLayout.finishRefresh()
|
else
|
refreshLayout.finishLoadMore()
|
|
}){_,_->
|
if (page == 1)
|
refreshLayout.finishRefresh(false)
|
else
|
refreshLayout.finishLoadMore(false)
|
page--
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == Activity.RESULT_OK){
|
getCoin()
|
}
|
}
|
|
companion object{
|
const val TYPE_RECHARGE = 1 //充值明细
|
const val TYPE_SCORE = 2 //积分记录
|
}
|
}
|