/VideoLoadStateViewHolder.kt Secret
Created
May 22, 2022 11:05
Star
You must be signed in to star a gist
This file contains 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 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