From 4566efc7f7442cada56da43f9e53e87cd6c19a77 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 4 Jan 2024 14:56:11 +0100 Subject: [PATCH] its better, no? --- .../memorisationapplication/ui/ModifySetViewModel.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/ModifySetViewModel.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/ModifySetViewModel.kt index 75b3d8f..e8638e7 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/ModifySetViewModel.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/ModifySetViewModel.kt @@ -11,15 +11,16 @@ import kotlinx.coroutines.launch class ModifySetViewModel(application: Application) : AndroidViewModel(application) { private val dao = (application as MemoApplication).database.memoDao() + private val initialId = -1 // invalid ID, mean that we don't have the ID yet - var setId = mutableStateOf(-1) + var setId = mutableStateOf(initialId) var questions = dao.loadQuestions(setId.value) var selection = mutableStateOf(null) var action = mutableStateOf(ActionModifySet.AUCUN) fun updateQuestionList(setId: Int) { - viewModelScope.launch(Dispatchers.IO) { - questions = dao.loadQuestions(setId) + if (setId != initialId) { + viewModelScope.launch(Dispatchers.IO) { questions = dao.loadQuestions(setId) } } }