Skip to content

Reformat ThreadAdapter onBindViewHolder(payload) #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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