Created
August 26, 2020 11:07
-
-
Save ronnieotieno/8267d57e55e377e670f4d0125eb59540 to your computer and use it in GitHub Desktop.
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 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