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
package com.dollearn.student.ui.welfare
 
import android.annotation.SuppressLint
import android.webkit.WebChromeClient
import android.webkit.WebViewClient
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.visible
import com.dollearn.student.R
import com.dollearn.student.dialog.LoginRuleDialog
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.entity.Banner
import com.dollearn.student.network.entity.ExchangeDetail
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.home.adapter.HomeBannerAdapter
import com.dollearn.student.utils.extention.clickDelay
import com.youth.banner.indicator.CircleIndicator
import kotlinx.android.synthetic.main.activity_exchange_detail.*
 
@SuppressLint("SetTextI18n")
class ExchangeDetailActivity : TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_exchange_detail
 
    private val id by lazy { intent.getStringExtra("id")?:"" }
    private val bannerImg = arrayListOf<Banner>()
    private val bannerAdapter by lazy {
        HomeBannerAdapter(bannerImg, this)
    }
    private var exchangeDetail: ExchangeDetail? = null
 
    override fun initClick() {
        tv_shop.clickDelay {
            LoginRuleDialog.show(
                supportFragmentManager,
                exchangeDetail?.belongs ?: "",
                LoginRuleDialog.TYPE_COUPON_USAGE
            )
        }
    }
 
    override fun initView() {
        banner.adapter = bannerAdapter
        banner.indicator = CircleIndicator(this)
        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() {}
        getData()
    }
 
 
    private fun getData() {
        HttpManager.redemptionDetails(id).request(this) { _, data ->
            exchangeDetail = data
            data?.apply {
                bannerImg.addAll((pics ?: arrayListOf()).map { Banner(url = it) })
                bannerAdapter.notifyDataSetChanged()
                banner.currentItem = 1
                tv_name.text = goodName
                tv_price.text =
                    if (exchangeType == 2) "${integral}积分+¥${cash}" else if (exchangeType == 3) "¥${cash}" else "${integral}积分"
                tv_deadline.text = "${startTime}至${endTime}"
                tv_order_time.text = orderTime
                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 + contents, "text/html", "utf-8", null)
                if (useType == 1) { //1已使用 2未使用
                    iv_used.visible()
                    ll_used.visible()
                    tv_use_time.text = writeOffTime
                    tv_use_shop.text = writeOffName
                } else {
                    iv_used.gone()
                    ll_target_shop.visible()
                }
 
                when (goodType) {
                    2 -> {
                        rl_classhour.visible()
                        mtvClassHour.text = "${classHours}课时"
                        tv_deadline.gone()
                        tv_1.gone()
                    }
                    3 -> {
                        rl_type.visible()
                        mtvFeeType.text = cardType?.let {
                            when (it) {
                                // 1日卡 2月卡 3季卡 4年卡
                                1 -> "日卡"
                                2 -> "月卡"
                                3 -> "季卡"
                                4 -> "年卡"
                                else -> ""
                            }
                        } ?: ""
                    }
                }
            }
        }
    }
 
}