package com.igo.user.ui.mine
|
|
import android.app.Activity
|
import android.text.Editable
|
import android.text.TextWatcher
|
import android.widget.CheckedTextView
|
import android.widget.EditText
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.toBrowser
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.myToast
|
import com.igo.user.R
|
import com.igo.user.dialog.ChooseCardDialog
|
import com.igo.user.dialog.SingleWheelDialog
|
import com.igo.user.interfaces.StringCallback
|
import com.igo.user.network.HttpManager
|
import com.igo.user.network.request
|
import com.igo.user.ui.TransparentStatusBarActivity
|
import com.igo.user.utils.pay.PayListener
|
import org.jetbrains.anko.find
|
|
|
class RechargeActivity : TransparentStatusBarActivity(), PayListener {
|
override fun setContentView() = R.layout.activity_recharge
|
|
private val items = arrayListOf<CheckedTextView>()
|
private var money = 10.0 //充值金额
|
private var balance = 0.0
|
private var isGotoPay = false //是否跳转到微信小程序支付 true:回来时需要查询是否充值成功
|
|
private val tv_action by lazy { find<TextView>(R.id.tv_action) }
|
private val tv_money by lazy { find<TextView>(R.id.tv_money) }
|
private val tv_10 by lazy { find<CheckedTextView>(R.id.tv_10) }
|
private val tv_20 by lazy { find<CheckedTextView>(R.id.tv_20) }
|
private val tv_50 by lazy { find<CheckedTextView>(R.id.tv_50) }
|
private val tv_100 by lazy { find<CheckedTextView>(R.id.tv_100) }
|
private val tv_200 by lazy { find<CheckedTextView>(R.id.tv_200) }
|
private val et_money by lazy { find<EditText>(R.id.et_money) }
|
|
override fun initClick() {
|
tv_action.setOnClickListener {
|
if (money == 0.0)
|
myToast(getString(R.string.请选择充值金额))
|
else{
|
val singleWheelDialog = SingleWheelDialog()
|
singleWheelDialog.arguments = bundleOf("data" to arrayListOf(getString(R.string.银行卡支付),getString(R.string.手机支付)))
|
singleWheelDialog.setCallback(object :StringCallback{
|
override fun onRlt(rlt: String) {
|
if (rlt == getString(R.string.银行卡支付)){
|
val dialog = ChooseCardDialog()
|
dialog.setCallback(object :StringCallback{
|
override fun onRlt(rlt: String) {
|
showDialog()
|
HttpManager.depositBalance(2,money,rlt).request(this@RechargeActivity){ _, data->
|
isGotoPay = true
|
toBrowser(data?:"")
|
}
|
}
|
})
|
dialog.show(supportFragmentManager,"card")
|
} else{
|
showDialog()
|
HttpManager.depositBalance(1,money).request(this@RechargeActivity){ _, data->
|
isGotoPay = true
|
toBrowser(data?:"")
|
}
|
}
|
}
|
})
|
singleWheelDialog.show(supportFragmentManager,"way")
|
}
|
}
|
}
|
|
|
override fun initView() {
|
title = getString(R.string.充值)
|
balance = intent.getDoubleExtra("balance",0.0)
|
tv_money.text = SpanBuilder(String.format("FCFA%.2f",balance)).size(0,3,21).build()
|
items.addAll(arrayOf(tv_10,tv_20,tv_50,tv_100,tv_200))
|
items.forEachIndexed { index, checkedTextView ->
|
checkedTextView.setOnClickListener {
|
items.forEach {
|
it.isChecked = false
|
}
|
checkedTextView.isChecked = true
|
et_money.setText("")
|
money = checkedTextView.text.toString().substring(3,checkedTextView.text.length).toDouble()
|
}
|
}
|
et_money.addTextChangedListener(object :TextWatcher{
|
override fun afterTextChanged(s: Editable?) {
|
if (s.isNullOrEmpty())
|
money = 0.0
|
else{
|
items.forEach {
|
it.isChecked = false
|
}
|
money = try {
|
s.toString().toDouble()
|
}catch (e:Exception){
|
0.0
|
}
|
}
|
|
}
|
|
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
}
|
|
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
}
|
})
|
}
|
|
override fun onPaySuccess() {
|
myToast(getString(R.string.充值成功))
|
setResult(Activity.RESULT_OK)
|
finish()
|
}
|
|
override fun onPayCancel() {
|
}
|
|
override fun onResume() {
|
super.onResume()
|
if (isGotoPay){
|
isGotoPay = false
|
HttpManager.queryUserInfo().request(this){_,data->
|
data?.run {
|
if (balance == this@RechargeActivity.balance+money){
|
onPaySuccess()
|
}else{
|
myToast(getString(R.string.充值失败))
|
}
|
}
|
}
|
}
|
}
|
}
|