lmw
2025-01-08 09b34483033cf5f117103f9bb82a90da8a42e80a
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
package com.xianning.driver.ui.mine
 
import android.text.Editable
import android.text.TextWatcher
import androidx.recyclerview.widget.GridLayoutManager
import cn.sinata.xldutils.utils.clickDelay
import com.xianning.driver.R
import com.xianning.driver.base.MyBaseActivity
import com.xianning.driver.bean.RechargeMoneyBean
import com.xianning.driver.netUtls.Api
import com.xianning.driver.netUtls.callNet
import com.xianning.driver.netUtls.getMapByAny
import com.xianning.driver.ui.DialogUtil
import com.xianning.driver.ui.adapter.MoneyAdapter
import kotlinx.android.synthetic.main.activity_recharge.*
import kotlinx.android.synthetic.main.dialog_wx_pay.view.*
import java.lang.Exception
 
class RechargeActivity : MyBaseActivity() {
    override fun setContentView() {
        setContentView(R.layout.activity_recharge)
    }
 
    private val moneyAdapter = MoneyAdapter()
 
    override fun initView() {
        setTitleText("钱包")
        rv_money.layoutManager = GridLayoutManager(this,5)
        rv_money.adapter = moneyAdapter
        getMoney()
    }
 
    override fun setOnclick() {
        moneyAdapter.setOnItemClickListener { view, position ->
            moneyAdapter.checked = moneyAdapter.data[position]
            moneyAdapter.notifyDataSetChanged()
        }
 
        et_money.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
 
            }
 
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
 
            override fun afterTextChanged(s: Editable?) {
                moneyAdapter.checked = 0.0
                moneyAdapter.notifyDataSetChanged()
            }
        })
 
        tv_recharge.clickDelay {
            var money = 0.0
            if (moneyAdapter.checked!=0.0)
                money = moneyAdapter.checked
            else{
                val etMoney = et_money.text.toString()
                if (etMoney.isNullOrEmpty()){
                    showToast("请选择或填写充值金额")
                }else{
                    try {
                        money = etMoney.toDouble()
                    }catch (e:Exception){
                        showToast("请选择或填写充值金额")
                    }
                }
            }
            if (money == 0.0)
                showToast("请选择或填写充值金额")
            else{
                val dialog = DialogUtil.getDialog(this, R.layout.dialog_wx_pay)
                val view = DialogUtil.getView(dialog)
                view.tv_cancel.setOnClickListener {
                    dialog.dismiss()
                }
                view.tv_wx.setOnClickListener {
                    dialog.dismiss()
                    val mapByAny = getMapByAny()
                    mapByAny["money"] = money
                    callNet(Api.recharge,mapByAny){
 
                    }
                }
            }
        }
    }
 
    private fun getMoney(){
        callNet(Api.getRechargeMoney, getMapByAny()){
            val fromJson = gson.fromJson(it, RechargeMoneyBean::class.java)
            val map = fromJson.data.content.split(",").map { it.toDouble() }
            moneyAdapter.data.addAll(map)
            moneyAdapter.notifyDataSetChanged()
        }
    }
 
}