|
|
@@ -6,32 +6,42 @@ import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.yingyangfly.baselib.base.BaseActivity
|
|
|
+import com.yingyangfly.baselib.db.QuestionOptionBean
|
|
|
+import com.yingyangfly.baselib.db.QuestionRecordsBean
|
|
|
import com.yingyangfly.baselib.dialog.TipsDialog
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
+import com.yingyangfly.baselib.ext.show
|
|
|
+import com.yingyangfly.baselib.ext.toast
|
|
|
+import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.GsonUtil
|
|
|
import com.yingyangfly.baselib.utils.RxTimer
|
|
|
import com.yingyangfly.evaluation.R
|
|
|
+import com.yingyangfly.evaluation.adapter.QuestionListAdapter
|
|
|
import com.yingyangfly.evaluation.databinding.ActivityQuestionListBinding
|
|
|
|
|
|
/**
|
|
|
* 试题列表
|
|
|
*/
|
|
|
@Route(path = RouterUrlCommon.questionList)
|
|
|
-class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.OnTouchListener {
|
|
|
+class QuestionListActivity : BaseMVVMActivity<ActivityQuestionListBinding, QuestionListViewModel>(),
|
|
|
+ View.OnTouchListener {
|
|
|
|
|
|
private lateinit var rxTimer: RxTimer
|
|
|
private var time: Long = 0
|
|
|
+ private var questionIndex = 0
|
|
|
+
|
|
|
+ private var questionRecordsBeans = mutableListOf<QuestionRecordsBean>()
|
|
|
+
|
|
|
+ private var questionOptionBeans = mutableListOf<QuestionOptionBean>()
|
|
|
+ private val questionListAdapter by lazy { QuestionListAdapter() }
|
|
|
+
|
|
|
|
|
|
override fun initViews() {
|
|
|
rxTimer = RxTimer()
|
|
|
- if (questionOptionDao != null) {
|
|
|
- Log.e("wpp", GsonUtil.GsonString(questionOptionDao?.getAllQuestionOptionBeanBean()))
|
|
|
- }
|
|
|
-
|
|
|
- if (questionRecordsDao != null) {
|
|
|
- Log.e("wpp", GsonUtil.GsonString(questionRecordsDao?.getAllQuestionRecordsBeanBean()))
|
|
|
+ binding {
|
|
|
+ rvSelectedItem.adapter = questionListAdapter
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -39,6 +49,8 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
layoutHead.setOnTouchListener(this@QuestionListActivity)
|
|
|
+ btnPrevious.setOnTouchListener(this@QuestionListActivity)
|
|
|
+ btnNext.setOnTouchListener(this@QuestionListActivity)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -54,26 +66,57 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
|
|
|
"已用时 $seconds 秒"
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (questionRecordsDao != null) {
|
|
|
+ val data = questionRecordsDao?.getAllQuestionRecordsBeanBean()
|
|
|
+ questionRecordsBeans.clear()
|
|
|
+ if (data.isNullOrEmpty().not()) {
|
|
|
+ questionRecordsBeans.addAll(data!!)
|
|
|
+ }
|
|
|
+ Log.e(
|
|
|
+ "wpp",
|
|
|
+ "1-------------->" + GsonUtil.GsonString(questionRecordsDao?.getAllQuestionRecordsBeanBean())
|
|
|
+ )
|
|
|
+ setOptionList()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
when (event.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
|
- if (v.id == R.id.layoutHead) {
|
|
|
+ if (v.id == R.id.layoutHead || v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
v.startAnimation(getScaleAnimation())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
- if (v.id == R.id.layoutHead) {
|
|
|
- showTipsDialog()
|
|
|
+ when (v.id) {
|
|
|
+ R.id.layoutHead -> {
|
|
|
+ showTipsDialog()
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.btnPrevious -> {
|
|
|
+ if (questionIndex > 0) {
|
|
|
+ questionIndex--
|
|
|
+ setOptionList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.btnNext -> {
|
|
|
+ if (questionIndex < questionRecordsBeans.size - 1) {
|
|
|
+ questionIndex++
|
|
|
+ setOptionList()
|
|
|
+ } else {
|
|
|
+ "提交数据".toast()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MotionEvent.ACTION_CANCEL -> {
|
|
|
- if (v.id == R.id.layoutHead) {
|
|
|
+ if (v.id == R.id.layoutHead || v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
}
|
|
|
}
|
|
|
@@ -90,4 +133,35 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
|
|
|
finish()
|
|
|
}, true).show(supportFragmentManager)
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 展示选项列表
|
|
|
+ */
|
|
|
+ private fun setOptionList() {
|
|
|
+ //底部按钮展示逻辑
|
|
|
+ binding {
|
|
|
+ btnPrevious.show(questionIndex > 0)
|
|
|
+ }
|
|
|
+ val questionRecordsBean = questionRecordsBeans[questionIndex]
|
|
|
+ if (questionRecordsBean != null) {
|
|
|
+ binding.data = questionRecordsBean
|
|
|
+ questionOptionBeans.clear()
|
|
|
+ if (questionOptionDao != null) {
|
|
|
+ val data =
|
|
|
+ questionOptionDao?.getQuestionOptionBeanByQuestionId(questionRecordsBean.id)
|
|
|
+ if (data.isNullOrEmpty().not()) {
|
|
|
+ Log.e("wpp", "2-------------->" + GsonUtil.GsonString(data))
|
|
|
+ questionOptionBeans.addAll(data!!)
|
|
|
+ } else {
|
|
|
+ Log.e("wpp", "2----------------信息错误")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.e("wpp", "1----------------信息错误")
|
|
|
+ }
|
|
|
+ questionListAdapter.setData(questionOptionBeans)
|
|
|
+ } else {
|
|
|
+ Log.e("wpp", "信息错误")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|