summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-08-04 20:10:38 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-08-04 20:10:38 +0000
commit0400e59e5d4a0140e98af01ad1acbc83d3f3f0a7 (patch)
tree330dce9f43a1961bf8170f1aa95c8a27ac32da8d
parent0a410243dea33f204764000be81814e541dcae48 (diff)
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.
-rw-r--r--android/app/src/main/java/org/terst/doot/widget/ui/QuickAddActivity.kt33
1 files changed, 27 insertions, 6 deletions
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<String>()
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"}")
}
}
},