Skip to content

Commit

Permalink
Merge pull request #1707 from Infomaniak/format-threadAdapter-code
Browse files Browse the repository at this point in the history
Reformat ThreadAdapter `onBindViewHolder(payload)`
  • Loading branch information
KevinBoulongne authored Feb 22, 2024
2 parents 4fdd090 + 9988357 commit 69fb9a0
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,30 @@ class ThreadAdapter(
val item = items[position]
if (item is Message && holder is MessageViewHolder) with(holder.binding) {
when (payload) {
NotifyType.TOGGLE_LIGHT_MODE -> {
isThemeTheSameMap[item.uid] = !isThemeTheSameMap[item.uid]!!
holder.toggleContentAndQuoteTheme(item.uid)
}
NotifyType.TOGGLE_LIGHT_MODE -> holder.handleToggleLightModePayload(item.uid)
NotifyType.RE_RENDER -> reloadVisibleWebView()
NotifyType.FAILED_MESSAGE -> {
messageLoader.isGone = true
failedLoadingErrorMessage.isVisible = true
if (isExpandedMap[item.uid] == true) onExpandedMessageLoaded(item.uid)
}
NotifyType.ONLY_REBIND_CALENDAR_ATTENDANCE -> {
val attendees = item.latestCalendarEventResponse?.calendarEvent?.attendees ?: emptyList()
holder.binding.calendarEvent.onlyUpdateAttendance(attendees)
}
NotifyType.FAILED_MESSAGE -> handleFailedMessagePayload(item.uid)
NotifyType.ONLY_REBIND_CALENDAR_ATTENDANCE -> handleCalendarAttendancePayload(item)
}
}
}.getOrDefault(Unit)

private fun MessageViewHolder.handleToggleLightModePayload(messageUid: String) {
isThemeTheSameMap[messageUid] = !isThemeTheSameMap[messageUid]!!
toggleContentAndQuoteTheme(messageUid)
}

private fun ItemMessageBinding.handleFailedMessagePayload(messageUid: String) {
messageLoader.isGone = true
failedLoadingErrorMessage.isVisible = true
if (isExpandedMap[messageUid] == true) onExpandedMessageLoaded(messageUid)
}

private fun ItemMessageBinding.handleCalendarAttendancePayload(message: Message) {
val attendees = message.latestCalendarEventResponse?.calendarEvent?.attendees ?: emptyList()
calendarEvent.onlyUpdateAttendance(attendees)
}

override fun onBindViewHolder(holder: ThreadAdapterViewHolder, position: Int) {

val item = items[position]
Expand Down

0 comments on commit 69fb9a0

Please sign in to comment.