lmw
2024-06-18 1f45a54dc8e149548d3a61d1228741627aa4f23e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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)
                }
            }
        }
    }
 
}