This commit is contained in:
Mylloon 2024-01-08 09:16:15 +01:00
parent 4f25c2d266
commit 93e490d1cd
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 24 additions and 13 deletions

View file

@ -150,4 +150,3 @@ fun <T: Any> ShowDialog(
dialog() dialog()
} }
} }

View file

@ -35,7 +35,7 @@ fun PlayScreen(
navController: NavController, navController: NavController,
snackbarHostState: SnackbarHostState, snackbarHostState: SnackbarHostState,
idSet: Int, idSet: Int,
model: PlayViewModel = viewModel() model: PlayViewModel = viewModel(),
) { ) {
// First update the list of questions // First update the list of questions
model.updateQuestionList(idSet) model.updateQuestionList(idSet)
@ -85,7 +85,7 @@ fun Play(
question: Question?, question: Question?,
reponse: String, reponse: String,
correction: AnswerType?, correction: AnswerType?,
delay: Int delay: Int,
) { ) {
val context = LocalContext.current val context = LocalContext.current
@ -94,7 +94,10 @@ fun Play(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
if (question == null) { if (question == null) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(context.getString(R.string.no_question), fontSize = 30.sp) Text(context.getString(R.string.no_question), fontSize = 30.sp)
} }
} else { } else {
@ -163,7 +166,7 @@ fun SnackbarAnswer(
model: PlayViewModel, model: PlayViewModel,
snackbarHostState: SnackbarHostState, snackbarHostState: SnackbarHostState,
cpt: Int, cpt: Int,
correction: AnswerType? correction: AnswerType?,
) { ) {
val context = LocalContext.current val context = LocalContext.current
if (correction != null) { if (correction != null) {

View file

@ -67,9 +67,11 @@ class ModifySetViewModel(application: Application) : AndroidViewModel(applicatio
fun modifAction() { fun modifAction() {
action.value = ActionModifySet.MODIFICATION action.value = ActionModifySet.MODIFICATION
} }
fun ajoutAction() { fun ajoutAction() {
action.value = ActionModifySet.AJOUT action.value = ActionModifySet.AJOUT
} }
fun supprAction() { fun supprAction() {
action.value = ActionModifySet.SUPPRIMER action.value = ActionModifySet.SUPPRIMER
} }

View file

@ -6,12 +6,12 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey import androidx.datastore.preferences.core.intPreferencesKey
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import fr.uparis.diamantkennel.memorisationapplication.DELAY
import fr.uparis.diamantkennel.memorisationapplication.MemoApplication import fr.uparis.diamantkennel.memorisationapplication.MemoApplication
import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_BAD import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_BAD
import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_DONE import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_DONE
import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_GOOD import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_GOOD
import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_TRIED import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_TRIED
import fr.uparis.diamantkennel.memorisationapplication.DELAY
import fr.uparis.diamantkennel.memorisationapplication.data.Question import fr.uparis.diamantkennel.memorisationapplication.data.Question
import fr.uparis.diamantkennel.memorisationapplication.dataStore import fr.uparis.diamantkennel.memorisationapplication.dataStore
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -47,7 +47,9 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
dao.loadQuestions(setId).collect { questionList -> dao.loadQuestions(setId).collect { questionList ->
questions.value = questionList.shuffled() questions.value = questionList.shuffled()
if (questions.value.isNotEmpty()) { if (questions.value.isNotEmpty()) {
datastore.edit { it[statsKeyTotal] = (it[statsKeyTotal] ?: 0) + 1 } datastore.edit {
it[statsKeyTotal] = (it[statsKeyTotal] ?: 0) + 1
}
} }
updateQuestion() updateQuestion()
} }
@ -106,7 +108,8 @@ class PlayViewModel(application: Application) : AndroidViewModel(application) {
} }
fun checkAnswer() { fun checkAnswer() {
val probaReponse = calcSimilarite(currentQuestion.value!!.reponse, proposedAnswer.value) val probaReponse =
calcSimilarite(currentQuestion.value!!.reponse, proposedAnswer.value)
if (probaReponse >= .70f) { if (probaReponse >= .70f) {
evaluatedAnswer.value = AnswerType.GOOD evaluatedAnswer.value = AnswerType.GOOD
} else { } else {

View file

@ -15,9 +15,9 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.work.PeriodicWorkRequest import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager import androidx.work.WorkManager
import fr.uparis.diamantkennel.memorisationapplication.DELAY
import fr.uparis.diamantkennel.memorisationapplication.HOUR import fr.uparis.diamantkennel.memorisationapplication.HOUR
import fr.uparis.diamantkennel.memorisationapplication.MINUTE import fr.uparis.diamantkennel.memorisationapplication.MINUTE
import fr.uparis.diamantkennel.memorisationapplication.DELAY
import fr.uparis.diamantkennel.memorisationapplication.MemoApplication import fr.uparis.diamantkennel.memorisationapplication.MemoApplication
import fr.uparis.diamantkennel.memorisationapplication.RappelWorker import fr.uparis.diamantkennel.memorisationapplication.RappelWorker
import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_BAD import fr.uparis.diamantkennel.memorisationapplication.STATS_TOTAL_BAD
@ -51,7 +51,8 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
val statTotalGood = datastore.data.map { it[statsKeyTotalGood] ?: 0 } val statTotalGood = datastore.data.map { it[statsKeyTotalGood] ?: 0 }
val statTotalBad = datastore.data.map { it[statsKeyTotalBad] ?: 0 } val statTotalBad = datastore.data.map { it[statsKeyTotalBad] ?: 0 }
var prefConfigTime = datastore.data.map { TimeConfig(it[notifH] ?: 8, it[notifM] ?: 0) } var prefConfigTime =
datastore.data.map { TimeConfig(it[notifH] ?: 8, it[notifM] ?: 0) }
var deletionDB = mutableStateOf(false) var deletionDB = mutableStateOf(false)
var deletionStat = mutableStateOf(false) var deletionStat = mutableStateOf(false)
@ -159,12 +160,15 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
fun dismissDeletionDB() { fun dismissDeletionDB() {
deletionDB.value = false deletionDB.value = false
} }
fun dismissDeletionStat() { fun dismissDeletionStat() {
deletionStat.value = false deletionStat.value = false
} }
fun dismissNotif() { fun dismissNotif() {
notif.value = false notif.value = false
} }
fun dismissDelayRequest() { fun dismissDelayRequest() {
delayRequest.value = false delayRequest.value = false
} }