From b5ff4ec22b089566b89334104d01966cda3df88e Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Mon, 5 Oct 2026 01:36:36 -0700 Subject: [PATCH] send the first usage note after leaving the choices, not on the switch --- .../app/seb3thehacker/gearslip/stats/UsageStats.kt | 10 ++++++++-- .../seb3thehacker/gearslip/ui/UsageStatsChoices.kt | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/stats/UsageStats.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/stats/UsageStats.kt index 3629b6b..c97517d 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/stats/UsageStats.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/stats/UsageStats.kt @@ -78,8 +78,14 @@ object UsageStats { .putBoolean("share_phone", choices.phone) .putBoolean("share_cars", choices.cars) .apply() - if (enabled) sendSoon(context) - else prefs(context).edit().remove(KEY_CARS).remove(KEY_SENT_DAY).apply() + // Turning it on sends nothing yet: the driver may still be ticking boxes. The first note + // waits for [choicesClosed]. + if (!enabled) prefs(context).edit().remove(KEY_CARS).remove(KEY_SENT_DAY).apply() + } + + /** The driver left the screen with the usage note choices: send today's note if it's due. */ + fun choicesClosed(context: Context) { + if (prefs(context).getString(KEY_SENT_DAY, null) != LocalDate.now().toString()) sendSoon(context) } /** Gearslip was opened: send today's note unless one already went out. */ diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/UsageStatsChoices.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/UsageStatsChoices.kt index bf94ca7..4a06381 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/UsageStatsChoices.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/UsageStatsChoices.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -80,6 +81,8 @@ internal fun ColumnScope.UsageStatsRows(showNote: Boolean) { var choices by remember { mutableStateOf(UsageStats.choices(context)) } var noteOpen by remember { mutableStateOf(false) } fun save() = UsageStats.set(context, on, choices) + // Nothing goes out while the choices are on screen; leaving them sends the first note. + DisposableEffect(Unit) { onDispose { UsageStats.choicesClosed(context) } } SettingsRow( "Send usage notes", @@ -180,7 +183,13 @@ internal fun UsageStatsPrompt() { ) } }, - confirmButton = { TextButton(onClick = { UsageStats.set(context, true); show = false }) { Text("Turn on") } }, + confirmButton = { + TextButton(onClick = { + UsageStats.set(context, true) + show = false + UsageStats.choicesClosed(context) + }) { Text("Turn on") } + }, dismissButton = { TextButton(onClick = { UsageStats.set(context, false); show = false }) { Text("No thanks") } }, ) }