package com.dollearn.student.ui.course
|
|
import android.content.Intent
|
import android.view.View
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import cn.sinata.xldutils.utils.toTime
|
import com.dollearn.student.R
|
import com.dollearn.student.DollearnApplication
|
import com.dollearn.student.dialog.ChooseMonthDialog
|
import com.dollearn.student.dialog.FilterPop
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.CourseRecord
|
import com.dollearn.student.network.entity.Session
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.ui.course.adapter.CourseNameAdapter
|
import com.dollearn.student.ui.course.adapter.CourseRecordAdapter
|
import com.dollearn.student.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.activity_my_course_detail.*
|
import org.jetbrains.anko.startActivityForResult
|
|
class MyCourseDetailActivity : TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_my_course_detail
|
|
private val stuId by lazy { intent.getStringExtra("stuId")?:"" }
|
private var courseId = ""
|
private val names = arrayListOf<Session>()
|
private val nameAdapter = CourseNameAdapter(names)
|
private val records = arrayListOf<CourseRecord>()
|
private val recordAdapter = CourseRecordAdapter(records)
|
|
private var date = ""
|
private var type: Int? = null
|
|
override fun initClick() {
|
nameAdapter.setOnItemClickListener { view, position ->
|
nameAdapter.checked = position
|
tv_deadline.text = "有效期:${names[position].periodOfValidity}"
|
nameAdapter.notifyDataSetChanged()
|
refreshCourseInfo()
|
}
|
|
tv_month.setOnClickListener {
|
val chooseMonthDialog = ChooseMonthDialog()
|
chooseMonthDialog.setCallback(object : StringCallback {
|
override fun onResult(rst: String) {
|
tv_month.text = rst
|
date = rst.replace("年", "-").replace("月", "")
|
getRecord()
|
}
|
})
|
chooseMonthDialog.showAllowingStateLoss(supportFragmentManager, "date")
|
}
|
|
tv_filter.setOnClickListener {
|
val menuPop = FilterPop(this)
|
menuPop.setCallback(object : StringCallback {
|
override fun onResult(rst: String) {
|
tv_filter.text = rst
|
type = when (rst) {
|
"增加" -> 1
|
"扣除" -> 2
|
else -> null
|
}
|
getRecord()
|
}
|
})
|
menuPop.contentView
|
.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
|
menuPop.showAsDropDown(tv_filter, 0, 0, 0)
|
}
|
|
tv_buy.setOnClickListener {
|
|
}
|
}
|
|
override fun initView() {
|
courseId = intent.getStringExtra("courseId")?:""
|
tv_month.text = System.currentTimeMillis().toTime("yyyy年MM月")
|
date = System.currentTimeMillis().toTime("yyyy-MM")
|
rv_name.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
|
rv_name.adapter = nameAdapter
|
rv_record.layoutManager = LinearLayoutManager(this)
|
rv_record.adapter = recordAdapter
|
getData()
|
getRecord()
|
}
|
|
|
private fun getData() {
|
HttpManager.lessonDetails(courseId, stuId).request(this) { _, data ->
|
data?.apply {
|
iv_avatar.setImageURI(stuImage)
|
tv_name.text = stuName
|
tv_deadline.text = "有效期:${sessionNames.firstOrNull()?.periodOfValidity}"
|
tv_total_count.text = totalNums
|
tv_used_count.text = deductedNums
|
tv_last_count.text = remainingNums
|
|
// tv_used.text = "已扣课时数:${deductionClassHours}"
|
names.clear()
|
names.addAll(sessionNames)
|
nameAdapter.notifyDataSetChanged()
|
refreshCourseInfo()
|
// records.clear()
|
// records.addAll(details)
|
// recordAdapter.notifyDataSetChanged()
|
}
|
}
|
}
|
|
/**
|
* 显示课时信息
|
*/
|
private fun refreshCourseInfo() {
|
val current = names[nameAdapter.checked]
|
tv_total_count2.text = current.totalNums
|
tv_used_count2.text = current.deductedNums
|
tv_last_count2.text = current.remainingNums
|
courseId = current.sessionid
|
getRecord()
|
}
|
|
private fun getRecord() {
|
HttpManager.recordDetails(stuId, courseId, date, type).request(this) { _, data ->
|
records.clear()
|
records.addAll(data ?: arrayListOf())
|
recordAdapter.notifyDataSetChanged()
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (requestCode == 1) {
|
getData()
|
}
|
}
|
}
|