From 0400e59e5d4a0140e98af01ad1acbc83d3f3f0a7 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Tue, 4 Aug 2026 20:10:38 +0000 Subject: Widget quick-add: surface errors instead of failing silently addTask()'s failure path had no .onFailure handler, so a failed POST (network hiccup, server down) left the Add sheet just sitting there with zero feedback -- looked like the button did nothing. Also: the five calls chained after a successful addTask (updateTask, reschedule, setTaskProject, setTaskLabels, setTaskRecurrence) were still unchecked, so a task could get created with silently-dropped metadata even with the addTask fix in place. Both paths now collect and toast what failed; the task itself still gets created and the sheet still closes, since aborting would leave a task that already exists server-side with no way to tell the user without a duplicate. --- .../org/terst/doot/widget/ui/QuickAddActivity.kt | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'android/app/src/main/java/org/terst/doot/widget') diff --git a/android/app/src/main/java/org/terst/doot/widget/ui/QuickAddActivity.kt b/android/app/src/main/java/org/terst/doot/widget/ui/QuickAddActivity.kt index 18373c0..980f286 100644 --- a/android/app/src/main/java/org/terst/doot/widget/ui/QuickAddActivity.kt +++ b/android/app/src/main/java/org/terst/doot/widget/ui/QuickAddActivity.kt @@ -30,6 +30,10 @@ import org.terst.doot.widget.data.dataStore class QuickAddActivity : ComponentActivity() { + private fun toast(message: String) { + android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_LONG).show() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -75,26 +79,43 @@ class QuickAddActivity : ComponentActivity() { }, onAdd = { title, description -> lifecycleScope.launch { - val r = repo() ?: return@launch + val r = repo() + if (r == null) { + toast("Not configured: set server URL/token in Settings") + return@launch + } r.addTask(title).onSuccess { id -> + // addTask succeeding only means the task exists -- each + // follow-up call below can independently fail (network + // blip, expired token) without aborting the others, so + // collect what didn't stick rather than assume success + // silently the way the pre-fix code did for addTask itself. + val failed = mutableListOf() if (description.isNotBlank()) { - r.updateTask(id, title, description) + r.updateTask(id, title, description).onFailure { failed += "description" } } - dueDate?.let { r.reschedule(id, "doot", it) } - project?.let { r.setTaskProject(id, it.id) } + dueDate?.let { if (r.reschedule(id, "doot", it).isFailure) failed += "due date" } + project?.let { if (r.setTaskProject(id, it.id).isFailure) failed += "project" } if (labels.isNotEmpty()) { // Same "assign a default color the first time it's colored" // rule as the edit popup's label editor, so a quick-add task // with new labels doesn't leave them silently uncolored. val newlyAdded = labels.filter { it !in knownLabels } newlyAdded.forEach { label -> r.setLabelColor(label, colorForNewLabel(label)) } - r.setTaskLabels(id, labels) + if (r.setTaskLabels(id, labels).isFailure) failed += "labels" + } + recurrence?.let { + if (r.setTaskRecurrence(id, it.freq, it.interval, it.weekdays).isFailure) failed += "recurrence" } - recurrence?.let { r.setTaskRecurrence(id, it.freq, it.interval, it.weekdays) } r.fetchAndPersist(this@QuickAddActivity) DootWidget().updateAll(this@QuickAddActivity) + if (failed.isNotEmpty()) { + toast("Task added, but couldn't save: ${failed.joinToString(", ")}") + } finish() + }.onFailure { e -> + toast("Couldn't add task: ${e.message ?: "network error"}") } } }, -- cgit v1.2.3