summaryrefslogtreecommitdiff
path: root/android/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'android/app/src/main/java')
-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"}")
}
}
},