Created
May 27, 2018 17:34
-
-
Save bltuckerdevblog/c3a5fa85d6cfa342bd28553c9a5f1f44 to your computer and use it in GitHub Desktop.
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
@Singleton | |
class TeamDiffCallback @Inject constructor() : DiffUtil.ItemCallback<Team>() { | |
override fun areItemsTheSame(oldItem: Team, newItem: Team): Boolean { | |
return oldItem.teamId == newItem.teamId && oldItem.competitionId == newItem.competitionId | |
} | |
override fun areContentsTheSame(oldItem: Team, newItem: Team): Boolean { | |
return oldItem.name == newItem.name && oldItem.crestUrl == newItem.crestUrl && oldItem.shortName == newItem.shortName | |
} | |
} |
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
class TeamNameAdapter @Inject constructor(teamDiffCallback: TeamDiffCallback) : PagedListAdapter<Team, TeamViewHolder>(teamDiffCallback) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TeamViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
return TeamViewHolder(layoutInflater.inflate(R.layout.team_view_item, parent,false)) | |
} | |
override fun onBindViewHolder(holder: TeamViewHolder, position: Int) { | |
val safeTeam = getItem(position) ?: return | |
holder.bind(safeTeam) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment