1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package safeluck.drive.evaluation.DB.lightdb
 
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
 
/**DriveJudge
 * Created by lzw on 2021/1/15. 09:46:49
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
class LightDefaultViewModel internal constructor(private  val lightDefaultRepository: LightDefaultRepository): ViewModel() {
    var allDefaultQuestion2Answers = lightDefaultRepository.getLightUseQuestions()
    fun  deleteItem(lightUseQuestions: LightUseQuestions){
        viewModelScope.launch {
            lightDefaultRepository.removeItem(lightUseQuestions)
        }
    }
    @ExperimentalCoroutinesApi
    override fun onCleared() {
        super.onCleared()
        viewModelScope.cancel()
    }
 
    fun updateQuestion2Answer(questionId: Int, answ: String) {
            viewModelScope.launch {
                lightDefaultRepository.updateQuest2Answer(questionId,answ)
            }
    }
 
    fun addItem(questionId: Int, Question: String, flag: Int,answer:String) {
        viewModelScope.launch {
            lightDefaultRepository.addItem(questionId,Question,flag,answer)
        }
    }
}