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
package com.dollearn.student.ui.course
 
import android.app.Activity
import android.content.Intent
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.showAllowingStateLoss
import cn.sinata.xldutils.visible
import com.dollearn.student.R
import com.dollearn.student.dialog.ChooseStudentDialog
import com.dollearn.student.dialog.TipDialog
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.entity.Student
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.course.adapter.SwitchStudentAdapter
import com.dollearn.student.ui.home.AddStudentActivity
import com.dollearn.student.ui.home.adapter.StudentAdapter
import com.dollearn.student.utils.extention.clickDelay
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.activity_choose_use.*
import org.jetbrains.anko.startActivityForResult
 
class SwitchStudentActivity:TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_choose_use
 
    private val list = arrayListOf<Student>()
    private val adapter = SwitchStudentAdapter(list)
 
    override fun initClick() {
        tv_add_student.clickDelay {
            startActivityForResult<AddStudentActivity>(1,"type" to AddStudentActivity.TYPE_COURSE)
        }
        adapter.setOnItemClickListener { view, position ->
            adapter.checked = list[position].stuId?:""
            adapter.notifyDataSetChanged()
        }
        adapter.delCallback = object :StringCallback{
            override fun onResult(rst: String) {
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf("msg" to "是否确认删除该人员?")
                tipDialog.setCallback(object :TipDialog.OnClickCallback{
                    override fun onOk() {
                        HttpManager.delParticipant(list[rst.toInt()].id?:"",list[rst.toInt()].isStudent).request(this@SwitchStudentActivity){ _, _->
                            list.removeAt(rst.toInt())
                            adapter.notifyDataSetChanged()
                        }
                    }
 
                    override fun onCancel() {
                    }
                })
                tipDialog.showAllowingStateLoss(supportFragmentManager,"del")
            }
        }
        tv_action.setOnClickListener {
            if (adapter.checked.isEmpty())
                myToast("请选择运动营成员")
            else{ //罗易胜:切换学员不调接口,直接回传学员id
                myToast("切换成功")
                val intent = Intent()
                intent.putExtra("stuId",adapter.checked)
                setResult(Activity.RESULT_OK,intent)
                finish()
            }
        }
    }
 
    override fun initView() {
        tv_1.gone()
        tv_action.visible()
        rv_student.layoutManager = LinearLayoutManager(this)
        rv_student.adapter = adapter
        adapter.checked = intent.getStringExtra("currentStu")?:""
        getUser()
    }
 
    fun getUser(){
        HttpManager.listOfStu().request(this){_,data->
            list.clear()
            list.addAll(data?.filter { it.isNot == 1 }?: arrayListOf())
            list.addAll(data?.filter { it.isNot != 1 }?: arrayListOf())
            adapter.notifyDataSetChanged()
        }
    }
 
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK){
            getUser()
            setResult(Activity.RESULT_OK)
        }
    }
}