package com.dollearn.student.ui.home
|
|
import android.content.Intent
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.LinearLayoutManager
|
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.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.Match
|
import com.dollearn.student.network.entity.PayCourse
|
import com.dollearn.student.network.entity.Student
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
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_match.*
|
import kotlinx.android.synthetic.main.activity_join_match.banner
|
import kotlinx.android.synthetic.main.activity_join_match.mtvcheckmore
|
import kotlinx.android.synthetic.main.activity_join_match.tv_action
|
import kotlinx.android.synthetic.main.activity_join_match.tv_address
|
import kotlinx.android.synthetic.main.activity_join_match.tv_age
|
import kotlinx.android.synthetic.main.activity_join_match.tv_city
|
import kotlinx.android.synthetic.main.activity_join_match.tv_coin
|
import kotlinx.android.synthetic.main.activity_join_match.tv_condition
|
import kotlinx.android.synthetic.main.activity_join_match.tv_course_time
|
import kotlinx.android.synthetic.main.activity_join_match.tv_deadline
|
import kotlinx.android.synthetic.main.activity_join_match.tv_end_time
|
import kotlinx.android.synthetic.main.activity_join_match.tv_introduce
|
import kotlinx.android.synthetic.main.activity_join_match.tv_name
|
import kotlinx.android.synthetic.main.activity_join_match.tv_play_address
|
import kotlinx.android.synthetic.main.activity_join_match.tv_price
|
import kotlinx.android.synthetic.main.activity_join_match.tv_shops
|
import kotlinx.android.synthetic.main.activity_join_match.tv_start_time
|
import kotlinx.android.synthetic.main.activity_match_deatil.*
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.startActivityForResult
|
|
class JoinMatchActivity:TransparentStatusBarActivity(), PayListener {
|
override fun setContentView() = R.layout.activity_join_match
|
|
private val match by lazy { intent.getParcelableExtra<Match>("match") as Match }
|
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 initClick() {
|
tv_add_student.clickDelay {
|
ChooseStudentDialog.show(supportFragmentManager,ChooseStudentDialog.TYPE_MATCH,students,object :ChooseStudentDialog.ResultCallback{
|
override fun checked(list: List<Student>) {
|
students.clear()
|
students.addAll(list)
|
studentAdapter.notifyDataSetChanged()
|
}
|
},null,match.isReal == 1)
|
}
|
|
tv_action.clickDelay {
|
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) {
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
},students.size*((match.cashPrice?:"0.0").toDouble()),students.size*((match.playPaiCoin?:"0").toInt()),students.size*((match.classPrice?:"0").toInt()),null,students.filter { it.isStudent == 0 }.isNullOrEmpty())
|
}
|
})
|
}
|
}else{
|
ConfirmShopsDialog.show(supportFragmentManager,match.storeInfos?.joinToString("\n") { it.name }?:"",object :StringCallback{
|
override fun onResult(rst: String) {
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
},students.size*((match.cashPrice?:"0.0").toDouble()),students.size*((match.playPaiCoin?:"0").toInt()),students.size*((match.classPrice?:"0").toInt()),null,students.filter { it.isStudent == 0 }.isNullOrEmpty())
|
}
|
})
|
}
|
}
|
}
|
}
|
|
override fun initView() {
|
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 {
|
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 > 40) {
|
mtvcheckmore.visible()
|
mtvcheckmore.clickDelay {
|
val checkShopsDialog = CheckShopsDialog()
|
checkShopsDialog.arguments =
|
bundleOf("shopinfo" to stores.toString())
|
checkShopsDialog.showAllowingStateLoss(
|
supportFragmentManager,
|
"checkshops"
|
)
|
}
|
} else {
|
mtvcheckmore.gone()
|
}
|
}
|
|
val list = imgs.split(",").map {
|
Banner(url = it)
|
}
|
bannerImg.addAll(list)
|
bannerAdapter.notifyDataSetChanged()
|
tv_name.text = name
|
tv_condition.text = getCondition()+"参与"
|
tv_address.text = "${storeName}(${storeAddress})"
|
tv_deadline.text = registerEndTime
|
tv_start_time.text = startTime
|
tv_end_time.text = endTime
|
tv_age.text = age
|
tv_city.text = "${province}|${city}"
|
tv_play_address.text = address
|
if (cashPrice!=null&&cashPrice.toDouble()!=0.0){
|
val price = "支付:¥%s/人".format(cashPrice)
|
tv_price.text = SpanBuilder(price).color(this@JoinMatchActivity,0,3,R.color.textColor66).bold(3,price.length).build()
|
tv_price.visible()
|
}
|
if (playPaiCoin!=null&&playPaiCoin.toInt()!=0){
|
val coin = "玩湃币:%s币/人".format(playPaiCoin)
|
tv_coin.text = SpanBuilder(coin).color(this@JoinMatchActivity,0,4,R.color.textColor66).bold(4,coin.length).build()
|
tv_coin.visible()
|
}
|
if (classPrice!=null&&classPrice.toInt()!=0){
|
val time = "课时:%s课时/人".format(classPrice)
|
tv_course_time.text = SpanBuilder(time).color(this@JoinMatchActivity,0,3,R.color.textColor66).bold(3,time.length).build()
|
tv_course_time.visible()
|
}
|
tv_introduce.text = introduction
|
}
|
PayUtil.addPayListener(this)
|
}
|
|
private fun pay(payType:Int,coursePaymentId:String? = null){
|
if (payType == 4&&coursePaymentId == null){//课时支付
|
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.paymentCompetition(payType,match.id, Gson().toJson(students),coursePaymentId).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_COURSE_FAILED,"msg" to msg)
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == RESULT_OK&&requestCode == 1){
|
tv_action.postDelayed({
|
PayDialog.show(supportFragmentManager,false,object :StringCallback{
|
override fun onResult(rst: String) {
|
pay(rst.toInt())
|
}
|
|
},students.size*((match.cashPrice?:"0.0").toDouble()),students.size*((match.playPaiCoin?:"0").toInt()),students.size*((match.classPrice?:"0").toInt()))
|
},500)
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
PayUtil.removePayListener(this)
|
PayUtil.unregisterApp()
|
}
|
|
override fun onPaySuccess() {
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_MATCH_SUC)
|
finish()
|
}
|
|
override fun onPayCancel() {
|
}
|
|
override fun onPayError(msg: String) {
|
startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_MATCH_FAILED)
|
}
|
|
}
|