Browse Source

1.添加测评module

王鹏鹏 2 years ago
parent
commit
584f939a49

+ 5 - 5
baselib/schemas/com.yingyangfly.baselib.db.AppDataBase/1.json

@@ -2,7 +2,7 @@
   "formatVersion": 1,
   "database": {
     "version": 1,
-    "identityHash": "f357e4c637ab54dffa07dbbcfddbca04",
+    "identityHash": "94d32106376dc4df10a097bf99e02f6e",
     "entities": [
       {
         "tableName": "Questions",
@@ -306,7 +306,7 @@
       },
       {
         "tableName": "QuestionOption",
-        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` REAL NOT NULL, `correctOption` TEXT, `optionKey` TEXT, `optionVal` TEXT, `questionId` TEXT, PRIMARY KEY(`id`))",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` REAL NOT NULL, `correctOption` TEXT, `optionKey` TEXT, `optionVal` TEXT, `questionId` REAL NOT NULL, PRIMARY KEY(`id`))",
         "fields": [
           {
             "fieldPath": "id",
@@ -335,8 +335,8 @@
           {
             "fieldPath": "questionId",
             "columnName": "questionId",
-            "affinity": "TEXT",
-            "notNull": false
+            "affinity": "REAL",
+            "notNull": true
           }
         ],
         "primaryKey": {
@@ -438,7 +438,7 @@
     "views": [],
     "setupQueries": [
       "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
-      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f357e4c637ab54dffa07dbbcfddbca04')"
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '94d32106376dc4df10a097bf99e02f6e')"
     ]
   }
 }

+ 3 - 6
baselib/src/main/java/com/yingyangfly/baselib/db/QuestionOptionBean.java

@@ -20,7 +20,7 @@ public class QuestionOptionBean {
     private String correctOption;
     private String optionKey;
     private String optionVal;
-    private String questionId;
+    private double questionId;
 
     @Ignore
     private String updateBy;
@@ -94,14 +94,11 @@ public class QuestionOptionBean {
         this.optionVal = optionVal;
     }
 
-    public String getQuestionId() {
-        if (TextUtils.isEmpty(questionId)) {
-            return "";
-        }
+    public double getQuestionId() {
         return questionId;
     }
 
-    public void setQuestionId(String questionId) {
+    public void setQuestionId(double questionId) {
         this.questionId = questionId;
     }
 

+ 1 - 1
baselib/src/main/java/com/yingyangfly/baselib/db/QuestionOptionDao.kt

@@ -15,7 +15,7 @@ interface QuestionOptionDao : BaseDao<QuestionOptionBean> {
     fun getAllQuestionOptionBeanBean(): MutableList<QuestionOptionBean>
 
     @Query("select * from QuestionOption where questionId = :questionId")
-    fun getQuestionOptionBeanByQuestionId(questionId: String): List<QuestionOptionBean>
+    fun getQuestionOptionBeanByQuestionId(questionId: Double): List<QuestionOptionBean>
 
     @Query("delete from QuestionOption")
     fun deleteAll()

+ 19 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/adapter/QuestionListAdapter.kt

@@ -0,0 +1,19 @@
+package com.yingyangfly.evaluation.adapter
+
+import com.yingyangfly.baselib.adapter.BaseDataBindingAdapter
+import com.yingyangfly.baselib.db.QuestionOptionBean
+import com.yingyangfly.evaluation.R
+import com.yingyangfly.evaluation.databinding.ItemQuestionListBinding
+import com.yingyangfly.evaluation.entity.EvaluationHistoryBean
+
+/**
+ * 选项adapter
+ */
+class QuestionListAdapter(override val layoutId: Int = R.layout.item_question_list) :
+    BaseDataBindingAdapter<QuestionOptionBean, ItemQuestionListBinding>() {
+    override fun onBindViewHolder(
+        binding: ItemQuestionListBinding, item: QuestionOptionBean, position: Int
+    ) {
+        binding.data = item
+    }
+}

+ 85 - 11
evaluation/src/main/java/com/yingyangfly/evaluation/questionlist/QuestionListActivity.kt

@@ -6,32 +6,42 @@ import android.view.MotionEvent
 import android.view.View
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.yingyangfly.baselib.base.BaseActivity
+import com.yingyangfly.baselib.db.QuestionOptionBean
+import com.yingyangfly.baselib.db.QuestionRecordsBean
 import com.yingyangfly.baselib.dialog.TipsDialog
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
+import com.yingyangfly.baselib.ext.show
+import com.yingyangfly.baselib.ext.toast
+import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
 import com.yingyangfly.baselib.router.RouterUrlCommon
 import com.yingyangfly.baselib.utils.GsonUtil
 import com.yingyangfly.baselib.utils.RxTimer
 import com.yingyangfly.evaluation.R
+import com.yingyangfly.evaluation.adapter.QuestionListAdapter
 import com.yingyangfly.evaluation.databinding.ActivityQuestionListBinding
 
 /**
  * 试题列表
  */
 @Route(path = RouterUrlCommon.questionList)
-class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.OnTouchListener {
+class QuestionListActivity : BaseMVVMActivity<ActivityQuestionListBinding, QuestionListViewModel>(),
+    View.OnTouchListener {
 
     private lateinit var rxTimer: RxTimer
     private var time: Long = 0
+    private var questionIndex = 0
+
+    private var questionRecordsBeans = mutableListOf<QuestionRecordsBean>()
+
+    private var questionOptionBeans = mutableListOf<QuestionOptionBean>()
+    private val questionListAdapter by lazy { QuestionListAdapter() }
+
 
     override fun initViews() {
         rxTimer = RxTimer()
-        if (questionOptionDao != null) {
-            Log.e("wpp", GsonUtil.GsonString(questionOptionDao?.getAllQuestionOptionBeanBean()))
-        }
-
-        if (questionRecordsDao != null) {
-            Log.e("wpp", GsonUtil.GsonString(questionRecordsDao?.getAllQuestionRecordsBeanBean()))
+        binding {
+            rvSelectedItem.adapter = questionListAdapter
         }
     }
 
@@ -39,6 +49,8 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
     override fun initListener() {
         binding {
             layoutHead.setOnTouchListener(this@QuestionListActivity)
+            btnPrevious.setOnTouchListener(this@QuestionListActivity)
+            btnNext.setOnTouchListener(this@QuestionListActivity)
         }
     }
 
@@ -54,26 +66,57 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
                 "已用时 $seconds 秒"
             }
         }
+
+        if (questionRecordsDao != null) {
+            val data = questionRecordsDao?.getAllQuestionRecordsBeanBean()
+            questionRecordsBeans.clear()
+            if (data.isNullOrEmpty().not()) {
+                questionRecordsBeans.addAll(data!!)
+            }
+            Log.e(
+                "wpp",
+                "1-------------->" + GsonUtil.GsonString(questionRecordsDao?.getAllQuestionRecordsBeanBean())
+            )
+            setOptionList()
+        }
     }
 
     @SuppressLint("ClickableViewAccessibility")
     override fun onTouch(v: View, event: MotionEvent): Boolean {
         when (event.action) {
             MotionEvent.ACTION_DOWN -> {
-                if (v.id == R.id.layoutHead) {
+                if (v.id == R.id.layoutHead || v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
                     v.startAnimation(getScaleAnimation())
                 }
             }
 
             MotionEvent.ACTION_UP -> {
                 v.startAnimation(getEndAnimation())
-                if (v.id == R.id.layoutHead) {
-                    showTipsDialog()
+                when (v.id) {
+                    R.id.layoutHead -> {
+                        showTipsDialog()
+                    }
+
+                    R.id.btnPrevious -> {
+                        if (questionIndex > 0) {
+                            questionIndex--
+                            setOptionList()
+                        }
+                    }
+
+                    R.id.btnNext -> {
+                        if (questionIndex < questionRecordsBeans.size - 1) {
+                            questionIndex++
+                            setOptionList()
+                        } else {
+                            "提交数据".toast()
+                        }
+                    }
                 }
             }
 
             MotionEvent.ACTION_CANCEL -> {
-                if (v.id == R.id.layoutHead) {
+                if (v.id == R.id.layoutHead || v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
                     v.startAnimation(getEndAnimation())
                 }
             }
@@ -90,4 +133,35 @@ class QuestionListActivity : BaseActivity<ActivityQuestionListBinding>(), View.O
                 finish()
             }, true).show(supportFragmentManager)
     }
+
+    /**
+     * 展示选项列表
+     */
+    private fun setOptionList() {
+        //底部按钮展示逻辑
+        binding {
+            btnPrevious.show(questionIndex > 0)
+        }
+        val questionRecordsBean = questionRecordsBeans[questionIndex]
+        if (questionRecordsBean != null) {
+            binding.data = questionRecordsBean
+            questionOptionBeans.clear()
+            if (questionOptionDao != null) {
+                val data =
+                    questionOptionDao?.getQuestionOptionBeanByQuestionId(questionRecordsBean.id)
+                if (data.isNullOrEmpty().not()) {
+                    Log.e("wpp", "2-------------->" + GsonUtil.GsonString(data))
+                    questionOptionBeans.addAll(data!!)
+                } else {
+                    Log.e("wpp", "2----------------信息错误")
+                }
+            } else {
+                Log.e("wpp", "1----------------信息错误")
+            }
+            questionListAdapter.setData(questionOptionBeans)
+        } else {
+            Log.e("wpp", "信息错误")
+        }
+
+    }
 }

+ 71 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/questionlist/QuestionListViewModel.kt

@@ -0,0 +1,71 @@
+package com.yingyangfly.evaluation.questionlist
+
+import com.yingyangfly.baselib.bean.QuestionRecordsListBean
+import com.yingyangfly.baselib.mvvm.BaseViewModel
+import com.yingyangfly.baselib.net.XUtils
+import com.yingyangfly.baselib.utils.GsonUtil
+import com.yingyangfly.evaluation.entity.EvaluationTypeBean
+import com.yingyangfly.evaluation.entity.ExaminationListBean
+import com.yingyangfly.evaluation.entity.GetExaminationListBean
+import com.yingyangfly.evaluation.entity.GetQuestionListBean
+import com.yingyangfly.evaluation.net.EVALUATION_API
+
+/**
+ * @author 王鹏鹏
+ * @description 工作台页面ViewModel
+ */
+class QuestionListViewModel : BaseViewModel() {
+
+    /**
+     * 获取推送消息类型
+     */
+    fun getSelectByDictType(
+        fail: ((msg: String) -> Unit)? = null,
+        success: ((success: List<EvaluationTypeBean>?) -> Unit)? = null,
+    ) = launchFlow(true) {
+        EVALUATION_API.getSelectByDictType("exam_type")
+    }.runUI(
+        success, fail
+    )
+
+    /**
+     * 获取试题库列表
+     */
+    fun getExaminationList(
+        showLoading: Boolean,
+        pageIndex: Int,
+        type: String,
+        fail: ((msg: String) -> Unit)? = null,
+        success: ((success: ExaminationListBean?) -> Unit)? = null,
+    ) = launchFlow(showLoading) {
+        val requestBean = GetExaminationListBean().apply {
+            limit = "10"
+            page = pageIndex
+            examType = type
+        }
+        val body = XUtils.createJson(GsonUtil.GsonString(requestBean))
+        EVALUATION_API.getExaminationList(body)
+    }.runUI(
+        success, fail
+    )
+
+    /**
+     * 获取试题库列表
+     */
+    fun getQuestionList(
+        id: String,
+        fail: ((msg: String) -> Unit)? = null,
+        success: ((success: QuestionRecordsListBean?) -> Unit)? = null,
+    ) = launchFlow(true) {
+        val requestBean = GetQuestionListBean().apply {
+            limit = "99999"
+            page = 1
+            examinationId = id
+        }
+        val body = XUtils.createJson(GsonUtil.GsonString(requestBean))
+        EVALUATION_API.getQuestionList(body)
+    }.runUI(
+        success, fail
+    )
+
+}

+ 18 - 0
evaluation/src/main/res/drawable/bg_next_question.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="ResourceName">
+
+    <item>
+        <shape android:shape="rectangle">
+            <corners android:radius="@dimen/divider_13px" />
+            <gradient
+                android:angle="180"
+                android:endColor="@color/color_FF4174FF"
+                android:startColor="@color/color_FF6D9AFF"
+                android:type="linear"
+                android:useLevel="true" />
+        </shape>
+    </item>
+
+</layer-list>

+ 10 - 0
evaluation/src/main/res/drawable/bg_previous_question.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="ResourceName">
+    <stroke
+        android:width="@dimen/divider_1px"
+        android:color="@color/color_FF4A76FF" />
+    <corners android:radius="@dimen/divider_13px" />
+    <solid android:color="@android:color/white" />
+</shape>

+ 63 - 0
evaluation/src/main/res/layout/activity_question_list.xml

@@ -4,6 +4,13 @@
     xmlns:tools="http://schemas.android.com/tools"
     tools:ignore="ResourceName">
 
+    <data>
+
+        <variable
+            name="data"
+            type="com.yingyangfly.baselib.db.QuestionRecordsBean" />
+    </data>
+
     <androidx.constraintlayout.widget.ConstraintLayout
         style="@style/layout_properties_specify_width_geight"
         android:background="@mipmap/icon_uniform_background">
@@ -57,6 +64,62 @@
                 android:layout_width="match_parent"
                 android:layout_height="match_parent">
 
+                <TextView
+                    android:id="@+id/tvTopic"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="@dimen/divider_27px"
+                    android:text="@{data.getTitle()}"
+                    android:textColor="@color/color_FF222222"
+                    android:textSize="@dimen/divider_34px"
+                    android:textStyle="bold"
+                    app:layout_constraintEnd_toEndOf="parent"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toTopOf="parent" />
+
+                <androidx.recyclerview.widget.RecyclerView
+                    android:id="@+id/rvSelectedItem"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_marginStart="@dimen/divider_128px"
+                    android:layout_marginTop="@dimen/divider_82px"
+                    android:layout_marginEnd="@dimen/divider_128px"
+                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
+                    app:layout_constraintBottom_toTopOf="@+id/btnNext"
+                    app:layout_constraintEnd_toEndOf="parent"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toBottomOf="@+id/tvTopic" />
+
+                <androidx.appcompat.widget.AppCompatButton
+                    android:id="@+id/btnPrevious"
+                    android:layout_width="@dimen/divider_240px"
+                    android:layout_height="@dimen/divider_68px"
+                    android:layout_marginStart="@dimen/divider_307px"
+                    android:layout_marginBottom="@dimen/divider_60px"
+                    android:background="@drawable/bg_previous_question"
+                    android:gravity="center"
+                    android:text="@string/previous_question"
+                    android:textColor="@color/color_FF4A76FF"
+                    android:textSize="@dimen/divider_28px"
+                    android:textStyle="bold"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintStart_toStartOf="parent" />
+
+                <androidx.appcompat.widget.AppCompatButton
+                    android:id="@+id/btnNext"
+                    android:layout_width="@dimen/divider_240px"
+                    android:layout_height="@dimen/divider_68px"
+                    android:layout_marginEnd="@dimen/divider_305px"
+                    android:layout_marginBottom="@dimen/divider_60px"
+                    android:background="@drawable/bg_next_question"
+                    android:gravity="center"
+                    android:text="@string/continues"
+                    android:textColor="@android:color/white"
+                    android:textSize="@dimen/divider_28px"
+                    android:textStyle="bold"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintEnd_toEndOf="parent" />
+
 
             </androidx.constraintlayout.widget.ConstraintLayout>
         </androidx.cardview.widget.CardView>

+ 30 - 0
evaluation/src/main/res/layout/item_question_list.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="ResourceName">
+
+    <data>
+        <variable
+            name="data"
+            type="com.yingyangfly.baselib.db.QuestionOptionBean" />
+    </data>
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:id="@+id/tvTitle"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:textColor="@color/color_FF222222"
+            android:textSize="@dimen/divider_34px"
+            android:textStyle="bold"
+            android:text="@{data.getOptionVal()}"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</layout>

+ 2 - 0
evaluation/src/main/res/values/dimens.xml

@@ -47,6 +47,7 @@
     <dimen name="divider_315px" tools:ignore="ResourceName">315px</dimen>
     <dimen name="divider_313px" tools:ignore="ResourceName">313px</dimen>
     <dimen name="divider_307px" tools:ignore="ResourceName">307px</dimen>
+    <dimen name="divider_305px" tools:ignore="ResourceName">305px</dimen>
     <dimen name="divider_291px" tools:ignore="ResourceName">291px</dimen>
     <dimen name="divider_289px" tools:ignore="ResourceName">289px</dimen>
     <dimen name="divider_285px" tools:ignore="ResourceName">285px</dimen>
@@ -65,6 +66,7 @@
     <dimen name="divider_250px" tools:ignore="ResourceName">250px</dimen>
     <dimen name="divider_249px" tools:ignore="ResourceName">249px</dimen>
     <dimen name="divider_245px" tools:ignore="ResourceName">245px</dimen>
+    <dimen name="divider_240px" tools:ignore="ResourceName">240px</dimen>
     <dimen name="divider_238px" tools:ignore="ResourceName">238px</dimen>
     <dimen name="divider_237px" tools:ignore="ResourceName">237px</dimen>
     <dimen name="divider_235px" tools:ignore="ResourceName">235px</dimen>

+ 2 - 0
evaluation/src/main/res/values/strings.xml

@@ -69,4 +69,6 @@
     <string name="report_query" tools:ignore="ResourceName">报告查询</string>
     <string name="other_evaluations" tools:ignore="ResourceName">其他测评</string>
     <string name="evaluation" tools:ignore="ResourceName">测评</string>
+    <string name="continues" tools:ignore="ResourceName">继续</string>
+    <string name="previous_question" tools:ignore="ResourceName">上一题</string>
 </resources>