|
|
@@ -10,6 +10,7 @@ import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.moca.adapter.ChoiceAdapter
|
|
|
+import com.yingyangfly.moca.adapter.SpeakResultAdapter
|
|
|
|
|
|
/**
|
|
|
* 单选
|
|
|
@@ -22,7 +23,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
private var questionId = 0
|
|
|
private var question: QuestionsBean? = null
|
|
|
private val choiceItemList = mutableListOf<QuestionsBean>()
|
|
|
- private val adapter by lazy { ChoiceAdapter() }
|
|
|
+ private val adapter by lazy { SpeakResultAdapter() }
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
questionId = arguments?.getInt("questionId") ?: 60
|
|
|
@@ -32,7 +33,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
override fun initViews() {
|
|
|
binding {
|
|
|
rvChoice.adapter = adapter
|
|
|
- adapter.onNumClickListener = {
|
|
|
+ adapter.onCheckClickListener = {
|
|
|
if (dao != null) {
|
|
|
dao?.update(it)
|
|
|
}
|
|
|
@@ -72,25 +73,27 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
}
|
|
|
}
|
|
|
btnNext.setOnSingleClickListener {
|
|
|
- when (questionId) {
|
|
|
- 60 -> {
|
|
|
- questionId++
|
|
|
- loadData()
|
|
|
- }
|
|
|
- 77 -> {
|
|
|
- questionId--
|
|
|
- loadData()
|
|
|
- }
|
|
|
- 76 -> {
|
|
|
- "提交信息".toast()
|
|
|
- }
|
|
|
- else -> {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 62)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_singleChoiceFragment_to_recordresultfragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
+ if (judge()) {
|
|
|
+ when (questionId) {
|
|
|
+ 60 -> {
|
|
|
+ questionId++
|
|
|
+ loadData()
|
|
|
+ }
|
|
|
+ 77 -> {
|
|
|
+ questionId--
|
|
|
+ loadData()
|
|
|
+ }
|
|
|
+ 76 -> {
|
|
|
+ "提交信息".toast()
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ val controller = Navigation.findNavController(it)
|
|
|
+ val bundle = bundleOf("questionId" to 62)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_singleChoiceFragment_to_recordresultfragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -133,4 +136,19 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 非空判断
|
|
|
+ */
|
|
|
+ private fun judge(): Boolean {
|
|
|
+ if (choiceItemList.isNullOrEmpty().not()) {
|
|
|
+ choiceItemList.forEach {
|
|
|
+ if (it.inputString.isNullOrEmpty()) {
|
|
|
+ "请判断答案是否正确".toast()
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|