-
-
Save AlexPrestonSB/2d153f09bb5b5dc16e4f2b669e368629 to your computer and use it in GitHub Desktop.
Shows implementation for how to bind your views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | |
val message = messages.get(position) | |
var isNewDay = false | |
when { | |
(position < messages.size - 1) -> { | |
val previousMessage = messages.get(position + 1) | |
isNewDay = !DateUtil.isSameDay(message.createdAt, previousMessage.createdAt) | |
} | |
(position == messages.size - 1) -> { | |
isNewDay = true | |
} | |
} | |
when (holder.itemViewType) { | |
AppConstants.VIEW_TYPE_LOCATION_ME -> { | |
holder as MyLocationHolder | |
holder.bindView(context, messages.get(position) as UserMessage, isNewDay) | |
} | |
AppConstants.VIEW_TYPE_LOCATION_OTHER -> { | |
holder as OtherLocationHolder | |
holder.bindView(context, messages.get(position) as UserMessage, isNewDay) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment