Skip to content

Instantly share code, notes, and snippets.

@ronnieotieno
Created August 26, 2020 11:07
Show Gist options
  • Save ronnieotieno/8267d57e55e377e670f4d0125eb59540 to your computer and use it in GitHub Desktop.
Save ronnieotieno/8267d57e55e377e670f4d0125eb59540 to your computer and use it in GitHub Desktop.
class ProductLoadingStateAdapter :
LoadStateAdapter<ProductLoadingStateAdapter.LoadStateViewHolder>() {
override fun onBindViewHolder(holder: LoadStateViewHolder, loadState: LoadState) {
val progress = holder.itemView.progress_bar_item
val txtErrorMessage = holder.itemView.error_msg_item
if (loadState is LoadState.Loading) progress.visibility =
View.VISIBLE; txtErrorMessage.visibility = View.GONE
if (loadState is LoadState.Error) {
txtErrorMessage.visibility = View.VISIBLE
txtErrorMessage.text = loadState.error.localizedMessage
}
}
override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): LoadStateViewHolder {
return LoadStateViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.network_state_item, parent, false)
)
}
class LoadStateViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment