|
|
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) {
|
|
|
// 点击外部不取消
|
...
|
...
|
|