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
package com.dollearn.student.ui.course
 
import android.annotation.SuppressLint
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.GridLayoutManager
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.dialog.GetMyCourseDialog
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.home.PayResultActivity
import com.dollearn.student.ui.home.adapter.ChooseCoursTimesAdapter
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 kotlinx.android.synthetic.main.activity_experiencecourse_layout.*
import kotlinx.android.synthetic.main.item_exchange_record.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
@SuppressLint("SetTextI18n")
class ExperienceCourseActivity : TransparentStatusBarActivity() {
    override fun setContentView(): Int {
        return R.layout.activity_experiencecourse_layout
    }
 
    private val classTimeAdapter by lazy {
        ChooseCoursTimesAdapter(arrayListOf())
    }
 
    private val stuId by lazy { intent.getStringExtra("stuId")?:"" }
 
    override fun initClick() {
        tv_pay.clickDelay {
            if (classTimeAdapter.checkeds.size == 0) {
                toast("请选择上课时间")
                return@clickDelay
            }
            HttpManager.getMyCourseList().request(this) { _, data ->
                data?.let {
                    val dialog = GetMyCourseDialog(object : StringCallback {
                        override fun onResult(rst: String) {
                            val time = classTimeAdapter.checkeds.map {
                                classTimeAdapter.mData[it].replace(".", "-")
                            }
                            HttpManager.payCourse(HashMap<String, Any>().apply {
                                this["stuId"] = stuId
                                this["courseId"] = id
                                this["num"] = classHours
                                this["oldCourseId"] = rst.toLong()
                            }, time).request(this@ExperienceCourseActivity, success = { _, data ->
                                run {
                                    startActivity<PayResultActivity>("type" to PayResultActivity.TYPE_PAYCOURSSUCCESS)
                                    EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_COURSDATA))
                                    finish()
                                }
                            }, error = { _, data ->
                                run {
                                    startActivity<PayResultActivity>("type" to PayResultActivity.TYPE_PAYCOURFAILED)
                                }
                            })
                        }
                    })
                    dialog.arguments =
                        bundleOf(
                            "data" to it,
                            "classHour" to classHours
                        )
                    dialog.showAllowingStateLoss(
                        (this@ExperienceCourseActivity).supportFragmentManager,
                        "mycourse"
                    )
 
                }
 
            }
        }
 
    }
 
    val id by lazy {
        intent.getIntExtra("id", -1)
    }
 
    var classHours = 0
 
    @SuppressLint("NotifyDataSetChanged")
    override fun initView() {
        rv_class_hour.layoutManager = GridLayoutManager(this, 4)
        rv_class_hour.adapter = classTimeAdapter
        HttpManager.payCourseInfo(id).request(this) { _, data ->
            data?.let { it ->
                mtvCourseName.text = it.name
                mtvClassHour.text = "${it.num}课时"
                mtvClassTimeWeek.text = it.week
                mtvClassTime.text = it.time.joinToString("  ")
 
 
                classTimeAdapter.setOnItemClickListener { _, position ->
                    if (classTimeAdapter.checkeds.contains(position)) {
                        classTimeAdapter.checkeds.remove(position)
                    } else classTimeAdapter.checkeds.add(position)
                    classTimeAdapter.notifyDataSetChanged()
 
                    it.num?.let { it2 ->
                        it
                        classHours = classTimeAdapter.checkeds.size * it2 * it.time.size
                        mtvNeedClassHour.text = classHours.toString()
                    }
 
 
                }
                classTimeAdapter.mData.apply {
                    clear()
                    addAll(it.day)
                    classTimeAdapter.notifyDataSetChanged()
                }
 
 
            }
 
        }
    }
 
}