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) {
|
if (wantToCreate) {
|
||||||
CreationDialog(
|
CreationDialog(
|
||||||
annuler = {model.setCreation(false)},
|
annuler = {(model::setCreation)(false)},
|
||||||
confirmer = {model.setCreation(false)},
|
|
||||||
model = model
|
model = model
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +113,6 @@ fun HomeScreen(padding: PaddingValues, model: HomeViewModel = viewModel()) {
|
||||||
@Composable
|
@Composable
|
||||||
fun CreationDialog(
|
fun CreationDialog(
|
||||||
annuler: () -> Unit,
|
annuler: () -> Unit,
|
||||||
confirmer: () -> Unit,
|
|
||||||
model : HomeViewModel = viewModel()
|
model : HomeViewModel = viewModel()
|
||||||
) {
|
) {
|
||||||
val sujet by model.sujet
|
val sujet by model.sujet
|
||||||
|
@ -126,13 +124,12 @@ fun CreationDialog(
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
sujet,
|
sujet,
|
||||||
label = { Text("Nouveau sujet") },
|
label = { Text("Nouveau sujet") },
|
||||||
onValueChange = { model.onSujetChange(it) }
|
onValueChange = model::onSujetChange
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(
|
Button(
|
||||||
// TODO : on ajoute le sujet dans la liste des sujets
|
onClick = model::addSet,
|
||||||
onClick = confirmer,
|
|
||||||
content = { Text("Ajouter") }
|
content = { Text("Ajouter") }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import androidx.room.RoomDatabase
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [SetQuestions::class, Question::class, Sets::class],
|
entities = [SetQuestions::class, Question::class, Sets::class],
|
||||||
version = 1,
|
version = 2,
|
||||||
)
|
)
|
||||||
abstract class QuestionsDB : RoomDatabase() {
|
abstract class QuestionsDB : RoomDatabase() {
|
||||||
abstract fun memoDao(): MemoDao
|
abstract fun memoDao(): MemoDao
|
||||||
|
|
|
@ -4,7 +4,7 @@ import androidx.room.Entity
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(indices = [Index(value = ["name"])])
|
@Entity(indices = [Index(value = ["name"], unique = true)])
|
||||||
data class SetQuestions(
|
data class SetQuestions(
|
||||||
@PrimaryKey(autoGenerate = true) val idSet: Int = 0,
|
@PrimaryKey(autoGenerate = true) val idSet: Int = 0,
|
||||||
val name: String,
|
val name: String,
|
||||||
|
|
|
@ -56,6 +56,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sujet.value = ""
|
sujet.value = ""
|
||||||
|
wantToCreate.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue