作者 刘纪龙

Loong:班级考试考试中状态复原及倒计时功能

... ... @@ -15,6 +15,7 @@
<entry key="app/src/main/res/layout/activity_splash.xml" value="0.2671875" />
<entry key="app/src/main/res/layout/activity_video_detail.xml" value="0.2671875" />
<entry key="app/src/main/res/layout/adapter_content_practice_item.xml" value="0.2671875" />
<entry key="app/src/main/res/layout/adapter_topic.xml" value="0.2671875" />
<entry key="app/src/main/res/layout/dialog_check_id.xml" value="0.33" />
<entry key="app/src/main/res/layout/fragment_bank.xml" value="0.33" />
<entry key="app/src/main/res/layout/fragment_class_duty_course.xml" value="0.2671875" />
... ...
... ... @@ -61,7 +61,8 @@ open class UserSubject(
var difficulty: String, // 难度1=简单2=适中3=困难
var correct: String, // 正确答案
var remark: String, // 题目解析
var options_arr: List<OptionArr>
var options_arr: List<OptionArr>,
var user_answer: String
)
data class StartItemBean(
... ...
... ... @@ -390,7 +390,20 @@ class CourseTestPaperAdapter(private val isShowPosition: Boolean = true):
index: Int,
data: UserSubject
) {
val adapterChild = TopicAdapter()
holder.topicRecycler.adapter = adapterChild
adapterChild.addList(data.options_arr)
adapterChild.let {
if(data.user_answer!=""){
data.options_arr.forEachIndexed { indexs, optionArr ->
if( optionArr.option_name==data.user_answer){
it.itemClick(indexs)
selectResultData[index] = it.mSelectIndex
}
}
}
}
val value = if (isShowPosition) {
"(${index + 1}/${itemCount})${data.title}${ConstantType.getType(data.type)}"
} else {
... ... @@ -398,6 +411,7 @@ class CourseTestPaperAdapter(private val isShowPosition: Boolean = true):
}
val span = SpannableString(value)
span.setSpan(
ForegroundColorSpan(Color.parseColor("#C8C9CC")),
value.length - 4,
... ... @@ -412,9 +426,6 @@ class CourseTestPaperAdapter(private val isShowPosition: Boolean = true):
)
holder.topic.text = span
val adapterChild = TopicAdapter()
adapterChild.addList(data.options_arr)
holder.topicRecycler.adapter = adapterChild
holder.txtCorrect.text = "正确答案:${data.correct}"
holder.txtAnalysis.text = "解析:${data.remark}"
holder.contentAnalysis.visibility = if (showCorrect) View.VISIBLE else View.GONE
... ...
package com.br_technology.securitytrain_master.ui.view.home.activity.course
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.CountDownTimer
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
... ... @@ -40,6 +42,8 @@ class CoursePractiseActivity :
private val mPagerAdapter = CourseTestPaperAdapter()
private var userItemId = ""
private var isFinish = false
private var isExam:Boolean=false
private var countDownTimer:CountDownTimer?=null
private val titleDialog by lazy {
DialogTitle(this)
}
... ... @@ -70,10 +74,11 @@ class CoursePractiseActivity :
}
}
@SuppressLint("WrongConstant")
override fun initData() {
super.initData()
courseBean = intent.getParcelableExtra(ConstantParamKey.COURSE_BEAN)
val isExam = intent.getBooleanExtra("isExam", false)
isExam = intent.getBooleanExtra("isExam", false)
courseBean?.let {
if (isExam) {
mViewModel.startExam(it.mTrainClassId)
... ... @@ -84,7 +89,7 @@ class CoursePractiseActivity :
binding.apply {
// 禁止滑动
practicePager.isUserInputEnabled = false
practicePager.offscreenPageLimit=1
toolBar.setRightText("答题卡")
toolBar.setRightTextDrawable(
ContextCompat.getDrawable(
... ... @@ -168,14 +173,14 @@ class CoursePractiseActivity :
}
fun countDown(seconds: Int) {
val total = seconds.toLong()
//intervalRange四个参数分别为:从0开始、到60结束、延时0开始,单位时间(NANOSECONDS,MICROSECONDS,MILLISECONDS,SECONDS,MINUTES,HOURS,DAYS)。
Flowable.intervalRange(0, total, 0, 1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext {
val current = total - it
val seconds = current % 60
val minutes = current / 60
if (countDownTimer != null) {
countDownTimer?.cancel()
}
countDownTimer = object : CountDownTimer((seconds * 1000).toLong(), 1000) {
override fun onTick(millisUntilFinished: Long) {
val mill= millisUntilFinished/1000
val seconds = mill % 60
val minutes = mill / 60
val hour = minutes / 60
val hourTx = if (hour < 10) {
"0${hour}"
... ... @@ -188,10 +193,35 @@ class CoursePractiseActivity :
} else "${minutes}"
binding.toolBar.setTitle("倒计时${hourTx}:${minutesTx}:${secondsx}")
}
.doOnComplete { //倒计时完毕事件处理
override fun onFinish() {
finish()
}
.subscribe()
cancel()
}
}.start()
// val total = seconds.toLong()
// //intervalRange四个参数分别为:从0开始、到60结束、延时0开始,单位时间(NANOSECONDS,MICROSECONDS,MILLISECONDS,SECONDS,MINUTES,HOURS,DAYS)。
// Flowable.intervalRange(0, total, 0, 1, TimeUnit.SECONDS)
// .observeOn(AndroidSchedulers.mainThread())
// .doOnNext {
// val current = total - it
// val seconds = current % 60
// val minutes = current / 60
// val hour = minutes / 60
// val hourTx = if (hour < 10) {
// "0${hour}"
// } else "${hour}"
// val secondsx = if (seconds < 10) {
// "0${seconds}"
// } else "${seconds}"
// val minutesTx = if (minutes < 10) {
// "0${minutes}"
// } else "${minutes}"
// binding.toolBar.setTitle("倒计时${hourTx}:${minutesTx}:${secondsx}")
// }
// .doOnComplete { //倒计时完毕事件处理
// finish()
// }
// .subscribe()
}
... ... @@ -205,8 +235,27 @@ class CoursePractiseActivity :
mViewModel.exam.observe(this) {
if (it.code == 1) {
userItemId = it.data.user_item_id
mPagerAdapter.addList(it.data.list)
binding.practicePager.adapter = mPagerAdapter
mPagerAdapter.addList(it.data.list)
val list= it.data.list.filter { userSubject -> userSubject.user_answer!=""}
if(list.isNotEmpty()){
binding.practicePager.currentItem=list.size
val index = binding.practicePager.currentItem
if(index==it.data.list.size-1){
binding.finishJob.visibility = View.VISIBLE
binding.previous.visibility = View.VISIBLE
binding.next.visibility = View.GONE
}else if(index==0){
binding.finishJob.visibility = View.GONE
binding.previous.visibility = View.GONE
binding.next.visibility = View.VISIBLE
}else{
binding.finishJob.visibility = View.GONE
binding.previous.visibility = View.VISIBLE
binding.next.visibility = View.VISIBLE
}
}
countDown(it.data.over_second)
} else {
ToastUtils.s(baseContext, it.msg)
this@CoursePractiseActivity.finish()
... ... @@ -223,8 +272,10 @@ class CoursePractiseActivity :
mPagerAdapter.notifyDataSetChanged()
mViewModel.subFinish(userItemId)
}
if (!isExam) {
binding.toolBar.setTitle("班级练习")
}
}
mViewModel.subFinish.observe(this) {
if (!titleDialog.isShowing) {
// 点击外部不取消
... ...