Compare commits
1 commit
49f7a977dd
...
73d24ffdfc
Author | SHA1 | Date | |
---|---|---|---|
Peter Vacho | 73d24ffdfc |
|
@ -90,7 +90,11 @@ class NotificationsActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun getInvitationData(invitationId: String, rvPosition: Int): InvitationResponse? {
|
||||
return invitations[invitationId]
|
||||
val ret = invitations[invitationId]
|
||||
if (ret == null) {
|
||||
Log.w("NotificationsActivity", "NotificationAdapter requested unknown invitation: $invitationId")
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun getUserData(userId: String, rvPosition: Int?): UserResponse? {
|
||||
|
|
|
@ -88,33 +88,72 @@ class NotificationAdapter(
|
|||
val user = getUserData(usernameId, position)
|
||||
val username = user?.username ?: "Unknown User"
|
||||
|
||||
val statusSuffix = when (invitation.status) {
|
||||
"accepted" -> " [already accepted]"
|
||||
"declined" -> " [already declined]"
|
||||
"pending" -> ""
|
||||
else -> throw IllegalStateException("Unexpected invitation status: ${invitation.status} for invitation ID: ${invitation.id}")
|
||||
}
|
||||
|
||||
return when (notification.message) {
|
||||
"new-invitation" -> "You have received an event invitation from @$username"
|
||||
"invitation-accepted" -> "@$username has accepted your event invitation"
|
||||
"invitation-declined" -> "@$username has declined your event invitation"
|
||||
"new-invitation" -> "You have received an event invitation from @$username$statusSuffix"
|
||||
"invitation-accepted" -> "@$username has accepted your event invitation$statusSuffix"
|
||||
"invitation-declined" -> "@$username has declined your event invitation$statusSuffix"
|
||||
else -> throw IllegalArgumentException("Unexpected notification message: ${notification.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun handleInvitationActions(
|
||||
holder: NotificationViewHolder,
|
||||
notification: NotificationResponse,
|
||||
position: Int
|
||||
) {
|
||||
if (notification.event_type == "invitation") {
|
||||
val invitation = getInvitationData(notification.data, position)
|
||||
if (invitation == null) {
|
||||
// For deleted invitations, make all the buttons visible but unclickable & grayed out
|
||||
holder.invitationActions.visibility = View.VISIBLE
|
||||
holder.acceptButton.visibility = View.VISIBLE
|
||||
holder.declineButton.visibility = View.VISIBLE
|
||||
holder.viewEventButton.visibility = View.VISIBLE
|
||||
|
||||
holder.acceptButton.isEnabled = false
|
||||
holder.declineButton.isEnabled = false
|
||||
holder.viewEventButton.isEnabled = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
when (notification.message) {
|
||||
"new-invitation" -> {
|
||||
// Show Accept/Decline & View buttons
|
||||
holder.invitationActions.visibility = View.VISIBLE
|
||||
holder.acceptButton.visibility = View.VISIBLE
|
||||
holder.declineButton.visibility = View.VISIBLE
|
||||
holder.viewEventButton.visibility = View.VISIBLE
|
||||
when (invitation.status) {
|
||||
"pending" -> {
|
||||
// Show Accept/Decline & View buttons
|
||||
holder.invitationActions.visibility = View.VISIBLE
|
||||
holder.acceptButton.visibility = View.VISIBLE
|
||||
holder.declineButton.visibility = View.VISIBLE
|
||||
holder.viewEventButton.visibility = View.VISIBLE
|
||||
|
||||
holder.acceptButton.setOnClickListener {
|
||||
onActionClick(notification, Action.ACCEPT, position)
|
||||
}
|
||||
holder.declineButton.setOnClickListener {
|
||||
onActionClick(notification, Action.DECLINE, position)
|
||||
holder.acceptButton.setOnClickListener {
|
||||
onActionClick(notification, Action.ACCEPT, position)
|
||||
}
|
||||
holder.declineButton.setOnClickListener {
|
||||
onActionClick(notification, Action.DECLINE, position)
|
||||
}
|
||||
}
|
||||
"accepted", "declined" -> {
|
||||
// Show only View button
|
||||
holder.invitationActions.visibility = View.VISIBLE
|
||||
holder.acceptButton.visibility = View.GONE
|
||||
holder.declineButton.visibility = View.GONE
|
||||
holder.viewEventButton.visibility = View.VISIBLE
|
||||
|
||||
holder.viewEventButton.setOnClickListener {
|
||||
onActionClick(notification, Action.VIEW_EVENT, position)
|
||||
}
|
||||
}
|
||||
else -> throw IllegalStateException("Unexpected invitation status: ${invitation.status} for invite ID: ${invitation.id}")
|
||||
}
|
||||
}
|
||||
"invitation-accepted", "invitation-declined" -> {
|
||||
|
|
Loading…
Reference in a new issue