From 31e1d9fd929c405a0b4acf15c70dde8662def369 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sun, 16 May 2021 03:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E5=9B=A2=E4=B8=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=8B=E6=8B=89=E8=8F=9C=E5=8D=95=20?= =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=95=8C=E9=9D=A2=E6=8B=86=E5=88=86=E4=B8=BA?= =?UTF-8?q?=E5=85=A5=E5=9B=A2=E7=94=B3=E8=AF=B7=E8=A1=A8=E5=92=8C=E5=85=A5?= =?UTF-8?q?=E5=9B=A2=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csams/association/model/ExamViewModel.kt | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt b/app/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt index fae7464..bcff8c9 100644 --- a/app/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt +++ b/app/src/main/java/com/gyf/csams/association/model/ExamViewModel.kt @@ -2,8 +2,10 @@ package com.gyf.csams.association.model import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.viewModelScope import com.gyf.csams.uikit.ScrollList import com.gyf.csams.uikit.StringForm +import kotlinx.coroutines.launch import kotlin.random.Random /** @@ -174,20 +176,22 @@ class ExamViewModel:ScrollList() { * */ override fun load() { - _data.value?.apply { - repeat(initSize) { - if (Random.nextBoolean()){ - add(OpenQuestionsVo(question = StringForm(formDesc = "问题",textLength = QUESTION_TEXT_LENGTH,value = "这是一道开放题:$size"))) - } else{ - add( - ChoiceQuestionVo( - question = StringForm(formDesc = "问题",textLength = QUESTION_TEXT_LENGTH,value = "这是一道选择题:$size"), - answers = ('A'..'D').map { StringForm(formDesc = "选项",textLength = ANSWER_TEXT_LENGTH,value = "选项$it") }, - rightAnswer = Random.nextInt(ANSWER_SIZE) + viewModelScope.launch { + _data.value?.apply { + repeat(initSize) { + if (Random.nextBoolean()){ + add(OpenQuestionsVo(question = StringForm(formDesc = "问题",textLength = QUESTION_TEXT_LENGTH,value = "这是一道开放题:$size"))) + } else{ + add( + ChoiceQuestionVo( + question = StringForm(formDesc = "问题",textLength = QUESTION_TEXT_LENGTH,value = "这是一道选择题:$size"), + answers = ('A'..'D').map { StringForm(formDesc = "选项",textLength = ANSWER_TEXT_LENGTH,value = "选项$it") }, + rightAnswer = Random.nextInt(ANSWER_SIZE) + ) ) - ) - } + } + } } } }