Created
May 24, 2019 07:22
-
-
Save alfianyusufabdullah/1683e66b8cee24745e0891bd1569d0e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MainAdapter(private val teams: List<Team>) | |
: RecyclerView.Adapter<TeamViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TeamViewHolder { | |
return TeamViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent))) | |
} | |
override fun onBindViewHolder(holder: TeamViewHolder, position: Int) { | |
holder.bindItem(teams[position]) | |
} | |
override fun getItemCount(): Int = teams.size | |
} | |
class TeamUI : AnkoComponent<ViewGroup> { | |
override fun createView(ui: AnkoContext<ViewGroup>): View { | |
return with(ui) { | |
linearLayout { | |
lparams(width = matchParent, height = wrapContent) | |
padding = dip(16) | |
orientation = LinearLayout.HORIZONTAL | |
imageView { | |
id = team_badge | |
}.lparams{ | |
height = dip(50) | |
width = dip(50) | |
} | |
textView { | |
id = team_name | |
textSize = 16f | |
}.lparams{ | |
margin = dip(15) | |
} | |
} | |
} | |
} | |
} | |
class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view){ | |
private val teamBadge: ImageView = view.find(team_badge) | |
private val teamName: TextView = view.find(team_name) | |
fun bindItem(teams: Team) { | |
Picasso.get().load(teams.teamBadge).into(teamBadge) | |
teamName.text = teams.teamName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment