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
package com.dollearn.student.ui.welfare
 
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
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.welfare.adapter.CoinAdapter
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.activity_coin_record.*
 
class CoinRecordActivity : TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_coin_record
 
    private var date = ""
    private var type:Int? = null
    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
                    type = when(rst){
                        "增加"-> 1
                        "扣除"-> 2
                        else -> null
                    }
                    refreshLayout.autoRefresh()
                }
            })
            menuPop.contentView
                .measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
            menuPop.showAsDropDown(tv_filter,0,0,0)
        }
    }
 
    override fun initView() {
        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 {
            getRecord()
        }
        refreshLayout.setEnableLoadMore(false)
        getRecord()
    }
 
    private fun getRecord(){
        HttpManager.userBilling(date,type).request(this,success = { _, data->
            datas.clear()
            datas.addAll(data?: arrayListOf())
            adapter.notifyDataSetChanged()
            refreshLayout.finishRefresh()
 
        }){_,_->
            refreshLayout.finishRefresh(false)
        }
    }
 
}