[UI] Fix updating event dialog when editing or removing.

This commit is contained in:
Kuba Szczodrzyński 2021-04-14 10:16:22 +02:00
parent 5eaa754401
commit ec765c9070
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
2 changed files with 14 additions and 3 deletions

View File

@ -32,7 +32,7 @@ import kotlin.coroutines.CoroutineContext
class EventDetailsDialog( class EventDetailsDialog(
val activity: AppCompatActivity, val activity: AppCompatActivity,
val event: EventFull, var event: EventFull,
val onShowListener: ((tag: String) -> Unit)? = null, val onShowListener: ((tag: String) -> Unit)? = null,
val onDismissListener: ((tag: String) -> Unit)? = null val onDismissListener: ((tag: String) -> Unit)? = null
) : CoroutineScope { ) : CoroutineScope {
@ -139,6 +139,7 @@ class EventDetailsDialog(
launch(Dispatchers.Default) { launch(Dispatchers.Default) {
app.db.eventDao().replace(event) app.db.eventDao().replace(event)
} }
update()
b.checkDoneButton.isChecked = true b.checkDoneButton.isChecked = true
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
@ -149,6 +150,7 @@ class EventDetailsDialog(
launch(Dispatchers.Default) { launch(Dispatchers.Default) {
app.db.eventDao().replace(event) app.db.eventDao().replace(event)
} }
update()
} }
} }
b.checkDoneButton.attachToastHint(R.string.hint_mark_as_done) b.checkDoneButton.attachToastHint(R.string.hint_mark_as_done)
@ -160,6 +162,14 @@ class EventDetailsDialog(
activity, activity,
event.profileId, event.profileId,
editingEvent = event, editingEvent = event,
onSaveListener = {
if (it == null) {
dialog.dismiss()
return@EventManualDialog
}
event = it
update()
},
onShowListener = onShowListener, onShowListener = onShowListener,
onDismissListener = onDismissListener onDismissListener = onDismissListener
) )
@ -327,8 +337,6 @@ class EventDetailsDialog(
removeEventDialog?.dismiss() removeEventDialog?.dismiss()
dialog.dismiss() dialog.dismiss()
Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show()
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_AGENDA)
activity.reloadTarget()
} }
private fun openInCalendar() { launch { private fun openInCalendar() { launch {

View File

@ -48,6 +48,7 @@ class EventManualDialog(
val defaultTime: Time? = null, val defaultTime: Time? = null,
val defaultType: Long? = null, val defaultType: Long? = null,
val editingEvent: EventFull? = null, val editingEvent: EventFull? = null,
val onSaveListener: ((event: EventFull?) -> Unit)? = null,
val onShowListener: ((tag: String) -> Unit)? = null, val onShowListener: ((tag: String) -> Unit)? = null,
val onDismissListener: ((tag: String) -> Unit)? = null val onDismissListener: ((tag: String) -> Unit)? = null
) : CoroutineScope { ) : CoroutineScope {
@ -596,6 +597,7 @@ class EventManualDialog(
} }
} }
onSaveListener?.invoke(eventObject.withMetadata(metadataObject))
dialog.dismiss() dialog.dismiss()
Toast.makeText(activity, R.string.saved, Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.saved, Toast.LENGTH_SHORT).show()
} }
@ -608,6 +610,7 @@ class EventManualDialog(
} }
removeEventDialog?.dismiss() removeEventDialog?.dismiss()
onSaveListener?.invoke(null)
dialog.dismiss() dialog.dismiss()
Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show()
} }