package com.dollearn.student.ui.worldcup
|
|
import android.webkit.WebChromeClient
|
import android.webkit.WebViewClient
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.parserTime
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import cn.sinata.xldutils.visible
|
import com.dollearn.student.R
|
import com.dollearn.student.dialog.CheckShopsDialog
|
import com.dollearn.student.dialog.TipDialog
|
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.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.ui.home.adapter.HomeBannerAdapter
|
import com.dollearn.student.ui.worldcup.adapter.StudentQrAdapter
|
import com.dollearn.student.utils.Const
|
import com.dollearn.student.utils.event.EmptyEvent
|
import com.dollearn.student.utils.extention.clickDelay
|
import kotlinx.android.synthetic.main.activity_my_world_detail.*
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.backgroundColorResource
|
|
class MyWorldInfoActivity:TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_my_world_detail
|
|
private val id by lazy { intent.getStringExtra("id")?:"" }
|
|
private val bannerImg = arrayListOf<Banner>()
|
private val bannerAdapter by lazy {
|
HomeBannerAdapter(bannerImg, this)
|
}
|
|
private val students = arrayListOf<Student>()
|
private val studentAdapter = StudentQrAdapter(students)
|
|
override fun initClick() {
|
tv_action.clickDelay {
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf("msg" to "是否确认取消?")
|
tipDialog.setCallback(object :TipDialog.OnClickCallback{
|
override fun onOk() {
|
HttpManager.cancelMyWorldCup(id).request(this@MyWorldInfoActivity){_,data->
|
tv_action.isEnabled = false
|
tv_action.backgroundColorResource = R.color.disableColor
|
tv_action.text = "已取消"
|
}
|
}
|
|
override fun onCancel() {
|
}
|
|
})
|
tipDialog.show(supportFragmentManager,"cancel")
|
}
|
}
|
|
override fun initView() {
|
banner.adapter = bannerAdapter
|
rv_student.layoutManager = LinearLayoutManager(this)
|
rv_student.adapter = studentAdapter
|
getData()
|
}
|
|
private fun getData() {
|
HttpManager.getMyWorldCupInfo(id).request(this){_,data->
|
data?.apply {
|
if (status in 2..4){
|
tv_action.isEnabled = false
|
tv_action.backgroundColorResource = R.color.disableColor
|
tv_action.text = getStateStr()
|
}else if (startTime.parserTime("yyyy-MM-dd HH:mm") - System.currentTimeMillis() < 1000L*24*60*60){//开始前一天不能取消
|
tv_action.text = "取消"
|
tv_action.isEnabled = false
|
tv_action.backgroundColorResource = R.color.disableColor
|
}
|
tv_action.visible()
|
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()
|
banner.currentItem = 1
|
tv_name.text = name
|
tv_hot.text = heat.toString()
|
// tv_address.text = "${storeName}(${storeAddress})"
|
tv_deadline.text = if (registrationClosingTime.isNullOrEmpty()) endTime else 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
|
|
students.addAll(participants?: arrayListOf())
|
studentAdapter.notifyDataSetChanged()
|
|
when(payType){//支付方式(0=免费,1=微信,2=支付宝,3=玩湃币,4=课时)
|
0->{
|
tv_price.text = "免费"
|
tv_total.text = "免费"
|
}
|
1,2->{
|
tv_price.text = "¥%.2f/人".format(unitPrice?:0.0)
|
tv_total.text = "合计:¥%.2f".format((unitPrice?:0.0)*(participants?.size?:0))
|
}
|
3->{
|
tv_price.text = "%d玩湃币/人".format((unitPrice?:0.0).toInt())
|
tv_total.text = "合计:%d玩湃币".format(((unitPrice?:0.0)*(participants?.size?:0)).toInt())
|
}
|
4->{
|
tv_price.text = "%d课时/人".format((unitPrice?:0.0).toInt())
|
tv_total.text = "合计:%d课时".format(((unitPrice?:0.0)*(participants?.size?:0)).toInt())
|
}
|
}
|
|
tv_introduce.text = intro
|
if (!content.isNullOrEmpty()) {
|
val settings = webView.settings
|
settings.javaScriptEnabled = true
|
settings.javaScriptCanOpenWindowsAutomatically = true
|
settings.defaultTextEncodingName = "utf-8"
|
settings.domStorageEnabled = true
|
webView.webChromeClient = object : WebChromeClient() {}
|
webView.webViewClient = object : WebViewClient() {}
|
val sHead =
|
"<html><head><meta name=\"viewport\" content=\"width=device-width, " + "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />" + "<style>img{max-width:100% !important;height:auto !important;}</style>" + "<style>body{max-width:100% !important;}</style>" + "</head><body>"
|
webView!!.loadDataWithBaseURL(null, sHead + content, "text/html", "utf-8", null)
|
}
|
}
|
}
|
}
|
|
}
|