create button works
This commit is contained in:
parent
c114ed74f6
commit
91bdab8f81
4 changed files with 6 additions and 8 deletions
|
@ -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") }
|
||||
)
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -56,6 +56,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
|||
}
|
||||
|
||||
sujet.value = ""
|
||||
wantToCreate.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue