Skip to content

Instantly share code, notes, and snippets.

@DivS-15
Created May 22, 2022 11:05
Show Gist options
  • Save DivS-15/375b2fd385a5230e5c3e0ae79f8d1e93 to your computer and use it in GitHub Desktop.
Save DivS-15/375b2fd385a5230e5c3e0ae79f8d1e93 to your computer and use it in GitHub Desktop.
class VideoLoadStateViewHolder(
private val binding: LoadstateViewholderLayoutBinding,
retry: () -> Unit
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.retryButton.setOnClickListener {
retry.invoke()
}
}
fun bind(loadState: LoadState){
binding.progressBar.isVisible = loadState is LoadState.Loading
binding.retryButton.isVisible = loadState is LoadState.Error
binding.retryText.isVisible = loadState is LoadState.Error
}
companion object{
fun create(parent: ViewGroup, retry: () -> Unit): VideoLoadStateViewHolder{
val view = LayoutInflater.from(parent.context).inflate(R.layout.loadstate_viewholder_layout, parent, false)
val binding = LoadstateViewholderLayoutBinding.bind(view)
return VideoLoadStateViewHolder(binding, retry)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment