feat(notifications): Add accept/decline support
This commit is contained in:
parent
7a0f3cea06
commit
8c57542934
|
@ -131,10 +131,30 @@ class NotificationsActivity : AppCompatActivity() {
|
||||||
private fun handleNotificationAction(notification: NotificationResponse, action: NotificationAdapter.Action, position: Int) {
|
private fun handleNotificationAction(notification: NotificationResponse, action: NotificationAdapter.Action, position: Int) {
|
||||||
when (action) {
|
when (action) {
|
||||||
NotificationAdapter.Action.ACCEPT -> {
|
NotificationAdapter.Action.ACCEPT -> {
|
||||||
// TODO: Handle accept action
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val invitationId = notification.data
|
||||||
|
RetrofitClient.invitationService.acceptInvitation(invitationId)
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@NotificationsActivity, "Invitation accepted", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
// Also mark the notification as read after the interaction
|
||||||
|
if (!notification.read) handleNotificationClick(notification, position, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NotificationAdapter.Action.DECLINE -> {
|
NotificationAdapter.Action.DECLINE -> {
|
||||||
// TODO: Handle decline action
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val invitationId = notification.data
|
||||||
|
RetrofitClient.invitationService.declineInvitation(invitationId)
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@NotificationsActivity, "Invitation declined", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
// Also mark the notification as read after the interaction
|
||||||
|
if (!notification.read) handleNotificationClick(notification, position, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NotificationAdapter.Action.VIEW_EVENT -> {
|
NotificationAdapter.Action.VIEW_EVENT -> {
|
||||||
// TODO: Handle viewing the event
|
// TODO: Handle viewing the event
|
||||||
|
@ -142,7 +162,7 @@ class NotificationsActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleNotificationClick(notification: NotificationResponse, position: Int) {
|
private fun handleNotificationClick(notification: NotificationResponse, position: Int, sendToast: Boolean = true) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val updatedNotification =
|
val updatedNotification =
|
||||||
RetrofitClient.notificationsService.markNotificationRead(notification.id)
|
RetrofitClient.notificationsService.markNotificationRead(notification.id)
|
||||||
|
@ -151,7 +171,10 @@ class NotificationsActivity : AppCompatActivity() {
|
||||||
val adapter = rvNotifications.adapter as NotificationAdapter
|
val adapter = rvNotifications.adapter as NotificationAdapter
|
||||||
adapter.notifyItemChanged(position)
|
adapter.notifyItemChanged(position)
|
||||||
|
|
||||||
Toast.makeText(this@NotificationsActivity, "Marked as read", Toast.LENGTH_SHORT).show()
|
if (sendToast) {
|
||||||
|
Toast.makeText(this@NotificationsActivity, "Marked as read", Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue