Browse Source

1.添加获取moca试题库module

王鹏鹏 2 years ago
parent
commit
2def55ae82

+ 48 - 18
moca/src/main/java/com/yingyangfly/moca/signature/DesignsChoiceFragment.kt

@@ -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
+    }
 }

+ 5 - 1
moca/src/main/java/com/yingyangfly/moca/signature/SignatureFragment.kt

@@ -1,5 +1,6 @@
 package com.yingyangfly.moca.signature
 
+import android.graphics.Bitmap
 import android.os.Bundle
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
@@ -46,8 +47,11 @@ class SignatureFragment : BaseFragment<FragmentSignatureBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
+                val bundle = Bundle()
+                bundle.putInt("questionId", 33)
+                val bitmap: Bitmap = signatureView.getCachebBitmaps()
+                bundle.putParcelable("bitmap", bitmap)
                 val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 33)
                 controller.navigate(
                     R.id.action_signatureFragment_to_designsChoiceFragment,
                     bundle

+ 1 - 4
moca/src/main/java/com/yingyangfly/moca/widget/LinePathView.kt

@@ -220,10 +220,7 @@ class LinePathView : View {
     }
 
     fun getCachebBitmaps(): Bitmap {
-        var bitmap = cachebBitmap
-//        if (clearBlank) {
-//            bitmap = clearBlank(bitmap, blank)
-//        }
+        val bitmap = cachebBitmap
         val bos = ByteArrayOutputStream()
         bitmap!!.compress(Bitmap.CompressFormat.PNG, 100, bos)
         return bitmap

+ 23 - 7
moca/src/main/res/layout/fragment_designs_choice.xml

@@ -24,14 +24,30 @@
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 
-        <androidx.appcompat.widget.AppCompatImageView
-            android:id="@+id/designsImage"
-            android:layout_width="@dimen/divider_179px"
-            android:layout_height="@dimen/divider_179px"
-            android:layout_marginTop="@dimen/divider_26px"
+        <com.google.android.material.card.MaterialCardView
+            android:id="@+id/designsLayout"
+            android:layout_width="@dimen/divider_245px"
+            android:layout_height="@dimen/divider_245px"
+            android:layout_marginStart="@dimen/divider_38px"
+            android:layout_marginBottom="@dimen/divider_60px"
+            android:theme="@style/Theme.MaterialComponents.NoActionBar"
+            app:cardBackgroundColor="@android:color/white"
+            app:cardCornerRadius="@dimen/divider_20px"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
+            app:layout_constraintTop_toTopOf="parent"
+            app:strokeColor="@color/color_FF979797"
+            app:strokeWidth="@dimen/divider_1px">
+
+            <androidx.appcompat.widget.AppCompatImageView
+                android:id="@+id/designsImage"
+                android:layout_width="@dimen/divider_240px"
+                android:layout_height="@dimen/divider_240px"
+                android:layout_gravity="center"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
+
+        </com.google.android.material.card.MaterialCardView>
 
         <com.google.android.material.card.MaterialCardView
             android:id="@+id/contentLayout"
@@ -44,7 +60,7 @@
             app:cardBackgroundColor="@android:color/white"
             app:cardCornerRadius="@dimen/divider_20px"
             app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toEndOf="@+id/designsImage"
+            app:layout_constraintStart_toEndOf="@+id/designsLayout"
             app:layout_constraintTop_toBottomOf="@+id/tvTitle"
             app:strokeColor="@color/color_FF979797"
             app:strokeWidth="@dimen/divider_1px">