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
package com.dollearn.student.dialog
 
import android.annotation.SuppressLint
import android.view.Gravity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.network.entity.MyCourse
import com.dollearn.student.ui.course.adapter.ClassHourChooseAdapter
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_exchange_count.tv_action
import kotlinx.android.synthetic.main.dialog_exchange_count.tv_cancel
import kotlinx.android.synthetic.main.dialog_wfp_classhour.*
 
class UndistributedClassHourialog : BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_wfp_classhour
 
    var callback: StringCallback? = null
 
    val count by lazy {
        arguments?.getInt("count") ?: 0
    }
 
    val list by lazy {
        arguments?.getSerializable("list") as ArrayList<MyCourse>
    }
 
    val adapter by lazy {
        ClassHourChooseAdapter(list)
    }
 
    override fun setGravity() = Gravity.CENTER
 
    @SuppressLint("SetTextI18n", "NotifyDataSetChanged")
    override fun initView() {
        mtvinfo.text = "未分配课时数:$count"
        tv_action.setOnClickListener {
            callback?.onResult(list[adapter.checked].id)
            dismissAllowingStateLoss()
        }
        tv_cancel.setOnClickListener { dismissAllowingStateLoss() }
 
        mrl.layoutManager = LinearLayoutManager(context)
        mrl.adapter = adapter
        adapter.setOnItemClickListener { _, position ->
            run {
                adapter.checked = position
                adapter.notifyDataSetChanged()
            }
 
        }
    }
 
    companion object {
        fun show(
            fm: FragmentManager,
            count: Int,
            list: ArrayList<MyCourse>,
            callback: StringCallback
        ) :UndistributedClassHourialog{
            val exchangeCountDialog = UndistributedClassHourialog()
            exchangeCountDialog.callback = callback
            exchangeCountDialog.arguments = bundleOf(
                "count" to count,
                "list" to list
            )
            exchangeCountDialog.showAllowingStateLoss(fm, "")
 
           return exchangeCountDialog
        }
    }
}