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 49973bb..18d3be4 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/HomeScreen.kt @@ -53,8 +53,7 @@ fun HomeScreen(padding: PaddingValues, model: HomeViewModel = viewModel()) { if (wantToCreate) { CreationDialog( - annuler = {model.setCreation(false)}, - confirmer = {model.setCreation(false)}, + annuler = {(model::setCreation)(false)}, model = model ) } @@ -114,7 +113,6 @@ fun HomeScreen(padding: PaddingValues, model: HomeViewModel = viewModel()) { @Composable fun CreationDialog( annuler: () -> Unit, - confirmer: () -> Unit, model : HomeViewModel = viewModel() ) { val sujet by model.sujet @@ -126,13 +124,12 @@ fun CreationDialog( OutlinedTextField( sujet, label = { Text("Nouveau sujet") }, - onValueChange = { model.onSujetChange(it) } + onValueChange = model::onSujetChange ) }, confirmButton = { Button( - // TODO : on ajoute le sujet dans la liste des sujets - onClick = confirmer, + onClick = model::addSet, content = { Text("Ajouter") } ) }, diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/QuestionsDB.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/QuestionsDB.kt index 1e5705f..5537f53 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/QuestionsDB.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/QuestionsDB.kt @@ -7,7 +7,7 @@ import androidx.room.RoomDatabase @Database( entities = [SetQuestions::class, Question::class, Sets::class], - version = 1, + version = 2, ) abstract class QuestionsDB : RoomDatabase() { abstract fun memoDao(): MemoDao diff --git a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/SetQuestions.kt b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/SetQuestions.kt index 5636104..949fb9d 100644 --- a/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/SetQuestions.kt +++ b/app/src/main/java/fr/uparis/diamantkennel/memorisationapplication/data/SetQuestions.kt @@ -4,7 +4,7 @@ import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey -@Entity(indices = [Index(value = ["name"])]) +@Entity(indices = [Index(value = ["name"], unique = true)]) data class SetQuestions( @PrimaryKey(autoGenerate = true) val idSet: Int = 0, val name: String, 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 e9890a2..cf9ad8f 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 @@ -56,6 +56,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) { } sujet.value = "" + wantToCreate.value = false } }