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
40
41
42
43
44
45
46
47
48
49
50
51
package safeluck.drive.evaluation.DB.lightdb
 
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
 
/**DriveJudge
 * Created by lzw on 2021/1/15. 10:01:31
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
class LightDefaultRepository private constructor(
        private val lightdefaulDao: LightUseQuestionsDao
){
    suspend fun removeItem(lightusequest:LightUseQuestions){
        withContext(IO){
            lightdefaulDao.deleteItem(lightusequest)
        }
    }
 
 
 
    fun getLightUseQuestions() = lightdefaulDao.getLightUseQuestions()
   suspend fun updateQuest2Answer(questionId: Int, answ: String) {
       withContext(IO){
 
        lightdefaulDao.updateAnswer(questionId,answ)
       }
    }
 
    suspend fun addItem(questionId: Int, question: String, flag: Int,answ:String) {
        withContext(IO){
 
            var lightquest = LightUseQuestions()
            lightquest.question  = question
            lightquest.id = questionId
            lightquest.flag = flag
            lightquest.answer = answ
            lightdefaulDao.insertQuestion(lightquest)
        }
    }
 
 
    companion object{
        @Volatile
        private var instance:LightDefaultRepository ?= null
 
        fun getInstance(lightdefaulDao: LightUseQuestionsDao)= instance?: synchronized(this){
                instance?: LightDefaultRepository(lightdefaulDao).also { instance = it }
        }
    }
}