package com.dollearn.student.ui.worldcup
|
|
import android.content.Intent
|
import android.os.Bundle
|
import android.view.View
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.activity.BaseActivity
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.myToast
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import cn.sinata.xldutils.visible
|
import com.github.zackratos.ultimatebar.UltimateBar
|
import com.google.gson.Gson
|
import com.dollearn.student.R
|
import com.dollearn.student.dialog.*
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.Banner
|
import com.dollearn.student.network.entity.Student
|
import com.dollearn.student.network.entity.WorldCupBean
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.H5Activity
|
import com.dollearn.student.ui.home.PayResultActivity
|
import com.dollearn.student.ui.home.adapter.HomeBannerAdapter
|
import com.dollearn.student.ui.home.adapter.StudentAdapter
|
import com.dollearn.student.utils.Const
|
import com.dollearn.student.utils.event.EmptyEvent
|
import com.dollearn.student.utils.extention.clickDelay
|
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_world_cup.*
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.startActivityForResult
|
import org.jetbrains.anko.textColorResource
|
|
class JoinWCActivity : BaseActivity(), PayListener {
|
|
private val match by lazy { intent.getParcelableExtra<WorldCupBean>("match") as WorldCupBean }
|
private val bannerImg = arrayListOf<Banner>()
|
private val bannerAdapter by lazy {
|
HomeBannerAdapter(bannerImg, this)
|
}
|
|
private val students = arrayListOf<Student>()
|
private val studentAdapter = StudentAdapter(students, StudentAdapter.TYPE_MATCH_DETAIL)
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
setContentView(R.layout.activity_join_world_cup)
|
initView()
|
initClick()
|
}
|
|
fun initClick() {
|
tv_add_student.clickDelay {
|
ChooseStudentDialog.show(supportFragmentManager,
|
ChooseStudentDialog.TYPE_WORLD,students,object : ChooseStudentDialog.ResultCallback{
|
override fun checked(list: List<Student>) {
|
students.clear()
|
students.addAll(list)
|
studentAdapter.notifyDataSetChanged()
|
}
|
},null,true,match.gender,match.age)
|
}
|
tv_action.setOnClickListener {
|
if (cb_rule.isChecked){
|
if (students.isEmpty())
|
myToast("请添加参赛人员")
|
else if (match.storeInfos?.size == 1){
|
match.storeInfos?.firstOrNull()?.let {
|
ConfirmShopDialog.show(supportFragmentManager,it.storeCoverDrawing?:"",it.name?:"",it.address?:"",
|
if (it.distance == null) "" else "${it.distance}km",object :StringCallback{
|
override fun onResult(rst: String) {
|
if (tv_price.text == "免费"){
|
pay(3)
|
}else
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
},students.size*((match.cash?:"0.0").toDouble()),students.size*((match.paiCoin?:"0.0").toDouble().toInt()),students.size*((match.classHour?:"0.0").toDouble().toInt()),null,students.filter { it.isStudent == 0 }.isNullOrEmpty())
|
}
|
},ConfirmShopDialog.TYPE_WORLD)
|
}
|
}else{
|
ConfirmShopsDialog.show(supportFragmentManager,match.storeInfos?.joinToString("\n") { it.name }?:"",object :StringCallback{
|
override fun onResult(rst: String) {
|
if (tv_price.text == "免费"){
|
pay(3)
|
}else
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
},students.size*((match.cash?:"0.0").toDouble()),students.size*((match.paiCoin?:"0.0").toDouble().toInt()),students.size*((match.classHour?:"0.0").toDouble().toInt()),null,students.filter { it.isStudent == 0 }.isNullOrEmpty())
|
}
|
})
|
}
|
}else
|
myToast("请阅读并同意《社区世界杯报名协议》")
|
}
|
tv_rule.setOnClickListener {
|
HttpManager.getH5(5).request(this@JoinWCActivity){ _, data->
|
data?.let {
|
startActivityForResult<H5Activity>(1,"title" to "社区世界杯报名协议","url" to it)
|
}
|
}
|
}
|
}
|
|
fun initView() {
|
titleBar.titleView.text = title
|
titleBar.titleView.textColorResource = R.color.white
|
titleBar.leftView.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.back_white,0,0,0)
|
UltimateBar.with(this)
|
.statusDark(false)
|
.create().transparentBar() //沉浸状态栏
|
banner.adapter = bannerAdapter
|
rv_student.layoutManager = LinearLayoutManager(this)
|
rv_student.adapter = studentAdapter
|
studentAdapter.delCallback = object : StringCallback {
|
override fun onResult(rst: String) {
|
students.removeAt(rst.toInt())
|
studentAdapter.notifyDataSetChanged()
|
}
|
}
|
match.apply {
|
if (registrationClosingTime.isNullOrEmpty())
|
registrationClosingTime = endTime
|
storeInfos?.let {
|
val stores = StringBuffer()
|
for (s in it.indices) {
|
if (s == it.size - 1) stores.append(it[s].name)
|
else stores.append(it[s].name + ",")
|
}
|
tv_shops.text = stores
|
if (stores.length > 20) {
|
mtvcheckmore.visible()
|
mtvcheckmore.clickDelay {
|
val checkShopsDialog = CheckShopsDialog()
|
checkShopsDialog.arguments =
|
bundleOf("shopinfo" to stores.toString(),"type" to CheckShopsDialog.TYPE_WORLD_SITE)
|
checkShopsDialog.showAllowingStateLoss(
|
supportFragmentManager,
|
"checkshops"
|
)
|
}
|
} else {
|
mtvcheckmore.gone()
|
}
|
}
|
|
val list = infoImg.split(",").map {
|
Banner(url = it)
|
}
|
bannerImg.addAll(list)
|
bannerAdapter.notifyDataSetChanged()
|
tv_name.text = name
|
tv_hot.text = heat.toString()
|
tv_deadline.text = registrationClosingTime
|
tv_start_time.text = startTime
|
tv_end_time.text = endTime
|
tv_age.text = "${age}岁"
|
tv_sex.text = getJoinSex()
|
tv_city.text = "${province}|${city}"
|
tv_play_address.text = address
|
if (cash!=null&&cash.toDouble()!=0.0){
|
val price = "支付:¥%s/人".format(cash)
|
tv_price.text = SpanBuilder(price).color(this@JoinWCActivity,0,3,R.color.textColor66).bold(3,price.length).build()
|
tv_price.visible()
|
}
|
if (paiCoin!=null&&paiCoin.toDouble()!=0.0){
|
val coin = "玩湃币:%s币/人".format(paiCoin)
|
tv_coin.text = SpanBuilder(coin).color(this@JoinWCActivity,0,4,R.color.textColor66).bold(4,coin.length).build()
|
tv_coin.visible()
|
}
|
if (classHour!=null&&classHour.toDouble()!=0.0){
|
val time = "课时:%s课时/人".format(classHour)
|
tv_course_time.text = SpanBuilder(time).color(this@JoinWCActivity,0,3,R.color.textColor66).bold(3,time.length).build()
|
tv_course_time.visible()
|
}
|
if (tv_price.visibility == View.GONE&&tv_coin.visibility == View.GONE&&tv_course_time.visibility == View.GONE){ //免费课
|
tv_price.visible()
|
tv_price.text = "免费"
|
}
|
}
|
PayUtil.addPayListener(this)
|
}
|
|
private fun pay(payType:Int,coursePaymentId:String? = null){
|
// if (payType == 4&&coursePaymentId == null){//课时支付 //todo 蒲志兵:课时支付暂时由他判断
|
// HttpManager.paymentCompetitionCourseList(match.id).request(this){_,data->
|
// val list = arrayListOf<PayCourse>()
|
// list.addAll(data?: arrayListOf())
|
// if (list.isEmpty())
|
// myToast("暂无可用课时")
|
// else
|
// CoursePayDialog.show(supportFragmentManager,object :StringCallback{
|
// override fun onResult(rst: String) {
|
// pay(payType, rst)
|
// }
|
// },students.size*((match.classPrice?:"0").toInt()), list)
|
// }
|
// }else
|
|
HttpManager.paymentWorldCup(match.id, Gson().toJson(students),payType).request(this,false,success = {_,data->
|
if (payType == 2){
|
PayUtil.aliPay(this,data?.orderInfo?:"")
|
}else if (payType == 3||payType == 4){
|
EventBus.getDefault().post(EmptyEvent(Const.EventCode.REFRESH_USER)) //玩湃币支付后刷新首页
|
onPaySuccess()
|
}else{
|
PayUtil.initWeChatPay(this, Const.WX_APP_ID)
|
PayUtil.weChatPay(data!!)
|
}
|
}){_,msg->
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_WORLD_FAILED,"msg" to msg)
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
PayUtil.removePayListener(this)
|
PayUtil.unregisterApp()
|
}
|
|
override fun onPaySuccess() {
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_WORLD_SUC)
|
finish()
|
}
|
|
override fun onPayCancel() {
|
}
|
|
override fun onPayError(msg: String) {
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_WORLD_FAILED)
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == RESULT_OK&&requestCode == 1){
|
tv_action.postDelayed({
|
if (tv_price.text == "免费"){
|
pay(3)
|
}else
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
},students.size*((match.cash?:"0.0").toDouble()),students.size*((match.paiCoin?:"0.0").toDouble().toInt()),students.size*((match.classHour?:"0.0").toDouble().toInt()),null,students.filter { it.isStudent == 0 }.isNullOrEmpty())
|
},500)
|
}
|
}
|
|
}
|