|
|
@@ -1,6 +1,7 @@
|
|
|
package com.yingyangfly.moca.singlechoice
|
|
|
|
|
|
import android.os.Bundle
|
|
|
+import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
|
@@ -11,13 +12,17 @@ import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
+import com.yingyangfly.baselib.mvvm.BaseMVVMFragment
|
|
|
+import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
import com.yingyangfly.moca.adapter.ChoiceAdapter
|
|
|
import com.yingyangfly.moca.adapter.SpeakResultAdapter
|
|
|
+import gorden.rxbus2.RxBus
|
|
|
|
|
|
/**
|
|
|
* 单选
|
|
|
*/
|
|
|
-class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
+class SingleChoiceFragment :
|
|
|
+ BaseMVVMFragment<FragmentSingleChoiceBinding, SingleChoiceViewModel>() {
|
|
|
|
|
|
/**
|
|
|
* 问题id
|
|
|
@@ -86,12 +91,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
loadData()
|
|
|
}
|
|
|
76 -> {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ submit()
|
|
|
}
|
|
|
else -> {
|
|
|
val controller = Navigation.findNavController(it)
|
|
|
@@ -158,4 +158,29 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交测试
|
|
|
+ */
|
|
|
+ private fun submit() {
|
|
|
+ if (dao != null) {
|
|
|
+ val questionsBeans = dao?.getAllQuestions()
|
|
|
+ if (questionsBeans.isNullOrEmpty().not()) {
|
|
|
+ questionsBeans?.forEach {
|
|
|
+ it.reviewId = it.id
|
|
|
+ if (TextUtils.equals("0", it.correct)) {
|
|
|
+ it.score = "0"
|
|
|
+ } else {
|
|
|
+ it.score = it.reviewScore
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ viewModel.submitQuestions(questionsBeans!!, fail = {
|
|
|
+ it.toast()
|
|
|
+ }, success = {
|
|
|
+ "提交成功".toast()
|
|
|
+ RxBus.get().send(RxBusCodes.EndMOCAQuestion)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|