From b5922d7280c657872303285d8da87718598e6cff Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 3 Jan 2024 22:53:05 +0100 Subject: [PATCH] fix: dismissing deletion dialog wasn't cancelling the deletion, also remove useless decorator in dao --- .../memorisationapplication/HomeScreen.kt | 20 +++++++++++-------- .../memorisationapplication/data/MemoDao.kt | 2 -- .../ui/HomeViewModel.kt | 8 ++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt index f94a00c..7638cfe 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt @@ -94,12 +94,14 @@ fun HomeScreen( if (deletionRequest) { DeletionDialog( + model::dismissDeleteOne, model::deleteSelected ) } if (deletionDBRequest) { DeletionDBDialog( + model::dismissDeleteAll, model::deleteAll ) } @@ -271,16 +273,18 @@ fun ErrorDialog(errMsg: String, dismiss: () -> Unit) = AlertDialog(onDismissRequ confirmButton = { Button(onClick = dismiss) { Text(text = "Ok") } }) @Composable -fun DeletionDialog(dismiss: () -> Unit) = AlertDialog(onDismissRequest = dismiss, - title = { Text(text = "Supprimer un jeu de question") }, - text = { Text(text = "Voulez-vous supprimer ce jeu de question ?") }, - confirmButton = { Button(onClick = dismiss) { Text(text = "Ok") } }) +fun DeletionDialog(dismiss: () -> Unit, confirm: () -> Unit) = + AlertDialog(onDismissRequest = dismiss, + title = { Text(text = "Supprimer un jeu de question") }, + text = { Text(text = "Voulez-vous supprimer ce jeu de question ?") }, + confirmButton = { Button(onClick = confirm) { Text(text = "Ok") } }) @Composable -fun DeletionDBDialog(dismiss: () -> Unit) = AlertDialog(onDismissRequest = dismiss, - title = { Text(text = "Supprimer la base de données") }, - text = { Text(text = "Voulez-vous supprimer la base de données ?") }, - confirmButton = { Button(onClick = dismiss) { Text(text = "Ok") } }) +fun DeletionDBDialog(dismiss: () -> Unit, confirm: () -> Unit) = + AlertDialog(onDismissRequest = dismiss, + title = { Text(text = "Supprimer la base de données") }, + text = { Text(text = "Voulez-vous supprimer la base de données ?") }, + confirmButton = { Button(onClick = confirm) { Text(text = "Ok") } }) @Composable fun ShowList( diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/MemoDao.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/MemoDao.kt index d88514b..0a074b3 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/MemoDao.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/MemoDao.kt @@ -4,7 +4,6 @@ import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.Query -import androidx.room.Transaction import kotlinx.coroutines.flow.Flow @Dao @@ -15,7 +14,6 @@ interface MemoDao { @Insert suspend fun insertQuestion(question: Question) - @Transaction @Query("SELECT * FROM SetQuestions") fun loadAllSets(): Flow> diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/HomeViewModel.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/HomeViewModel.kt index 8f6486f..4229d2a 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/HomeViewModel.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/ui/HomeViewModel.kt @@ -125,6 +125,14 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) { creation.value = false } + fun dismissDeleteOne() { + deletionSelect.value = false + } + + fun dismissDeleteAll() { + deletionDB.value = false + } + fun dismissModification() { modification.value = false }