package com.dollearn.student.dialog
|
|
import android.view.Gravity
|
import androidx.core.os.bundleOf
|
import androidx.fragment.app.FragmentManager
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import com.dollearn.student.R
|
import com.dollearn.student.utils.extention.clickDelay
|
import com.dollearn.student.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.dialog_pay.*
|
import org.jetbrains.anko.support.v4.toast
|
|
class PayDialog: BaseDialogFragment() {
|
override fun setContentView() = R.layout.dialog_pay
|
|
private val isVip by lazy {
|
arguments?.getBoolean("isVip",false)?:false
|
}
|
private val coin by lazy {//玩湃币
|
arguments?.getInt("coin",0)?:0
|
}
|
private val course by lazy {//课时
|
arguments?.getInt("course",0)?:0
|
}
|
private val integral by lazy { //积分
|
arguments?.getInt("integral",0)?:0
|
}
|
private val price by lazy {//钱
|
arguments?.getDouble("price",0.0)?:0.0
|
}
|
private val courseEnable by lazy { //课时支付是否可用,不可用需将按钮置灰
|
arguments?.getBoolean("courseEnable",true)?:true
|
}
|
var callback:StringCallback? = null
|
|
override fun setGravity() = Gravity.BOTTOM
|
|
override fun initView() {
|
if (isVip){
|
tv_coin.gone()
|
line.gone()
|
tv_course.gone()
|
line3.gone()
|
tv_integral.gone()
|
line4.gone()
|
tv_wx.text = SpanBuilder("微信支付 ¥199").color(requireContext(),0,4,R.color.textColor66).build()
|
tv_ali.text = SpanBuilder("支付宝支付 ¥199").color(requireContext(),0,5,R.color.textColor66).build()
|
}else{
|
if (price == 0.0){
|
line1.gone()
|
line2.gone()
|
tv_wx.gone()
|
tv_ali.gone()
|
tv_coin.isChecked = true
|
}else{
|
tv_wx.text = SpanBuilder("微信支付 ¥%.2f".format(price)).color(requireContext(),0,4,R.color.textColor66).build()
|
tv_ali.text = SpanBuilder("支付宝支付 ¥%.2f".format(price)).color(requireContext(),0,5,R.color.textColor66).build()
|
}
|
if (coin == 0){
|
tv_coin.gone()
|
line.gone()
|
}else
|
tv_coin.text = SpanBuilder("玩湃币支付 ${coin}币").color(requireContext(),0,5,R.color.textColor66).build()
|
if (course == 0){
|
tv_course.gone()
|
line3.gone()
|
}else{
|
tv_course.text = SpanBuilder("课时支付 ${course}课时").color(requireContext(),0,4,R.color.textColor66).build()
|
if (!courseEnable){
|
tv_course.isEnabled = false
|
tv_course.alpha = 0.5f
|
}
|
}
|
|
if (integral == 0){
|
tv_integral.gone()
|
line4.gone()
|
}else
|
tv_integral.text = SpanBuilder("积分支付 ${integral}积分").color(requireContext(),0,4,R.color.textColor66).build()
|
}
|
tv_cancel.setOnClickListener {
|
dismissAllowingStateLoss()
|
}
|
tv_pay.clickDelay {
|
// val type = if (tv_ali.isChecked) 2 else if (tv_wx.isChecked) 1 else 3
|
val type = when(rg_pay.checkedRadioButtonId){
|
R.id.tv_ali->2
|
R.id.tv_wx->1
|
R.id.tv_integral->5
|
R.id.tv_coin->3
|
else->4
|
}
|
callback?.onResult(type.toString())
|
dismissAllowingStateLoss()
|
}
|
}
|
|
companion object{
|
/**
|
* @param courseEnable 赛事可以用课时支付,但当参赛学员有非学员身份时,课时支付需要置灰
|
*/
|
fun show(fm:FragmentManager,isVip:Boolean,callback:StringCallback,price:Double? = null,coin:Int? = null,course:Int? = null,integral:Int? = null,courseEnable:Boolean? = null){
|
val payDialog = PayDialog()
|
payDialog.arguments = bundleOf("isVip" to isVip,"price" to price,"coin" to coin,"course" to course,"integral" to integral,"courseEnable" to courseEnable)
|
payDialog.callback = callback
|
payDialog.showAllowingStateLoss(fm,"pay")
|
}
|
}
|
|
}
|