package com.dollearn.student.ui.worldcup
|
|
import android.os.Bundle
|
import android.view.View
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import androidx.fragment.app.Fragment
|
import androidx.viewpager.widget.ViewPager
|
import cn.sinata.xldutils.activity.BaseActivity
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import cn.sinata.xldutils.utils.toTime
|
import cn.sinata.xldutils.visible
|
import com.github.zackratos.ultimatebar.UltimateBar
|
import com.dollearn.student.R
|
import com.dollearn.student.dialog.CheckQrCodeDialog
|
import com.dollearn.student.dialog.SwitchStudentDialog
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.Student
|
import com.dollearn.student.network.entity.WorldRank
|
import com.dollearn.student.network.request
|
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.getQRcodeImg
|
import kotlinx.android.synthetic.main.activity_my_world_cup.*
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.textColorResource
|
|
class MyWorldActivity : BaseActivity() {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
setContentView(R.layout.activity_my_world_cup)
|
initView()
|
initClick()
|
}
|
|
val rbCity by lazy {
|
find<TextView>(R.id.rb_city)
|
}
|
val rbCountry by lazy {
|
find<TextView>(R.id.rb_country)
|
}
|
|
private val index by lazy { intent.getIntExtra("index",0) }
|
var stu:Student? = null
|
var cityName = ""
|
|
var mineRank: WorldRank? = null //我的排名
|
|
|
fun initClick() {
|
iv_code.clickDelay {
|
if (stu == null)
|
return@clickDelay
|
val dialog = CheckQrCodeDialog()
|
val content = "{\"id\":${stu?.id},\"isStudent\":${stu?.isStudent}}"
|
dialog.arguments = bundleOf("qrinfo" to content,"title" to stu?.name)
|
dialog.showAllowingStateLoss(supportFragmentManager, "checkqr")
|
}
|
tv_change.clickDelay {
|
SwitchStudentDialog.show(supportFragmentManager,stu,object :SwitchStudentDialog.ResultCallback{
|
override fun checked(list: List<Student>) {
|
if (!list.isNullOrEmpty()){
|
stu = list.firstOrNull()
|
stu?.apply {
|
iv_avatar.setImageURI(avatar)
|
tv_name.text = name
|
val content = "{\"id\":${id},\"isStudent\":${isStudent}}"
|
iv_code.setImageBitmap(getQRcodeImg(this@MyWorldActivity, content))
|
getRank()
|
}
|
}
|
}
|
})
|
}
|
}
|
|
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() //沉浸状态栏
|
tv_year.text = "您的${System.currentTimeMillis().toTime("yyyy")}年场次排名"
|
rb_city.isSelected = true
|
getUser()
|
}
|
|
private fun initTab(){
|
val frags = arrayListOf<Fragment>()
|
frags.add(MyWorldFragment.newInstance(MyWorldFragment.TYPE_DOING))
|
frags.add(MyWorldFragment.newInstance(MyWorldFragment.TYPE_UN_START))
|
frags.add(WorldRecordFragment())
|
frags.add(WorldRankFragment())
|
tab_bar.setViewPager(view_pager, arrayOf("进行中","未开始","比赛记录","排名"),this,frags)
|
view_pager.currentItem = index
|
view_pager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
|
override fun onPageScrolled(
|
position: Int,
|
positionOffset: Float,
|
positionOffsetPixels: Int
|
) {
|
|
}
|
|
override fun onPageSelected(position: Int) {
|
rg_region.visibility = if (position == 3) View.VISIBLE else View.GONE
|
if (position == 3) showMineRank() else bg.gone()
|
}
|
|
override fun onPageScrollStateChanged(state: Int) {
|
|
}
|
})
|
}
|
|
fun showMineRank(){
|
bg.visibility = if (mineRank!=null){
|
when(mineRank!!.rank){
|
1->{
|
tv_rank.gone()
|
iv_rank.visible()
|
iv_rank.setImageResource(R.mipmap.goldmedal)
|
}
|
2->{
|
tv_rank.gone()
|
iv_rank.visible()
|
iv_rank.setImageResource(R.mipmap.silvermedal)
|
}
|
3->{
|
tv_rank.gone()
|
iv_rank.visible()
|
iv_rank.setImageResource(R.mipmap.bronzemedal)
|
}
|
else->{
|
tv_rank.visible()
|
iv_rank.gone()
|
tv_rank.text = mineRank!!.rank.toString()
|
}
|
}
|
iv_mine_avatar.setImageURI(mineRank!!.avatar)
|
tv_mine_name.text = mineRank!!.name
|
tv_count.text = mineRank!!.totalSession.toString()
|
tv_rate.text = "%.2f".format(mineRank!!.winRate)+"%"
|
View.VISIBLE
|
}else View.GONE
|
|
}
|
|
private fun getUser() {
|
HttpManager.getParticipant().request(this){ _, data->
|
data?.firstOrNull()?.apply {
|
stu = this
|
initTab()
|
iv_avatar.setImageURI(avatar)
|
tv_name.text = name
|
val content = "{\"id\":${id},\"isStudent\":${isStudent}}"
|
iv_code.setImageBitmap(getQRcodeImg(this@MyWorldActivity, content))
|
getRank()
|
}
|
}
|
}
|
|
private fun getRank(){
|
HttpManager.getEntrantRank(stu?.id?:"",stu?.isStudent?:0).request(this){_,data->
|
data?.apply {
|
this@MyWorldActivity.cityName = cityName
|
rb_city.text = cityName
|
tv_rank_country.text = nationalRank.toString()
|
tv_rank_city.text = cityRank.toString()
|
tv_city.text = cityName+"排名"
|
tv_win.text = win
|
tv_lose.text = lose
|
val s = "%.2f".format(winRate)+"%"
|
tv_win_rate.text = SpanBuilder(s).size(s.length-1,s.length,15).build()
|
}
|
}
|
}
|
|
}
|