|
|
@@ -8,6 +8,7 @@ import com.yingyang.moca.databinding.FragmentSingleChoiceBinding
|
|
|
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.moca.adapter.ChoiceAdapter
|
|
|
|
|
|
/**
|
|
|
@@ -19,6 +20,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
* 问题id
|
|
|
*/
|
|
|
private var questionId = 0
|
|
|
+ private var question: QuestionsBean? = null
|
|
|
private val choiceItemList = mutableListOf<QuestionsBean>()
|
|
|
private val adapter by lazy { ChoiceAdapter() }
|
|
|
|
|
|
@@ -41,31 +43,55 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
btnPrevious.setOnSingleClickListener {
|
|
|
- if (questionId == 60) {
|
|
|
- btnPrevious.setOnSingleClickListener {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 59)
|
|
|
+ val controller = Navigation.findNavController(it)
|
|
|
+ when (questionId) {
|
|
|
+ 76 -> {
|
|
|
+ questionId++
|
|
|
+ loadData()
|
|
|
+ }
|
|
|
+ 77 -> {
|
|
|
+ val bundle = bundleOf("questionId" to questionId)
|
|
|
controller.navigate(
|
|
|
- R.id.action_singleChoiceFragment_to_numberRecordsFragment,
|
|
|
+ R.id.action_singleChoiceFragment_to_weekFragment,
|
|
|
bundle
|
|
|
)
|
|
|
}
|
|
|
- } else {
|
|
|
- questionId--
|
|
|
- loadData()
|
|
|
+ 60 -> {
|
|
|
+ btnPrevious.setOnSingleClickListener {
|
|
|
+ val bundle = bundleOf("questionId" to 59)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_singleChoiceFragment_to_numberRecordsFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ questionId--
|
|
|
+ loadData()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
btnNext.setOnSingleClickListener {
|
|
|
- if (questionId == 60) {
|
|
|
- questionId++
|
|
|
- loadData()
|
|
|
- } else {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 62)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_singleChoiceFragment_to_recordresultfragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
+ 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
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -84,18 +110,27 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
|
|
|
* 加载数据
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
- binding.tvTitle.text = if (questionId == 60) {
|
|
|
- "下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢"
|
|
|
- } else {
|
|
|
- "手表和尺子呢"
|
|
|
- }
|
|
|
choiceItemList.clear()
|
|
|
if (dao != null) {
|
|
|
- val question = dao?.getQuestion(questionId)
|
|
|
+ question = dao?.getQuestion(questionId)
|
|
|
if (question != null) {
|
|
|
- choiceItemList.add(question)
|
|
|
+ choiceItemList.add(question!!)
|
|
|
}
|
|
|
}
|
|
|
adapter.setData(choiceItemList)
|
|
|
+ binding.tvTitle.text = when (questionId) {
|
|
|
+ 76 -> {
|
|
|
+ "现在您在哪个城市"
|
|
|
+ }
|
|
|
+ 77 -> {
|
|
|
+ "我们现在是在什么地方"
|
|
|
+ }
|
|
|
+ 60 -> {
|
|
|
+ "下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢"
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ "手表和尺子呢"
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|