lmw
2024-06-18 1f45a54dc8e149548d3a61d1228741627aa4f23e
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 //积分记录
    }
}