package com.dollearn.student.ui.home
|
|
import android.content.Intent
|
import cn.sinata.xldutils.callPhone
|
import cn.sinata.xldutils.utils.optString
|
import com.dollearn.student.R
|
import com.dollearn.student.WeparkApplication
|
import com.dollearn.student.dialog.PayDialog
|
import com.dollearn.student.network.Apis
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.utils.Const
|
import com.dollearn.student.utils.event.EmptyEvent
|
import com.dollearn.student.utils.extention.loadLongImage
|
import com.dollearn.student.utils.interfaces.StringCallback
|
import com.dollearn.student.utils.pay.PayListener
|
import com.dollearn.student.utils.pay.PayUtil
|
import kotlinx.android.synthetic.main.activity_join_vip.*
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.startActivityForResult
|
|
class JoinVipActivity : TransparentStatusBarActivity(), PayListener {
|
override fun setContentView() = R.layout.activity_join_vip
|
|
private val type by lazy { intent.getIntExtra("type", TYPE_VIP) }
|
private var phone:String? = null
|
|
override fun initClick() {
|
bg_action.setOnClickListener {
|
if (type == TYPE_FREE)
|
callPhone(phone)
|
else
|
PayDialog.show(supportFragmentManager,true,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
})
|
}
|
}
|
|
override fun initView() {
|
if (type == TYPE_FREE){
|
title = "免费福利"
|
tv_action.text = "联系我们"
|
tv_action.setCompoundDrawablesRelativeWithIntrinsicBounds(R.mipmap.iv_phone,0,0,0)
|
getFree()
|
}else{
|
getImage()
|
PayUtil.addPayListener(this)
|
}
|
}
|
|
private fun getFree(){
|
HttpManager.queryStoreFreeBenefit(WeparkApplication.storeId).request(this){_,data->
|
phone = data?.optString("phone")
|
data?.optString("img")?.loadLongImage(this,iv_img)
|
}
|
}
|
|
private fun getImage(){
|
val map = hashMapOf<String, Any>()
|
map["position"] = 2
|
HttpManager.queryString(Apis.querySystemImg,map).request(this){_,data->
|
data?.loadLongImage(this,iv_img)
|
}
|
}
|
|
private fun pay(payType:Int){
|
HttpManager.addVipPayment(payType).request(this){_,data->
|
if (payType == 2){
|
PayUtil.aliPay(this,data?.orderInfo?:"")
|
}else{
|
PayUtil.weChatPay(data!!)
|
}
|
}
|
}
|
|
override fun onPaySuccess() {
|
EventBus.getDefault().post(EmptyEvent(Const.EventCode.REFRESH_USER)) //成为会员后刷新首页
|
startActivity<PayResultActivity>()
|
finish()
|
}
|
|
override fun onPayCancel() {
|
|
}
|
|
override fun onPayError(msg: String) {
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_VIP_FAILED)
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == RESULT_OK){
|
tv_action.postDelayed({
|
tv_action.callOnClick()
|
},500)
|
}
|
}
|
|
override fun onDestroy() {
|
if (type == TYPE_VIP)
|
PayUtil.removePayListener(this)
|
super.onDestroy()
|
}
|
|
companion object{
|
const val TYPE_VIP = 0 //VIP
|
const val TYPE_FREE = 1 //免费福利
|
}
|
}
|