Skip to content

Instantly share code, notes, and snippets.

@patrick-elmquist
Last active December 16, 2018 19:41
Show Gist options
  • Save patrick-elmquist/ace14be89940ebea3f3a71918cac868b to your computer and use it in GitHub Desktop.
Save patrick-elmquist/ace14be89940ebea3f3a71918cac868b to your computer and use it in GitHub Desktop.
class ShowViewHolder(view: View) : ViewHolder(view) {
private val title = itemView.title
private val description = itemView.description
private val thumbnail = itemView.thumbnail
private val poster = itemView.poster
private val interpolator = FastOutLinearInInterpolator()
/**
* Offset the thumb and text with a factor [-1.0..1.0] of the total width
*/
var offset: Float = 0f
set(v) {
field = v.coerceIn(-1f, 1f)
val direction = if (field < 0) -1f else 1f
val interpolatedValue = interpolator.getInterpolation(abs(field))
val translationX = direction * interpolatedValue * itemView.measuredWidth
title.translationX = translationX
description.translationX = translationX
thumbnail.translationX = translationX
}
fun bind(viewModel: Show) {
title.setText(viewModel.title)
description.setText(viewModel.description)
thumbnail.setImageResource(viewModel.image)
poster.setImageResource(viewModel.image)
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment