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