send the first usage note after leaving the choices, not on the switch

This commit is contained in:
Seb3thehacker committed 2026-10-05 01:36:36 -07:00
1 parent 302dd6c344
commit b5ff4ec22b
2 files changed
+18 -3

No files matched your search

@@ -78,8 +78,14 @@ object UsageStats {
.putBoolean("share_phone", choices.phone) .putBoolean("share_phone", choices.phone)
.putBoolean("share_cars", choices.cars) .putBoolean("share_cars", choices.cars)
.apply() .apply()
if (enabled) sendSoon(context) // Turning it on sends nothing yet: the driver may still be ticking boxes. The first note
else prefs(context).edit().remove(KEY_CARS).remove(KEY_SENT_DAY).apply() // 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. */ /** Gearslip was opened: send today's note unless one already went out. */
@@ -25,6 +25,7 @@ import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@@ -80,6 +81,8 @@ internal fun ColumnScope.UsageStatsRows(showNote: Boolean) {
var choices by remember { mutableStateOf(UsageStats.choices(context)) } var choices by remember { mutableStateOf(UsageStats.choices(context)) }
var noteOpen by remember { mutableStateOf(false) } var noteOpen by remember { mutableStateOf(false) }
fun save() = UsageStats.set(context, on, choices) 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( SettingsRow(
"Send usage notes", "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") } }, dismissButton = { TextButton(onClick = { UsageStats.set(context, false); show = false }) { Text("No thanks") } },
) )
} }