mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
send the first usage note after leaving the choices, not on the switch
This commit is contained in:
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_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. */
|
||||
|
||||
@@ -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") } },
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user