支付限制时间啦
This commit is contained in:
parent
135b46db24
commit
2d49c2822a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,6 +3,7 @@ package com.coldmint.rust.pro
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.CountDownTimer
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -14,6 +15,10 @@ import com.coldmint.rust.pro.base.BaseActivity
|
||||||
import com.coldmint.rust.pro.databinding.ActivityPayBinding
|
import com.coldmint.rust.pro.databinding.ActivityPayBinding
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.coldmint.rust.core.dataBean.OrderDataBean
|
import com.coldmint.rust.core.dataBean.OrderDataBean
|
||||||
import com.coldmint.rust.core.interfaces.ApiCallBack
|
import com.coldmint.rust.core.interfaces.ApiCallBack
|
||||||
|
@ -34,6 +39,19 @@ import java.io.IOException
|
||||||
*/
|
*/
|
||||||
class PayActivity : BaseActivity<ActivityPayBinding>() {
|
class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||||
val hashMap: HashMap<String, String> = HashMap()
|
val hashMap: HashMap<String, String> = HashMap()
|
||||||
|
|
||||||
|
//是否超时了
|
||||||
|
var past: Boolean = false
|
||||||
|
|
||||||
|
//是否第一次启动
|
||||||
|
var first = true
|
||||||
|
|
||||||
|
//优惠的价格(用于询问退出时使用)
|
||||||
|
var difference = 0.toDouble()
|
||||||
|
|
||||||
|
//倒计时器
|
||||||
|
var countDownTimer: CountDownTimer? = null
|
||||||
|
|
||||||
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
|
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
|
||||||
if (canUseView) {
|
if (canUseView) {
|
||||||
viewBinding.toolbar.title = getText(R.string.pay)
|
viewBinding.toolbar.title = getText(R.string.pay)
|
||||||
|
@ -164,7 +182,6 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||||
override fun onResponse(t: OrderDataBean) {
|
override fun onResponse(t: OrderDataBean) {
|
||||||
if (t.code == ServerConfiguration.Success_Code) {
|
if (t.code == ServerConfiguration.Success_Code) {
|
||||||
val data = t.data
|
val data = t.data
|
||||||
createMoney(data.price)
|
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
stringBuilder.append("订单名:")
|
stringBuilder.append("订单名:")
|
||||||
stringBuilder.append(data.name)
|
stringBuilder.append(data.name)
|
||||||
|
@ -179,8 +196,38 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||||
stringBuilder.append("\n原价:")
|
stringBuilder.append("\n原价:")
|
||||||
stringBuilder.append(data.originalPrice)
|
stringBuilder.append(data.originalPrice)
|
||||||
stringBuilder.append("元")
|
stringBuilder.append("元")
|
||||||
|
difference = data.originalPrice - data.price
|
||||||
}
|
}
|
||||||
viewBinding.info.text = stringBuilder.toString()
|
viewBinding.info.text = stringBuilder.toString()
|
||||||
|
val timeBuilder = StringBuilder()
|
||||||
|
countDownTimer = object : CountDownTimer(600000, 1000) {
|
||||||
|
override fun onTick(p0: Long) {
|
||||||
|
//秒
|
||||||
|
timeBuilder.clear()
|
||||||
|
val second = p0 / 1000
|
||||||
|
if (second >= 60) {
|
||||||
|
val minute = second / 60
|
||||||
|
timeBuilder.append(minute)
|
||||||
|
timeBuilder.append("分钟")
|
||||||
|
timeBuilder.append(second % 60)
|
||||||
|
timeBuilder.append("秒")
|
||||||
|
} else {
|
||||||
|
timeBuilder.append(second)
|
||||||
|
timeBuilder.append("秒")
|
||||||
|
}
|
||||||
|
setMoney(timeBuilder.toString(), t.data.price)
|
||||||
|
Log.d("秒", timeBuilder.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinish() {
|
||||||
|
past = true
|
||||||
|
viewBinding.typeSpinner.isEnabled = false
|
||||||
|
viewBinding.baseImageView.isVisible = false
|
||||||
|
viewBinding.payMoneyView.text = getString(R.string.order_timeout)
|
||||||
|
viewBinding.saveCode.isEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
countDownTimer!!.start()
|
||||||
} else {
|
} else {
|
||||||
showError(t.message)
|
showError(t.message)
|
||||||
}
|
}
|
||||||
|
@ -195,29 +242,106 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
if (first) {
|
||||||
|
first = false
|
||||||
|
} else {
|
||||||
|
if (!past) {
|
||||||
|
MaterialDialog(this).show {
|
||||||
|
title(R.string.pay).message(R.string.is_paid).positiveButton(R.string.paid_yes)
|
||||||
|
.positiveButton {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
.negativeButton(R.string.paid_no).negativeButton {
|
||||||
|
askingQuit()
|
||||||
|
}.cancelable(false).neutralButton(R.string.paid_continue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
|
||||||
|
askingQuit()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
val id = item.itemId
|
||||||
|
if (id == android.R.id.home) {
|
||||||
|
askingQuit()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置显示钱数
|
* 询问是否退出
|
||||||
|
*/
|
||||||
|
fun askingQuit() {
|
||||||
|
if (difference == 0.toDouble()) {
|
||||||
|
countDownTimer?.cancel()
|
||||||
|
finish()
|
||||||
|
} else {
|
||||||
|
MaterialDialog(this).show {
|
||||||
|
title(R.string.paid_no).message(
|
||||||
|
text = String.format(
|
||||||
|
getString(R.string.preferential_price),
|
||||||
|
difference
|
||||||
|
)
|
||||||
|
).positiveButton(R.string.dialog_ok).positiveButton {
|
||||||
|
countDownTimer?.cancel()
|
||||||
|
finish()
|
||||||
|
}.negativeButton(R.string.dialog_cancel).cancelable(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置显示的钱数以及剩余时间
|
||||||
|
* @param time String
|
||||||
* @param money Double
|
* @param money Double
|
||||||
*/
|
*/
|
||||||
fun createMoney(money: Double) {
|
fun setMoney(time: String, money: Double) {
|
||||||
val payMoney = getString(R.string.pay_tip)
|
val payMoney = getString(R.string.pay_tip)
|
||||||
val tipMoney = money.toString()
|
val tipMoney = money.toString()
|
||||||
val tip = String.format(payMoney, tipMoney)
|
val tip = String.format(payMoney, time, tipMoney)
|
||||||
val start = payMoney.indexOf("%1\$s")
|
val start = tip.indexOf("在") + 1
|
||||||
|
val end = tip.indexOf("内")
|
||||||
|
val start2 = tip.indexOf("付") + 1
|
||||||
|
val end2 = tip.indexOf("元")
|
||||||
val spannableString = SpannableString(tip)
|
val spannableString = SpannableString(tip)
|
||||||
val colorSpan = ForegroundColorSpan(Color.parseColor("#0099EE"))
|
val colorSpan = ForegroundColorSpan(Color.parseColor("#0099EE"))
|
||||||
|
val colorSpan2 = ForegroundColorSpan(Color.parseColor("#0099EE"))
|
||||||
spannableString.setSpan(
|
spannableString.setSpan(
|
||||||
colorSpan,
|
colorSpan,
|
||||||
start,
|
start,
|
||||||
start + tipMoney.length,
|
end,
|
||||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
||||||
)
|
)
|
||||||
spannableString.setSpan(
|
spannableString.setSpan(
|
||||||
StyleSpan(Typeface.BOLD),
|
StyleSpan(Typeface.BOLD),
|
||||||
start,
|
start,
|
||||||
start + tipMoney.length,
|
end,
|
||||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
||||||
);
|
)
|
||||||
|
spannableString.setSpan(
|
||||||
|
colorSpan2,
|
||||||
|
start2,
|
||||||
|
end2,
|
||||||
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
|
spannableString.setSpan(
|
||||||
|
StyleSpan(Typeface.BOLD),
|
||||||
|
start2,
|
||||||
|
end2,
|
||||||
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
viewBinding.payMoneyView.text = spannableString
|
viewBinding.payMoneyView.text = spannableString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:text="请支付5元"
|
android:text="@string/pay_tip"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|
|
@ -694,7 +694,7 @@
|
||||||
<string name="payment_reminders">我们会在收到您的订单后24小时内充值进您的账户,请耐心等待。若您的订单未在24小时内处理,请向我们提交您的订单号申请处理.</string>
|
<string name="payment_reminders">我们会在收到您的订单后24小时内充值进您的账户,请耐心等待。若您的订单未在24小时内处理,请向我们提交您的订单号申请处理.</string>
|
||||||
<string name="pay">支付</string>
|
<string name="pay">支付</string>
|
||||||
<string name="pay_type">支付方式:</string>
|
<string name="pay_type">支付方式:</string>
|
||||||
<string name="pay_tip">请支付%1$s元</string>
|
<string name="pay_tip">请在%1$s内,支付%2$s元</string>
|
||||||
<string name="sava_code_and_copy_id">保存收款码,并复制备注</string>
|
<string name="sava_code_and_copy_id">保存收款码,并复制备注</string>
|
||||||
<string name="pay_tip2">我们已将二维码图像存放到了您的设备上。是否现在跳转至%1$s付款?</string>
|
<string name="pay_tip2">我们已将二维码图像存放到了您的设备上。是否现在跳转至%1$s付款?</string>
|
||||||
<string name="qq">QQ</string>
|
<string name="qq">QQ</string>
|
||||||
|
@ -815,4 +815,10 @@
|
||||||
<string name="experience_the_plan_describe">匿名发送软件奔溃信息(暂不可用)。</string>
|
<string name="experience_the_plan_describe">匿名发送软件奔溃信息(暂不可用)。</string>
|
||||||
<string name="update_and_iteration">版本更新与用户体验计划</string>
|
<string name="update_and_iteration">版本更新与用户体验计划</string>
|
||||||
<string name="setting_experience_the_plan">experiencePlan</string>
|
<string name="setting_experience_the_plan">experiencePlan</string>
|
||||||
|
<string name="order_timeout">订单超时,无法支付。</string>
|
||||||
|
<string name="is_paid">请问您付款了嘛?(未支付的订单将过期,无法再为其付款)。</string>
|
||||||
|
<string name="paid_yes">是的,我付款了</string>
|
||||||
|
<string name="paid_no">放弃订单</string>
|
||||||
|
<string name="preferential_price">已为您优惠%1$.2f元,仍然放弃订单嘛,放弃订单后不返还优惠券。</string>
|
||||||
|
<string name="paid_continue">继续支付</string>
|
||||||
</resources>
|
</resources>
|
|
@ -11,6 +11,7 @@
|
||||||
app:title="@string/reply_title"
|
app:title="@string/reply_title"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/appearance">
|
<PreferenceCategory android:title="@string/appearance">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user