|
@@ -1,5 +1,8 @@
|
|
|
package com.yingyangfly.moca.signature
|
|
|
|
|
|
+import android.graphics.Bitmap
|
|
|
+import android.graphics.drawable.BitmapDrawable
|
|
|
+import android.graphics.drawable.Drawable
|
|
|
import android.os.Bundle
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
@@ -9,6 +12,8 @@ import com.yingyang.moca.databinding.FragmentDesignsChoiceBinding
|
|
|
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.utils.ImageUtil
|
|
|
import com.yingyangfly.moca.adapter.ChoiceAdapter
|
|
|
|
|
|
/**
|
|
@@ -23,9 +28,11 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
|
|
|
|
|
|
private val choiceItemList = mutableListOf<QuestionsBean>()
|
|
|
private val adapter by lazy { ChoiceAdapter() }
|
|
|
+ private var bitmap: Bitmap? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
questionId = arguments?.getInt("questionId") ?: 33
|
|
|
+ bitmap = arguments?.getParcelable("bitmap")
|
|
|
super.onCreate(savedInstanceState)
|
|
|
}
|
|
|
|
|
@@ -33,7 +40,11 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
|
|
|
binding {
|
|
|
rvChoice.layoutManager = LinearLayoutManager(mContext)
|
|
|
rvChoice.adapter = adapter
|
|
|
-
|
|
|
+ adapter.onNumClickListener = {
|
|
|
+ if (dao != null) {
|
|
|
+ dao?.update(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -48,12 +59,14 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
|
|
|
)
|
|
|
}
|
|
|
btnNext.setOnSingleClickListener {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 38)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_designsChoiceFragment_to_drawDesignFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
+ if (judge()) {
|
|
|
+ val controller = Navigation.findNavController(it)
|
|
|
+ val bundle = bundleOf("questionId" to 38)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_designsChoiceFragment_to_drawDesignFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -71,6 +84,10 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
|
|
|
* 加载数据
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
+ if (bitmap != null) {
|
|
|
+ val drawable: Drawable = BitmapDrawable(bitmap)
|
|
|
+ ImageUtil.loadUrl(mContext, drawable, binding.designsImage)
|
|
|
+ }
|
|
|
choiceItemList.clear()
|
|
|
if (dao != null) {
|
|
|
val firstquestion = dao?.getQuestion(questionId)
|
|
@@ -87,20 +104,33 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
|
|
|
if (thirdQuestion != null) {
|
|
|
choiceItemList.add(thirdQuestion)
|
|
|
}
|
|
|
- if (questionId == 33) {
|
|
|
- val fourthQuestionId = questionId + 3
|
|
|
- val fourthQuestion = dao?.getQuestion(fourthQuestionId)
|
|
|
- if (fourthQuestion != null) {
|
|
|
- choiceItemList.add(fourthQuestion)
|
|
|
- }
|
|
|
+ val fourthQuestionId = questionId + 3
|
|
|
+ val fourthQuestion = dao?.getQuestion(fourthQuestionId)
|
|
|
+ if (fourthQuestion != null) {
|
|
|
+ choiceItemList.add(fourthQuestion)
|
|
|
+ }
|
|
|
|
|
|
- val fifthQuestionId = questionId + 4
|
|
|
- val fifthQuestion = dao?.getQuestion(fifthQuestionId)
|
|
|
- if (fifthQuestion != null) {
|
|
|
- choiceItemList.add(fifthQuestion)
|
|
|
- }
|
|
|
+ val fifthQuestionId = questionId + 4
|
|
|
+ val fifthQuestion = dao?.getQuestion(fifthQuestionId)
|
|
|
+ if (fifthQuestion != null) {
|
|
|
+ choiceItemList.add(fifthQuestion)
|
|
|
}
|
|
|
}
|
|
|
adapter.setData(choiceItemList)
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 非空判断
|
|
|
+ */
|
|
|
+ private fun judge(): Boolean {
|
|
|
+ if (choiceItemList.isNullOrEmpty().not()) {
|
|
|
+ choiceItemList.forEach {
|
|
|
+ if (it.inputString.isNullOrEmpty()) {
|
|
|
+ "请判断答案是否正确".toast()
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|