Skip to content

Instantly share code, notes, and snippets.

@AlexPrestonSB
Created November 5, 2019 23:05
Show Gist options
  • Save AlexPrestonSB/2d153f09bb5b5dc16e4f2b669e368629 to your computer and use it in GitHub Desktop.
Save AlexPrestonSB/2d153f09bb5b5dc16e4f2b669e368629 to your computer and use it in GitHub Desktop.
Shows implementation for how to bind your views
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