minor changes
This commit is contained in:
parent
7ca1044a96
commit
cb9a063e68
4 changed files with 45 additions and 59 deletions
|
@ -7,7 +7,7 @@ import android.content.Context
|
|||
import android.os.Build
|
||||
import fr.uparis.diamantkennel.memorisationapplication.data.QuestionsDB
|
||||
|
||||
const val CHANNEL_ID = "MY_CHANNEL_ID"
|
||||
const val CHANNEL_ID = "REMINDERS"
|
||||
|
||||
class MemoApplication : Application() {
|
||||
val database: QuestionsDB by lazy { QuestionsDB.getDataBase(this) }
|
||||
|
|
|
@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
|
@ -77,10 +78,9 @@ fun SettingsScreen(padding: PaddingValues, model: SettingsViewModel = viewModel(
|
|||
CleanStatDialog(model::cleanStats) { cleanStatRequest = false }
|
||||
}
|
||||
|
||||
if (choiceTimeNotifRequest)
|
||||
{
|
||||
if (choiceTimeNotifRequest) {
|
||||
ChoiceTimeNotifDialog(
|
||||
{ (model::choiceTimeNotif)(state, context) },
|
||||
{ model.choiceTimeNotif(state, context) },
|
||||
{ choiceTimeNotifRequest = false },
|
||||
state
|
||||
)
|
||||
|
@ -96,35 +96,10 @@ fun SettingsScreen(padding: PaddingValues, model: SettingsViewModel = viewModel(
|
|||
Divider(color = Color.Gray)
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
|
||||
Text(text = "Gestion", fontSize = 30.sp)
|
||||
Text(text = context.getString(R.string.notification), fontSize = 30.sp)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
onClick = { deletionDBRequest = true },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = colorResource(id = R.color.red))
|
||||
) {
|
||||
Text(text = context.getString(R.string.main_button_deletebase))
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = { cleanStatRequest = true },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = colorResource(id = R.color.red))
|
||||
) {
|
||||
Text(text = context.getString(R.string.clean_stat_button))
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
Divider(color = Color.Gray)
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
|
||||
Text(text = "Notifications", fontSize = 30.sp)
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
enabled = !permissionNotif,
|
||||
|
@ -143,6 +118,30 @@ fun SettingsScreen(padding: PaddingValues, model: SettingsViewModel = viewModel(
|
|||
Text(text = context.getString(R.string.time_notif_button))
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
Divider(color = Color.Gray)
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
|
||||
Text(text = context.getString(R.string.gestion), fontSize = 30.sp)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
onClick = { deletionDBRequest = true },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = colorResource(id = R.color.red))
|
||||
) {
|
||||
Text(text = context.getString(R.string.main_button_deletebase))
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = { cleanStatRequest = true },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = colorResource(id = R.color.red))
|
||||
) {
|
||||
Text(text = context.getString(R.string.clean_stat_button))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +196,7 @@ fun CleanStatDialog(confirm: () -> Unit, dismiss: () -> Unit) =
|
|||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChoiceTimeNotifDialog(confirm: () -> Unit, dismiss: () -> Unit, state: TimePickerState) {
|
||||
Dialog(onDismissRequest = { dismiss() }) {
|
||||
Dialog(onDismissRequest = dismiss) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
|
@ -209,23 +208,16 @@ fun ChoiceTimeNotifDialog(confirm: () -> Unit, dismiss: () -> Unit, state: TimeP
|
|||
modifier = Modifier.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = LocalContext.current.getString(R.string.time_notif), fontSize = 30.sp)
|
||||
Text(text = LocalContext.current.getString(R.string.time_notif_desc))
|
||||
Text(
|
||||
text = LocalContext.current.getString(R.string.time_notif),
|
||||
fontSize = 30.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
TimePicker(state = state, layoutType = TimePickerLayoutType.Vertical)
|
||||
Spacer(modifier = Modifier.padding(top = 10.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(onClick = dismiss) {
|
||||
Text(text = LocalContext.current.getString(R.string.no))
|
||||
}
|
||||
Button(onClick = confirm) {
|
||||
Text(text = LocalContext.current.getString(R.string.yes))
|
||||
}
|
||||
Text(text = LocalContext.current.getString(R.string.confirm))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Application
|
|||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
@ -49,6 +48,8 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||
val statTotalGood = stats.data.map { it[statsKeyTotalGood] ?: 0 }
|
||||
val statTotalBad = stats.data.map { it[statsKeyTotalBad] ?: 0 }
|
||||
|
||||
var prefConfig = stats.data.map { TimeConfig(it[notifH] ?: 8, it[notifM] ?: 0) }
|
||||
|
||||
val deletionDB = mutableStateOf(false)
|
||||
val deletionStat = mutableStateOf(false)
|
||||
var notif = mutableStateOf(false)
|
||||
|
@ -81,7 +82,6 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||
state.hour,
|
||||
state.minute
|
||||
)
|
||||
Log.d("Periodic", "config=$newConfig")
|
||||
save(newConfig)
|
||||
schedule(newConfig, context)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||
context.checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun save(config: TimeConfig) {
|
||||
private fun save(config: TimeConfig) {
|
||||
viewModelScope.launch {
|
||||
stats.edit {
|
||||
it[notifH] = config.hour
|
||||
|
@ -114,13 +114,6 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||
}
|
||||
}
|
||||
|
||||
val prefConfig = stats.data.map {
|
||||
TimeConfig(
|
||||
it[notifH] ?: 8,
|
||||
it[notifM] ?: 0
|
||||
)
|
||||
}
|
||||
|
||||
private fun schedule(config: TimeConfig, context: Context) {
|
||||
val wm = WorkManager.getInstance(context)
|
||||
wm.cancelAllWork()
|
||||
|
@ -136,10 +129,9 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||
if (target.before(now))
|
||||
target.add(Calendar.DAY_OF_YEAR, 1)
|
||||
val delta = target.timeInMillis - now.timeInMillis
|
||||
val request = PeriodicWorkRequest.Builder(RappelWorker::class.java, 1, TimeUnit.DAYS)
|
||||
|
||||
return PeriodicWorkRequest.Builder(RappelWorker::class.java, 1, TimeUnit.DAYS)
|
||||
.setInitialDelay(delta, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
Log.d("Periodic", "request: $request")
|
||||
return request
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,5 +57,7 @@
|
|||
<string name="notif_reminder_content">Il est temps de réviser !</string>
|
||||
<string name="time_notif_button">Modifier heure de rappel</string>
|
||||
<string name="time_notif">Choix heure de rappel</string>
|
||||
<string name="time_notif_desc">Choisissez l\'heure à laquelle vous souhaitez être notifié</string>
|
||||
<string name="gestion">Gestion</string>
|
||||
<string name="notification">Notifications</string>
|
||||
<string name="confirm">Confirmer</string>
|
||||
</resources>
|
||||
|
|
Reference in a new issue