2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.adapter
|
2018-11-30 01:06:16 +00:00
|
|
|
|
|
|
|
import android.app.Activity
|
2020-01-17 17:19:06 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-03-25 12:43:43 +00:00
|
|
|
import android.widget.TextView
|
2018-11-30 01:06:16 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.model.Contributor
|
|
|
|
import code.name.monkey.retromusic.util.RetroUtil.openUrl
|
2020-02-25 14:45:41 +00:00
|
|
|
import code.name.monkey.retromusic.views.RetroShapeableImageView
|
2019-09-16 18:02:40 +00:00
|
|
|
import com.bumptech.glide.Glide
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-09-09 13:04:53 +00:00
|
|
|
class ContributorAdapter(
|
2020-01-17 17:19:06 +00:00
|
|
|
private var contributors: List<Contributor>
|
2019-09-09 13:04:53 +00:00
|
|
|
) : RecyclerView.Adapter<ContributorAdapter.ViewHolder>() {
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
|
|
return if (viewType == HEADER) {
|
|
|
|
ViewHolder(
|
|
|
|
LayoutInflater.from(parent.context).inflate(
|
|
|
|
R.layout.item_contributor_header,
|
|
|
|
parent,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else ViewHolder(
|
|
|
|
LayoutInflater.from(parent.context).inflate(
|
|
|
|
R.layout.item_contributor,
|
|
|
|
parent,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2019-09-09 13:04:53 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
companion object {
|
|
|
|
const val HEADER: Int = 0
|
|
|
|
const val ITEM: Int = 1
|
|
|
|
}
|
2019-09-09 13:04:53 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
|
|
return if (position == 0) {
|
|
|
|
HEADER
|
|
|
|
} else {
|
|
|
|
ITEM
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
val contributor = contributors[position]
|
|
|
|
holder.bindData(contributor)
|
|
|
|
holder.itemView.setOnClickListener {
|
|
|
|
openUrl(it?.context as Activity, contributors[position].link)
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return contributors.size
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|
|
|
val title: TextView = itemView.findViewById(R.id.title)
|
|
|
|
val text: TextView = itemView.findViewById(R.id.text)
|
2020-02-25 14:45:41 +00:00
|
|
|
val image: RetroShapeableImageView = itemView.findViewById(R.id.icon)
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
internal fun bindData(contributor: Contributor) {
|
|
|
|
title.text = contributor.name
|
|
|
|
text.text = contributor.summary
|
2020-02-25 14:45:41 +00:00
|
|
|
Glide.with(image.context)
|
|
|
|
.load(contributor.profileImage)
|
2020-01-17 17:19:06 +00:00
|
|
|
.error(R.drawable.ic_account_white_24dp)
|
2020-02-25 14:45:41 +00:00
|
|
|
.placeholder(R.drawable.ic_account_white_24dp)
|
|
|
|
.dontAnimate()
|
|
|
|
.into(image)
|
2020-01-17 17:19:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|