package com.fuban.user.ui.mine
|
|
import android.app.Activity
|
import android.content.Intent
|
import android.text.Editable
|
import android.text.TextWatcher
|
import android.widget.CheckedTextView
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.utils.SPUtils
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.myToast
|
import com.fuban.user.R
|
import com.fuban.user.network.HttpManager
|
import com.fuban.user.network.request
|
import com.fuban.user.ui.TransparentStatusBarActivity
|
import com.fuban.user.dialog.SingleWheelDialog
|
import com.fuban.user.interfaces.StringCallback
|
import com.fuban.user.utils.Const
|
import com.fuban.user.utils.pay.PayListener
|
import com.fuban.user.utils.pay.PayUtil
|
import com.fuban.user.wxapi.WXPayEntryActivity
|
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory
|
import kotlinx.android.synthetic.main.activity_recharge.*
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.support.v4.startActivity
|
|
|
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 isGotoWx = false //是否跳转到微信小程序支付 true:回来时需要查询是否充值成功
|
override fun initClick() {
|
tv_action.setOnClickListener {
|
if (money == 0.0)
|
myToast("请选择充值金额")
|
else{
|
val singleWheelDialog = SingleWheelDialog()
|
singleWheelDialog.arguments = bundleOf("data" to arrayListOf(
|
// "支付宝支付",
|
"微信支付"))
|
singleWheelDialog.setCallback(object :StringCallback{
|
override fun onRlt(rlt: String) {
|
if (rlt == "微信支付")
|
HttpManager.depositBalance(if (rlt == "支付宝支付") 2 else 1,money).request(this@RechargeActivity){ _, data->
|
this@RechargeActivity.startActivity<WXPayEntryActivity>("type" to 1,"data" to data)
|
}
|
else{
|
showDialog()
|
HttpManager.depositBalance(if (rlt == "支付宝支付") 2 else 1,money).request(this@RechargeActivity){ _, data->
|
PayUtil.aliPay(this@RechargeActivity, data!!.orderString)
|
}
|
}
|
}
|
})
|
singleWheelDialog.show(supportFragmentManager,"way")
|
}
|
}
|
}
|
|
/**
|
* 微信小程序支付
|
*/
|
private fun wxPay() {
|
}
|
|
override fun initView() {
|
title = "充值"
|
balance = intent.getDoubleExtra("balance",0.0)
|
tv_money.text = SpanBuilder(String.format("¥%.2f",balance)).size(0,1,24).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(0,checkedTextView.text.length-1).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) {
|
}
|
})
|
PayUtil.addPayListener(this)
|
}
|
|
override fun onPaySuccess() {
|
myToast("充值成功")
|
setResult(Activity.RESULT_OK)
|
finish()
|
}
|
|
override fun onPayCancel() {
|
}
|
|
override fun onResume() {
|
super.onResume()
|
if (isGotoWx){
|
isGotoWx = false
|
HttpManager.queryUserInfo().request(this){_,data->
|
data?.run {
|
if (balance == this@RechargeActivity.balance+money){
|
onPaySuccess()
|
}else{
|
myToast("充值失败")
|
}
|
}
|
}
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
PayUtil.removePayListener(this)
|
}
|
|
}
|