permanar

next match adapter

Nov 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.96 KB | None | 0 0
  1. package com.oende.futbolapps.main
  2.  
  3. import android.support.v7.widget.RecyclerView
  4. import android.view.View
  5. import android.view.ViewGroup
  6. import android.widget.LinearLayout
  7. import android.widget.TextView
  8. import com.oende.futbolapps.R.id.match_id
  9. import com.oende.futbolapps.R.id.match_title
  10. import com.oende.futbolapps.model.NextMatch
  11. import org.jetbrains.anko.*
  12.  
  13. class NextMatchAdapter(private val teams: List<NextMatch>)
  14.     : RecyclerView.Adapter<NextMatchViewHolder>() {
  15.  
  16.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NextMatchViewHolder {
  17.         return NextMatchViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent)))
  18.     }
  19.  
  20.     override fun onBindViewHolder(holder: NextMatchViewHolder, position: Int) {
  21.         holder.bindItem(teams[position])
  22.     }
  23.  
  24.     override fun getItemCount(): Int = teams.size
  25.  
  26. }
  27.  
  28. class TeamUI : AnkoComponent<ViewGroup> {
  29.     override fun createView(ui: AnkoContext<ViewGroup>): View {
  30.         return with(ui) {
  31.             linearLayout {
  32.                 lparams(width = matchParent, height = wrapContent)
  33.                 padding = dip(16)
  34.                 orientation = LinearLayout.HORIZONTAL
  35.  
  36.                 textView {
  37.                     id = match_id
  38.                 }.lparams{
  39.                     height = dip(50)
  40.                     width = dip(50)
  41.                 }
  42.  
  43.                 textView {
  44.                     id = match_title
  45.                     textSize = 16f
  46.                 }.lparams{
  47.                     margin = dip(15)
  48.                 }
  49.  
  50.             }
  51.         }
  52.     }
  53.  
  54. }
  55.  
  56. class NextMatchViewHolder(view: View) : RecyclerView.ViewHolder(view){
  57.  
  58.     private val matchId: TextView = view.find(match_id)
  59.     private val matchTitle: TextView = view.find(match_title)
  60.  
  61.     fun bindItem(teams: NextMatch) {
  62. //        Picasso.get().load(teams.matchId).into(teamBadge)
  63.         matchId.text = teams.matchId
  64.         matchTitle.text = teams.matchTitle
  65.     }
  66. }
Add Comment
Please, Sign In to add comment