Quellcode durchsuchen

1.添加测评module

王鹏鹏 vor 2 Jahren
Ursprung
Commit
395a3bd8bf

+ 30 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/adapter/EvaluationTypeAdapter.kt

@@ -1,6 +1,10 @@
 package com.yingyangfly.evaluation.adapter
 
+import android.annotation.SuppressLint
+import android.text.TextUtils
 import com.yingyangfly.baselib.adapter.BaseDataBindingAdapter
+import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.setTextColorResource
 import com.yingyangfly.evaluation.R
 import com.yingyangfly.evaluation.databinding.ItemEvaluationTypeBinding
 import com.yingyangfly.evaluation.entity.EvaluationTypeBean
@@ -10,9 +14,35 @@ import com.yingyangfly.evaluation.entity.EvaluationTypeBean
  */
 class EvaluationTypeAdapter(override val layoutId: Int = R.layout.item_evaluation_type) :
     BaseDataBindingAdapter<EvaluationTypeBean, ItemEvaluationTypeBinding>() {
+
+    private var selectedType = ""
+
+    var onClickListener: ((bean: EvaluationTypeBean) -> Unit)? = null
+
+    fun setContent(selectedType: String) {
+        this.selectedType = selectedType
+    }
+
+    @SuppressLint("NotifyDataSetChanged")
     override fun onBindViewHolder(
         binding: ItemEvaluationTypeBinding, item: EvaluationTypeBean, position: Int
     ) {
         binding.data = item
+        if (TextUtils.isEmpty(selectedType).not() && TextUtils.equals(
+                selectedType, item.dictValue
+            )
+        ) {
+            binding.tvTitle.setTextColorResource(R.color.color_FFFFFFFF)
+            binding.tvTitle.setBackgroundResource(R.color.color_4A76FF)
+        } else {
+            binding.tvTitle.setTextColorResource(R.color.color_FF333333)
+            binding.tvTitle.setBackgroundResource(R.color.color_FFFFFFFF)
+        }
+
+        binding.tvTitle.setOnSingleClickListener {
+            selectedType = item.dictValue
+            notifyDataSetChanged()
+            onClickListener?.invoke(item)
+        }
     }
 }

+ 33 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/adapter/ExaminationAdapter.kt

@@ -0,0 +1,33 @@
+package com.yingyangfly.evaluation.adapter
+
+import com.yingyangfly.baselib.adapter.BaseDataBindingAdapter
+import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.evaluation.R
+import com.yingyangfly.evaluation.databinding.ItemExaminationBinding
+import com.yingyangfly.evaluation.entity.ExaminationRecord
+
+/**
+ * 试题库列表
+ */
+class ExaminationAdapter(override val layoutId: Int = R.layout.item_examination) :
+    BaseDataBindingAdapter<ExaminationRecord, ItemExaminationBinding>() {
+
+
+    var onClickListener: ((bean: ExaminationRecord) -> Unit)? = null
+
+    override fun onBindViewHolder(
+        binding: ItemExaminationBinding, item: ExaminationRecord, position: Int
+    ) {
+        binding.data = item
+        val index = position + 1
+        if (index % 2 == 0) {
+            binding.examinationLayout.setBackgroundResource(R.color.transparent)
+        } else {
+            binding.examinationLayout.setBackgroundResource(R.color.color_FFCFD9FF)
+        }
+
+        binding.imageArrow.setOnSingleClickListener {
+            onClickListener?.invoke(item)
+        }
+    }
+}

+ 1 - 1
evaluation/src/main/java/com/yingyangfly/evaluation/detail/ReviewResultDetailViewModel.kt

@@ -3,9 +3,9 @@ package com.yingyangfly.evaluation.detail
 import com.yingyangfly.baselib.mvvm.BaseViewModel
 import com.yingyangfly.baselib.net.XUtils
 import com.yingyangfly.baselib.utils.GsonUtil
+import com.yingyangfly.evaluation.entity.FindReviewResultBean
 import com.yingyangfly.evaluation.entity.ReviewResultDetailBean
 import com.yingyangfly.evaluation.net.EVALUATION_API
-import com.yingyangfly.evaluation.entity.FindReviewResultBean
 
 class ReviewResultDetailViewModel : BaseViewModel() {
 

+ 31 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/entity/ExaminationListBean.kt

@@ -0,0 +1,31 @@
+package com.yingyangfly.evaluation.entity
+
+data class ExaminationListBean(
+    val countId: Any,
+    val current: Int,
+    val maxLimit: Any,
+    val optimizeCountSql: Boolean,
+    val pages: Int,
+    val records: List<ExaminationRecord>,
+    val searchCount: Boolean,
+    val size: Int,
+    val total: Int
+)
+
+data class ExaminationRecord(
+    val createBy: String,
+    val createTime: String,
+    val described: String,
+    val examType: String,
+    val examinationCount: String,
+    val examinationScore: String,
+    val id: String,
+    val limit: Int,
+    val orgCode: String,
+    val orgName: String,
+    val page: Int,
+    val status: String,
+    val title: String,
+    val updateBy: String,
+    val updateTime: String
+)

+ 10 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/entity/GetExaminationListBean.kt

@@ -0,0 +1,10 @@
+package com.yingyangfly.evaluation.entity
+
+/**
+ * 分页
+ */
+class GetExaminationListBean {
+    var page: Int = 1
+    var limit: String = ""
+    var examType: String = ""
+}

+ 7 - 4
evaluation/src/main/java/com/yingyangfly/evaluation/net/EvaluationApiService.kt

@@ -3,10 +3,7 @@ package com.yingyangfly.evaluation.net
 import com.yingyangfly.baselib.bean.UserInfoBean
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.net.BaseResp
-import com.yingyangfly.evaluation.entity.EvaluationHistoryBean
-import com.yingyangfly.evaluation.entity.EvaluationTypeBean
-import com.yingyangfly.evaluation.entity.ReviewResultDetailBean
-import com.yingyangfly.evaluation.entity.ReviewTaskListBean
+import com.yingyangfly.evaluation.entity.*
 import okhttp3.RequestBody
 import retrofit2.http.Body
 import retrofit2.http.POST
@@ -56,4 +53,10 @@ interface EvaluationApiService {
     @POST("system/dict/data/selectByDictType")
     suspend fun getSelectByDictType(@Query("dictType") dictType: String): BaseResp<List<EvaluationTypeBean>>
 
+    /**
+     * 获取试题库列表
+     */
+    @POST("questionRecord/examinationList")
+    suspend fun getExaminationList(@Body requestBody: RequestBody): BaseResp<ExaminationListBean>
+
 }

+ 98 - 4
evaluation/src/main/java/com/yingyangfly/evaluation/otherevaluation/OtherEvaluationActivity.kt

@@ -1,41 +1,77 @@
 package com.yingyangfly.evaluation.otherevaluation
 
 import android.annotation.SuppressLint
+import android.text.TextUtils
+import android.view.MotionEvent
+import android.view.View
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.alibaba.android.arouter.facade.annotation.Route
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
 import com.yingyangfly.baselib.router.RouterUrlCommon
+import com.yingyangfly.evaluation.R
 import com.yingyangfly.evaluation.adapter.EvaluationTypeAdapter
+import com.yingyangfly.evaluation.adapter.ExaminationAdapter
 import com.yingyangfly.evaluation.databinding.ActivityOtherEvaluationBinding
 import com.yingyangfly.evaluation.entity.EvaluationTypeBean
+import com.yingyangfly.evaluation.entity.ExaminationRecord
 
 /**
  * 其他测评功能页面
  */
 @Route(path = RouterUrlCommon.otherEvaluation)
 class OtherEvaluationActivity :
-    BaseMVVMActivity<ActivityOtherEvaluationBinding, OtherEvaluationViewModel>() {
+    BaseMVVMActivity<ActivityOtherEvaluationBinding, OtherEvaluationViewModel>(),
+    View.OnTouchListener {
 
     /**
-     * 消息类型adapter
+     * 试题库类型adapter
      */
     private var evaluationType = ""
     private var evaluationTypeList = mutableListOf<EvaluationTypeBean>()
     private val evaluationAdapter by lazy { EvaluationTypeAdapter() }
 
+    private var page = 1
+    private var evaluationList = mutableListOf<ExaminationRecord>()
+    private val examinationAdapter by lazy { ExaminationAdapter() }
+
+
     override fun initViews() {
         binding {
+            swipeEvaluation.setEnableLoadMore(true)
+            swipeEvaluation.setEnableRefresh(true)
             val layoutManager =
                 LinearLayoutManager(this@OtherEvaluationActivity, RecyclerView.HORIZONTAL, false)
             rvEvaluationType.layoutManager = layoutManager
             rvEvaluationType.adapter = evaluationAdapter
+            evaluationAdapter.onClickListener = {
+                evaluationType = it.dictValue
+                getExaminationList(true, true)
+            }
+
+            rvEvaluation.adapter = examinationAdapter
+            examinationAdapter.onClickListener = {
+
+            }
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
+        binding {
+            layoutHead.setOnTouchListener(this@OtherEvaluationActivity)
 
+            swipeEvaluation.setOnRefreshListener {
+                getExaminationList(true, false)
+            }
+
+            swipeEvaluation.setOnLoadMoreListener {
+                getExaminationList(false, false)
+            }
+        }
     }
 
     override fun initData() {
@@ -50,7 +86,6 @@ class OtherEvaluationActivity :
     /**
      * 获取试题类型
      */
-    @SuppressLint("NotifyDataSetChanged")
     private fun getEvaluationType() {
         evaluationTypeList.clear()
         viewModel.getSelectByDictType(fail = {
@@ -59,8 +94,67 @@ class OtherEvaluationActivity :
             evaluationTypeList.clear()
             if (it.isNullOrEmpty().not()) {
                 evaluationTypeList.addAll(it!!)
+                if (TextUtils.isEmpty(evaluationType)) {
+                    evaluationType = it[0].dictValue
+                    getExaminationList(true, true)
+                }
+            }
+            if (TextUtils.isEmpty(evaluationType).not()) {
+                evaluationAdapter.setContent(evaluationType)
+            }
+            evaluationAdapter.setData(evaluationTypeList)
+        })
+    }
+
+    /**
+     * 获取试题库列表
+     */
+    private fun getExaminationList(
+        isRefresh: Boolean, showLoading: Boolean
+    ) {
+        if (isRefresh) {
+            page = 1
+            binding.swipeEvaluation.resetNoMoreData()
+        } else {
+            page++
+        }
+        viewModel.getExaminationList(showLoading, page, evaluationType, fail = {
+            it.toast()
+        }, success = {
+            if (isRefresh) {
+                evaluationList.clear()
             }
-            evaluationAdapter.notifyDataSetChanged()
+            if (it != null && it.records.isNullOrEmpty().not()) {
+                evaluationList.addAll(it.records)
+            }
+            examinationAdapter.setData(evaluationList)
         })
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.layoutHead) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.layoutHead -> {
+                        finish()
+                    }
+                }
+            }
+
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.layoutHead) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
 }

+ 28 - 4
evaluation/src/main/java/com/yingyangfly/evaluation/otherevaluation/OtherEvaluationViewModel.kt

@@ -1,8 +1,11 @@
 package com.yingyangfly.evaluation.otherevaluation
 
 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.GetEvaluationTypeBean
+import com.yingyangfly.evaluation.entity.ExaminationListBean
+import com.yingyangfly.evaluation.entity.GetExaminationListBean
 import com.yingyangfly.evaluation.net.EVALUATION_API
 
 /**
@@ -17,10 +20,31 @@ class OtherEvaluationViewModel : BaseViewModel() {
     fun getSelectByDictType(
         fail: ((msg: String) -> Unit)? = null,
         success: ((success: List<EvaluationTypeBean>?) -> Unit)? = null,
-    ) = launchFlow(false) {
+    ) = launchFlow(true) {
         EVALUATION_API.getSelectByDictType("exam_type")
     }.runUI(
-        success,
-        fail
+        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
+    )
+
 }

+ 87 - 11
evaluation/src/main/res/layout/activity_other_evaluation.xml

@@ -52,8 +52,9 @@
 
                 <com.google.android.material.card.MaterialCardView
                     android:id="@+id/titleLayout"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:layout_height="@dimen/divider_48px"
+                    android:layout_marginTop="@dimen/divider_20px"
                     android:theme="@style/Theme.MaterialComponents.NoActionBar"
                     app:cardBackgroundColor="@android:color/white"
                     app:cardCornerRadius="@dimen/divider_12px"
@@ -70,27 +71,102 @@
 
                 </com.google.android.material.card.MaterialCardView>
 
-                <LinearLayout
+                <com.google.android.material.card.MaterialCardView
                     android:layout_width="match_parent"
-                    android:layout_height="0dp"
+                    android:layout_height="match_parent"
                     android:layout_marginStart="@dimen/divider_34px"
+                    android:layout_marginTop="@dimen/divider_21px"
                     android:layout_marginEnd="@dimen/divider_37px"
                     android:layout_marginBottom="@dimen/divider_36px"
+                    android:orientation="vertical"
+                    android:theme="@style/Theme.MaterialComponents.NoActionBar"
+                    app:cardBackgroundColor="@android:color/white"
+                    app:cardCornerRadius="@dimen/divider_20px"
                     app:layout_constraintBottom_toBottomOf="parent"
                     app:layout_constraintEnd_toEndOf="parent"
                     app:layout_constraintStart_toStartOf="parent"
                     app:layout_constraintTop_toBottomOf="@+id/titleLayout">
 
-                    <androidx.recyclerview.widget.RecyclerView
-                        android:id="@+id/rvResult"
+                    <androidx.constraintlayout.widget.ConstraintLayout
                         android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
-                </LinearLayout>
+                        android:layout_height="match_parent">
+
+                        <LinearLayout
+                            android:id="@+id/titleLayour"
+                            android:layout_width="match_parent"
+                            android:layout_height="@dimen/divider_71px"
+                            android:background="@color/color_FF4A76FF"
+                            android:orientation="horizontal"
+                            app:layout_constraintEnd_toEndOf="parent"
+                            app:layout_constraintStart_toStartOf="parent"
+                            app:layout_constraintTop_toTopOf="parent">
+
+                            <androidx.appcompat.widget.AppCompatTextView
+                                android:layout_width="0dp"
+                                android:layout_height="match_parent"
+                                android:layout_weight="1"
+                                android:gravity="center"
+                                android:text="测评标题"
+                                android:textColor="@android:color/white"
+                                android:textSize="@dimen/divider_24px"
+                                android:textStyle="bold" />
+
+                            <androidx.appcompat.widget.AppCompatTextView
+                                android:layout_width="0dp"
+                                android:layout_height="match_parent"
+                                android:layout_weight="1"
+                                android:gravity="center"
+                                android:text="测评内容"
+                                android:textColor="@android:color/white"
+                                android:textSize="@dimen/divider_24px"
+                                android:textStyle="bold" />
 
+                            <androidx.appcompat.widget.AppCompatTextView
+                                android:layout_width="0dp"
+                                android:layout_height="match_parent"
+                                android:layout_weight="1"
+                                android:gravity="center"
+                                android:text="题目数量"
+                                android:textColor="@android:color/white"
+                                android:textSize="@dimen/divider_24px"
+                                android:textStyle="bold" />
+
+                            <androidx.appcompat.widget.AppCompatTextView
+                                android:layout_width="0dp"
+                                android:layout_height="match_parent"
+                                android:layout_weight="1"
+                                android:gravity="center"
+                                android:text="总分"
+                                android:textColor="@android:color/white"
+                                android:textSize="@dimen/divider_24px"
+                                android:textStyle="bold" />
+
+                            <androidx.appcompat.widget.AppCompatImageView
+                                android:id="@+id/imageArrow"
+                                android:layout_width="@dimen/divider_48px"
+                                android:layout_height="@dimen/divider_62px"
+                                android:layout_marginEnd="@dimen/divider_114px" />
+                        </LinearLayout>
+
+                        <com.scwang.smartrefresh.layout.SmartRefreshLayout
+                            android:id="@+id/swipeEvaluation"
+                            android:layout_width="match_parent"
+                            android:layout_height="0dp"
+                            android:background="@color/color_FFE6ECFF"
+                            app:layout_constraintBottom_toBottomOf="parent"
+                            app:layout_constraintEnd_toEndOf="parent"
+                            app:layout_constraintStart_toStartOf="parent"
+                            app:layout_constraintTop_toBottomOf="@+id/titleLayour">
+
+                            <androidx.recyclerview.widget.RecyclerView
+                                android:id="@+id/rvEvaluation"
+                                android:layout_width="match_parent"
+                                android:layout_height="match_parent"
+                                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+                        </com.scwang.smartrefresh.layout.SmartRefreshLayout>
+                    </androidx.constraintlayout.widget.ConstraintLayout>
+                </com.google.android.material.card.MaterialCardView>
             </androidx.constraintlayout.widget.ConstraintLayout>
         </com.google.android.material.card.MaterialCardView>
-
     </androidx.constraintlayout.widget.ConstraintLayout>
-
 </layout>

+ 69 - 0
evaluation/src/main/res/layout/item_examination.xml

@@ -0,0 +1,69 @@
+<?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.evaluation.entity.ExaminationRecord" />
+    </data>
+
+    <LinearLayout
+        android:id="@+id/examinationLayout"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/divider_98px"
+        android:gravity="center_vertical"
+        android:orientation="horizontal">
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:gravity="center"
+            android:text="@{data.title}"
+            android:textColor="@color/color_FF333333"
+            android:textSize="@dimen/divider_24px"
+            android:textStyle="bold" />
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:gravity="center"
+            android:text="@{data.described}"
+            android:textColor="@color/color_FF333333"
+            android:textSize="@dimen/divider_24px"
+            android:textStyle="bold" />
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:gravity="center"
+            android:text='@{data.examinationCount}'
+            android:textColor="@color/color_FF333333"
+            android:textSize="@dimen/divider_24px"
+            android:textStyle="bold" />
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:gravity="center"
+            android:text='@{data.examinationScore}'
+            android:textColor="@color/color_FF333333"
+            android:textSize="@dimen/divider_24px"
+            android:textStyle="bold" />
+
+        <androidx.appcompat.widget.AppCompatImageView
+            android:id="@+id/imageArrow"
+            android:layout_width="@dimen/divider_48px"
+            android:layout_height="@dimen/divider_62px"
+            android:layout_marginEnd="@dimen/divider_114px"
+            android:background="@mipmap/icon_question_arrow"
+            android:scaleType="centerInside" />
+    </LinearLayout>
+</layout>

BIN
evaluation/src/main/res/mipmap-xxhdpi/icon_question_arrow.png


+ 1 - 0
evaluation/src/main/res/values/colors.xml

@@ -88,4 +88,5 @@
     <color name="color_FF1AA8FD" tools:ignore="ResourceName">#FF1AA8FD</color>
     <color name="color_FF15C6FF" tools:ignore="ResourceName">#FF15C6FF</color>
     <color name="color_FF2B9DFF" tools:ignore="ResourceName">#FF2B9DFF</color>
+    <color name="color_FFFFFFFF" tools:ignore="ResourceName">#FFFFFFFF</color>
 </resources>