兑换和提现功能开发
This commit is contained in:
@@ -2,19 +2,34 @@ package com.yizhuan.erban.earn
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.yizhuan.erban.base.BaseViewModel
|
||||
import com.yizhuan.xchat_android_core.earn.bean.ConfigWithdrawInfo
|
||||
import com.yizhuan.xchat_android_core.earn.bean.EarnRecordInfo
|
||||
import com.yizhuan.xchat_android_core.earn.bean.GoldToDiamondInfo
|
||||
import com.yizhuan.xchat_android_core.earn.model.EarnModel
|
||||
import com.yizhuan.xchat_android_core.utils.toast
|
||||
|
||||
class EarnRecordViewModel : BaseViewModel() {
|
||||
|
||||
//收益记录
|
||||
private val _earnRecordLiveData = MutableLiveData<EarnRecordInfo?>()
|
||||
val earnRecordLiveData: MutableLiveData<EarnRecordInfo?> = _earnRecordLiveData
|
||||
|
||||
//金币兑换钻石
|
||||
private val _goldToDiamondLiveData = MutableLiveData<GoldToDiamondInfo?>()
|
||||
val goldToDiamondLiveData: MutableLiveData<GoldToDiamondInfo?> = _goldToDiamondLiveData
|
||||
|
||||
//金币兑换钻石-确认
|
||||
private val _exchangeConfirmLiveData = MutableLiveData<String?>()
|
||||
val exchangeConfirmLiveData: MutableLiveData<String?> = _exchangeConfirmLiveData
|
||||
|
||||
//提现界面
|
||||
private val _getConfigWithdrawLiveData = MutableLiveData<ConfigWithdrawInfo?>()
|
||||
val getConfigWithdrawLiveData: MutableLiveData<ConfigWithdrawInfo?> = _getConfigWithdrawLiveData
|
||||
|
||||
//提现
|
||||
private val _exchangeLiveData = MutableLiveData<String?>()
|
||||
val exchangeLiveData: MutableLiveData<String?> = _exchangeLiveData
|
||||
|
||||
/**
|
||||
* 收益记录
|
||||
*/
|
||||
@@ -45,4 +60,49 @@ class EarnRecordViewModel : BaseViewModel() {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 金币兑换钻石-确认
|
||||
*/
|
||||
fun exchangeConfirm(
|
||||
goldNum: Long,
|
||||
diamondNum: Long,
|
||||
currency: Int
|
||||
) {
|
||||
safeLaunch(
|
||||
true,
|
||||
block = {
|
||||
_exchangeConfirmLiveData.value =
|
||||
EarnModel.exchangeConfirm(goldNum, diamondNum, currency)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现界面
|
||||
*/
|
||||
fun getConfigWithdraw() {
|
||||
safeLaunch(
|
||||
true,
|
||||
block = {
|
||||
_getConfigWithdrawLiveData.value = EarnModel.getConfigWithdrawInfo()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现
|
||||
*/
|
||||
fun exchange(goldNum: Long, payPwd: String) {
|
||||
safeLaunch(
|
||||
true,
|
||||
onError = {
|
||||
it.message.toast()
|
||||
_exchangeLiveData.value = null
|
||||
},
|
||||
block = {
|
||||
_exchangeLiveData.value = EarnModel.exchange(goldNum, payPwd)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@@ -4,11 +4,16 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import androidx.activity.viewModels
|
||||
import com.netease.nim.uikit.StatusBarUtil
|
||||
import com.yizhuan.erban.R
|
||||
import com.yizhuan.erban.base.BaseViewBindingActivity
|
||||
import com.yizhuan.erban.databinding.ActivityConvertDiamondBinding
|
||||
import com.yizhuan.erban.earn.EarnRecordViewModel
|
||||
import com.yizhuan.xchat_android_core.earn.bean.GoldToDiamondInfo
|
||||
import com.yizhuan.xchat_android_library.common.util.DoubleUtils
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.floor
|
||||
|
||||
/**
|
||||
* author: wushaocheng
|
||||
@@ -17,6 +22,11 @@ import com.yizhuan.xchat_android_core.earn.bean.GoldToDiamondInfo
|
||||
*/
|
||||
class ConvertDiamondActivity : BaseViewBindingActivity<ActivityConvertDiamondBinding>() {
|
||||
|
||||
private val earnRecordModel: EarnRecordViewModel by viewModels()
|
||||
|
||||
private var isGold = false
|
||||
private var isDiamond = false
|
||||
|
||||
companion object {
|
||||
const val BEAN = "bean"
|
||||
|
||||
@@ -30,13 +40,19 @@ class ConvertDiamondActivity : BaseViewBindingActivity<ActivityConvertDiamondBin
|
||||
|
||||
override fun init() {
|
||||
initTitleBar(getString(R.string.convert_diamond))
|
||||
val bean: GoldToDiamondInfo = intent.getSerializableExtra(BEAN) as GoldToDiamondInfo
|
||||
bean.let {
|
||||
val bean = intent.getSerializableExtra(BEAN) as? GoldToDiamondInfo
|
||||
bean?.let {
|
||||
binding.tvMyGold.text = getString(R.string.my_gold, it.golds.toString())
|
||||
binding.tvMyDiamond.text = getString(R.string.my_diamond, it.diamonds.toString())
|
||||
binding.edGold.hint = (it.minDiamonds.toDouble() /it.rate).toString()
|
||||
binding.edGold.hint = it.minGolds.toString()
|
||||
binding.edDiamond.hint = it.minDiamonds.toString()
|
||||
binding.edGold.addTextChangedListener(object : TextWatcher{
|
||||
binding.edGold.setOnFocusChangeListener { view, b ->
|
||||
isGold = b
|
||||
}
|
||||
binding.edDiamond.setOnFocusChangeListener { view, b ->
|
||||
isDiamond = b
|
||||
}
|
||||
binding.edGold.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
@@ -46,11 +62,30 @@ class ConvertDiamondActivity : BaseViewBindingActivity<ActivityConvertDiamondBin
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
||||
if (isGold) {
|
||||
val goldText = s.toString()
|
||||
if (goldText.isNotEmpty()) {
|
||||
binding.edDiamond.setText(
|
||||
//去掉小数凑整:不论小数是多少,都不进位
|
||||
DoubleUtils.convertDoubleToString(
|
||||
floor(
|
||||
DoubleUtils.mul(
|
||||
goldText.toDouble(),
|
||||
it.rate
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
binding.edDiamond.setText("")
|
||||
}
|
||||
}
|
||||
binding.tvConvert.isEnabled = binding.edGold.text.toString()
|
||||
.isNotEmpty() && binding.edDiamond.text.toString().isNotEmpty()
|
||||
}
|
||||
|
||||
})
|
||||
binding.edDiamond.addTextChangedListener(object : TextWatcher{
|
||||
binding.edDiamond.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
@@ -60,10 +95,62 @@ class ConvertDiamondActivity : BaseViewBindingActivity<ActivityConvertDiamondBin
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
||||
if (isDiamond) {
|
||||
val diamondText = s.toString()
|
||||
if (diamondText.isNotEmpty()) {
|
||||
binding.edGold.setText(
|
||||
//去掉小数凑整:不管小数是多少,都进一
|
||||
DoubleUtils.convertDoubleToString(
|
||||
ceil(
|
||||
DoubleUtils.div(
|
||||
diamondText.toDouble(),
|
||||
it.rate
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
binding.edGold.setText("")
|
||||
}
|
||||
}
|
||||
binding.tvConvert.isEnabled = binding.edGold.text.toString()
|
||||
.isNotEmpty() && binding.edDiamond.text.toString().isNotEmpty()
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
earnRecordModel.loadingLiveData.observe(this) { loading ->
|
||||
if (loading) dialogManager.showProgressDialog(this)
|
||||
else dialogManager.dismissDialog()
|
||||
}
|
||||
|
||||
earnRecordModel.exchangeConfirmLiveData.observe(this) {
|
||||
toast(getString(R.string.exchange_success))
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.tvConvert.setOnClickListener { view ->
|
||||
if (binding.edDiamond.text.toString().toLong() < it.minDiamonds) {
|
||||
toast("至少需要兌換${it.minDiamonds}鉆石")
|
||||
} else if (binding.edDiamond.text.toString().toLong() > it.maxDiamonds) {
|
||||
toast("兌換鉆石數不能超過${it.maxDiamonds}鉆")
|
||||
} else {
|
||||
if (isDiamond) {
|
||||
earnRecordModel.exchangeConfirm(
|
||||
binding.edGold.text.toString().toLong(),
|
||||
binding.edDiamond.text.toString().toLong(),
|
||||
1
|
||||
)
|
||||
} else if (isGold) {
|
||||
earnRecordModel.exchangeConfirm(
|
||||
binding.edGold.text.toString().toLong(),
|
||||
binding.edDiamond.text.toString().toLong(),
|
||||
3
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -58,6 +58,12 @@ class EarnRecordActivity : BaseViewBindingActivity<ActivityEarnRecordBinding>(),
|
||||
}
|
||||
}
|
||||
|
||||
earnRecordModel.getConfigWithdrawLiveData.observe(this) {
|
||||
it?.let {
|
||||
EarnWithdrawActivity.start(this, it)
|
||||
}
|
||||
}
|
||||
|
||||
earnRecordModel.getEarnRecordInfo()
|
||||
}
|
||||
|
||||
@@ -90,7 +96,7 @@ class EarnRecordActivity : BaseViewBindingActivity<ActivityEarnRecordBinding>(),
|
||||
earnRecordModel.getGoldToDiamondInfo()
|
||||
}
|
||||
R.id.tvConvertWithdraw -> {//提现
|
||||
EarnWithdrawActivity.start(this)
|
||||
earnRecordModel.getConfigWithdraw()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,28 +2,139 @@ package com.yizhuan.erban.earn.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import com.jungly.gridpasswordview.GridPasswordView
|
||||
import com.netease.nim.uikit.StatusBarUtil
|
||||
import com.yizhuan.erban.R
|
||||
import com.yizhuan.erban.base.BaseViewBindingActivity
|
||||
import com.yizhuan.erban.databinding.ActivityEarnWithdrawBinding
|
||||
import com.yizhuan.erban.earn.EarnRecordViewModel
|
||||
import com.yizhuan.erban.pay.password.GiveGoldPassWordFragment
|
||||
import com.yizhuan.erban.ui.setting.ModifyPwdActivity
|
||||
import com.yizhuan.erban.ui.widget.dialog.CommonTipDialog
|
||||
import com.yizhuan.erban.ui.widget.password.PassWordFragment
|
||||
import com.yizhuan.xchat_android_core.earn.bean.ConfigWithdrawInfo
|
||||
import com.yizhuan.xchat_android_core.pay.PayModel
|
||||
import com.yizhuan.xchat_android_core.user.UserModel
|
||||
import com.yizhuan.xchat_android_library.utils.ResUtil
|
||||
import kotlinx.android.synthetic.main.activity_give_gold_to_user.*
|
||||
|
||||
/**
|
||||
* author: wushaocheng
|
||||
* time: 2022/11/18
|
||||
* desc: 提现
|
||||
*/
|
||||
class EarnWithdrawActivity : BaseViewBindingActivity<ActivityEarnWithdrawBinding>() {
|
||||
class EarnWithdrawActivity : BaseViewBindingActivity<ActivityEarnWithdrawBinding>(),
|
||||
GridPasswordView.OnPasswordChangedListener {
|
||||
|
||||
private val earnRecordModel: EarnRecordViewModel by viewModels()
|
||||
|
||||
private var passWordFragment: GiveGoldPassWordFragment? = null
|
||||
|
||||
companion object {
|
||||
|
||||
const val BEAN = "bean"
|
||||
|
||||
@JvmStatic
|
||||
fun start(context: Context) {
|
||||
fun start(context: Context, configWithdrawInfo: ConfigWithdrawInfo) {
|
||||
val starter = Intent(context, EarnWithdrawActivity::class.java)
|
||||
starter.putExtra(BEAN, configWithdrawInfo)
|
||||
context.startActivity(starter)
|
||||
}
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
initTitleBar(getString(R.string.withdraw))
|
||||
val bean = intent.getSerializableExtra(BEAN) as? ConfigWithdrawInfo
|
||||
bean?.let {
|
||||
binding.tvMyGold.text = getString(R.string.my_gold, it.golds.toString())
|
||||
binding.edGold.hint = it.minGolds.toString()
|
||||
binding.tvWithdrawNum.text =
|
||||
getString(R.string.number_of_withdrawals_in_remaining_weeks, it.remainTimes)
|
||||
if (it.account.uid != 0L) {
|
||||
binding.groupBind.visibility = View.VISIBLE
|
||||
binding.tvNoWithdraw.visibility = View.GONE
|
||||
binding.tvSwift.text = getString(R.string.swift_code, it.account.swift)
|
||||
binding.tvBankName.text = getString(R.string.bank_name, it.account.bankName)
|
||||
} else {
|
||||
binding.groupBind.visibility = View.GONE
|
||||
binding.tvNoWithdraw.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
binding.edGold.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
binding.tvWithdraw.isEnabled =
|
||||
it.account.uid != 0L && p0.toString().isNotEmpty() && it.remainTimes > 0
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
earnRecordModel.loadingLiveData.observe(this) { loading ->
|
||||
if (loading) dialogManager.showProgressDialog(this)
|
||||
else dialogManager.dismissDialog()
|
||||
}
|
||||
|
||||
earnRecordModel.exchangeLiveData.observe(this) { exchange ->
|
||||
exchange?.let {
|
||||
passWordFragment?.dismissAllowingStateLoss()
|
||||
toast(getString(R.string.withdraw_success))
|
||||
finish()
|
||||
} ?: run {
|
||||
passWordFragment?.dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
binding.tvWithdraw.setOnClickListener { view ->
|
||||
UserModel.get().cacheLoginUserInfo?.let { userInfo ->
|
||||
if (!userInfo.isBindPaymentPwd) {
|
||||
val tipDialog = CommonTipDialog(this@EarnWithdrawActivity)
|
||||
tipDialog.setTipMsg(ResUtil.getString(R.string.setting_pay_pwd_first))
|
||||
tipDialog.setOkText(getString(R.string.to_setting))
|
||||
tipDialog.setOnActionListener(
|
||||
object : CommonTipDialog.OnActionListener {
|
||||
override fun onOk() {
|
||||
ModifyPwdActivity.start(
|
||||
this@EarnWithdrawActivity,
|
||||
ModifyPwdActivity.PAY_PWD
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
tipDialog.show()
|
||||
} else if (binding.edGold.text.toString().toLong() < it.minGolds) {
|
||||
toast("至少需要兌換${it.minGolds}金幣")
|
||||
} else if (binding.edGold.text.toString().toLong() > it.maxGolds) {
|
||||
toast("提現不能超過${it.maxGolds}金幣")
|
||||
} else {
|
||||
GiveGoldPassWordFragment.newInstance(
|
||||
supportFragmentManager,
|
||||
"1000",
|
||||
"哈哈",
|
||||
""
|
||||
)
|
||||
.apply {
|
||||
passWordFragment = this
|
||||
setListener(this@EarnWithdrawActivity)
|
||||
}
|
||||
}
|
||||
} ?: run {
|
||||
toast(ResUtil.getString(R.string.ui_setting_settingactivity_06))
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun needSteepStateBar() = true
|
||||
@@ -34,5 +145,16 @@ class EarnWithdrawActivity : BaseViewBindingActivity<ActivityEarnWithdrawBinding
|
||||
StatusBarUtil.StatusBarLightMode(this)
|
||||
}
|
||||
|
||||
override fun onTextChanged(psw: String?) {
|
||||
val password = passWordFragment?.password?.password ?: ""
|
||||
if (password.length == 6) {
|
||||
earnRecordModel.exchange(binding.edGold.text.toString().toLong(), password)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInputFinish(psw: String?) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -176,6 +176,7 @@
|
||||
android:layout_marginEnd="@dimen/dp_15"
|
||||
android:layout_marginTop="@dimen/dp_50"
|
||||
android:background="@drawable/bg_common_confirm"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@+id/csConvertDetail"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -159,6 +159,7 @@
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:layout_marginBottom="@dimen/dp_18"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
android:text="@string/withdraw"
|
||||
android:textColor="@color/color_582815"
|
||||
|
@@ -26,6 +26,7 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_bar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvNoWithdraw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
@@ -37,6 +38,39 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSwift"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
android:text="@string/swift_code"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/sp_14"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tvBankName"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvBankName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
android:text="@string/bank_name"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/sp_14"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvSwift"/>
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/groupBind"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="tvSwift,tvBankName"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -75,17 +109,17 @@
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/ui_withdraw_withdrawactivity_09"
|
||||
android:textSize="@dimen/sp_13"
|
||||
android:textColor="@color/color_6D6B89"
|
||||
android:drawablePadding="@dimen/dp_2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvMyGold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvMyGold"
|
||||
android:layout_marginEnd="@dimen/dp_14"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableEndCompat="@drawable/ic_withdraw_record_arrow" />
|
||||
android:layout_marginEnd="@dimen/dp_14"
|
||||
android:drawablePadding="@dimen/dp_2"
|
||||
android:text="@string/ui_withdraw_withdrawactivity_09"
|
||||
android:textColor="@color/color_6D6B89"
|
||||
android:textSize="@dimen/sp_13"
|
||||
app:drawableEndCompat="@drawable/ic_withdraw_record_arrow"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvMyGold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvMyGold" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/csMyGold"
|
||||
@@ -136,23 +170,24 @@
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:text="@string/number_of_withdrawals_in_remaining_weeks"
|
||||
android:textSize="@dimen/sp_13"
|
||||
android:textColor="@color/color_6D6B89"
|
||||
android:includeFontPadding="false"
|
||||
android:id="@+id/tvWithdrawNum"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_28"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
android:layout_marginEnd="@dimen/dp_28"
|
||||
android:layout_marginBottom="@dimen/dp_20"
|
||||
android:includeFontPadding="false"
|
||||
android:text="@string/number_of_withdrawals_in_remaining_weeks"
|
||||
android:textColor="@color/color_6D6B89"
|
||||
android:textSize="@dimen/sp_13"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/csMyGold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
app:layout_constraintTop_toBottomOf="@+id/csMyGold" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvConvert"
|
||||
android:id="@+id/tvWithdraw"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="46dp"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
|
@@ -77,8 +77,7 @@
|
||||
android:layout_marginEnd="@dimen/dp_15"
|
||||
android:background="@drawable/bg_home_chat"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="48dp"
|
||||
@@ -107,6 +106,7 @@
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="@dimen/dp_10"
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||
|
||||
<ImageView
|
||||
|
@@ -4976,5 +4976,9 @@
|
||||
<string name="number_of_withdrawals_in_remaining_weeks">剩餘周提現次數:%d次</string>
|
||||
<string name="immediate_cash_withdrawal">立即提現</string>
|
||||
<string name="select_game">選擇游戲</string>
|
||||
<string name="exchange_success">兑换成功</string>
|
||||
<string name="swift_code">swift code/BIC:%s</string>
|
||||
<string name="bank_name">bank name:%s</string>
|
||||
<string name="withdraw_success">提現成功</string>
|
||||
|
||||
</resources>
|
@@ -0,0 +1,13 @@
|
||||
package com.yizhuan.xchat_android_core.earn.bean
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class ConfigWithdrawInfo(
|
||||
val account: WithdrawAccount,
|
||||
val golds: Double,//钱包当前金币数
|
||||
val remainTimes: Int,//周剩余次数
|
||||
val fee: Double,//手续费
|
||||
val minGolds: Long,
|
||||
val maxGolds: Long,
|
||||
val hasPayPwd: Boolean
|
||||
) : Serializable
|
@@ -7,5 +7,7 @@ data class GoldToDiamondInfo(
|
||||
val golds: Double,
|
||||
val rate: Double,
|
||||
val maxDiamonds: Long,
|
||||
val minDiamonds: Long
|
||||
val minDiamonds: Long,
|
||||
val maxGolds: Long,
|
||||
val minGolds: Long,
|
||||
) : Serializable
|
@@ -0,0 +1,15 @@
|
||||
package com.yizhuan.xchat_android_core.earn.bean
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class WithdrawAccount(
|
||||
val uid: Long,
|
||||
val swift: String,
|
||||
val bankName: String,
|
||||
val accountNumber: String,
|
||||
val accountName: String,
|
||||
val address: String,
|
||||
val city: String,
|
||||
val province: String,
|
||||
val postCode: String
|
||||
) : Serializable
|
@@ -2,12 +2,15 @@ package com.yizhuan.xchat_android_core.earn.model
|
||||
|
||||
import com.yizhuan.xchat_android_core.base.BaseModel
|
||||
import com.yizhuan.xchat_android_core.bean.response.ServiceResult
|
||||
import com.yizhuan.xchat_android_core.earn.bean.ConfigWithdrawInfo
|
||||
import com.yizhuan.xchat_android_core.earn.bean.EarnRecordInfo
|
||||
import com.yizhuan.xchat_android_core.earn.bean.GoldToDiamondInfo
|
||||
import com.yizhuan.xchat_android_core.home.bean.*
|
||||
import com.yizhuan.xchat_android_core.utils.net.launchRequest
|
||||
import com.yizhuan.xchat_android_library.net.rxnet.RxNet
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Query
|
||||
|
||||
object EarnModel : BaseModel() {
|
||||
|
||||
@@ -23,6 +26,25 @@ object EarnModel : BaseModel() {
|
||||
api.getGoldToDiamondInfo()
|
||||
}
|
||||
|
||||
suspend fun exchangeConfirm(
|
||||
goldNum: Long,
|
||||
diamondNum: Long,
|
||||
currency: Int
|
||||
): String? =
|
||||
launchRequest {
|
||||
api.exchangeConfirm(goldNum, diamondNum, currency)
|
||||
}
|
||||
|
||||
suspend fun getConfigWithdrawInfo(): ConfigWithdrawInfo? =
|
||||
launchRequest {
|
||||
api.getConfigWithdrawInfo()
|
||||
}
|
||||
|
||||
suspend fun exchange(goldNum: Long, payPwd: String): String? =
|
||||
launchRequest {
|
||||
api.exchange(goldNum, payPwd)
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
|
||||
/**
|
||||
@@ -37,6 +59,31 @@ object EarnModel : BaseModel() {
|
||||
@GET("/goldExchangeDiamond/getConfig")
|
||||
suspend fun getGoldToDiamondInfo(): ServiceResult<GoldToDiamondInfo>
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@POST("/goldExchangeDiamond/exchange")
|
||||
suspend fun exchangeConfirm(
|
||||
@Query("goldNum") goldNum: Long,
|
||||
@Query("diamondNum") diamondNum: Long,
|
||||
@Query("currency") currency: Int
|
||||
): ServiceResult<String>
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@GET("/withdraw/getConfig")
|
||||
suspend fun getConfigWithdrawInfo(): ServiceResult<ConfigWithdrawInfo>
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@POST("/withdraw/exchange")
|
||||
suspend fun exchange(
|
||||
@Query("goldNum") goldNum: Long,
|
||||
@Query("payPwd") payPwd: String
|
||||
): ServiceResult<String>
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package com.yizhuan.xchat_android_library.common.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。
|
||||
*/
|
||||
public class DoubleUtils{
|
||||
private static final int DEF_DIV_SCALE = 2;
|
||||
|
||||
/**
|
||||
* @Description 两个Double数相加
|
||||
*
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return Double
|
||||
*/
|
||||
public static Double add(Double d1,Double d2){
|
||||
BigDecimal b1 = new BigDecimal(d1.toString());
|
||||
BigDecimal b2 = new BigDecimal(d2.toString());
|
||||
return b1.add(b2).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 两个Double数相减
|
||||
*
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return Double
|
||||
*/
|
||||
public static Double sub(Double d1,Double d2){
|
||||
BigDecimal b1 = new BigDecimal(d1.toString());
|
||||
BigDecimal b2 = new BigDecimal(d2.toString());
|
||||
return b1.subtract(b2).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 两个Double数相乘
|
||||
*
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return Double
|
||||
*/
|
||||
public static Double mul(Double d1,Double d2){
|
||||
BigDecimal b1 = new BigDecimal(d1.toString());
|
||||
BigDecimal b2 = new BigDecimal(d2.toString());
|
||||
return b1.multiply(b2).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 两个Double数相除
|
||||
*
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return Double
|
||||
*/
|
||||
public static Double div(Double d1,Double d2){
|
||||
BigDecimal b1 = new BigDecimal(d1.toString());
|
||||
BigDecimal b2 = new BigDecimal(d2.toString());
|
||||
return b1.divide(b2,DEF_DIV_SCALE,BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 两个Double数相除,并保留scale位小数
|
||||
*
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @param scale
|
||||
* @return Double
|
||||
*/
|
||||
public static Double div(Double d1,Double d2,int scale){
|
||||
if(scale<0){
|
||||
throw new IllegalArgumentException(
|
||||
"The scale must be a positive integer or zero");
|
||||
}
|
||||
BigDecimal b1 = new BigDecimal(d1.toString());
|
||||
BigDecimal b2 = new BigDecimal(d2.toString());
|
||||
return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description String类型小数与Double类型的转换
|
||||
*/
|
||||
public static void StrToDouble(){
|
||||
String str="1234.5678";
|
||||
double num;
|
||||
DecimalFormat myformat = new DecimalFormat("#0.00");
|
||||
num = Double.parseDouble(str);//直接转换为double类型
|
||||
num = Double.parseDouble(myformat.format(num));//保留2为小数
|
||||
System.out.println(num);
|
||||
}
|
||||
|
||||
public static String convertDoubleToString(double number) {
|
||||
DecimalFormat df = new DecimalFormat("######0");
|
||||
return df.format(number);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user