-
-
Notifications
You must be signed in to change notification settings - Fork 3
Loading, Content, Error
Yogesh Choudhary Paliyal edited this page Oct 12, 2021
·
1 revision
example : Hitting an api for loading showing a shimmer and then when API response came show the data or getting an error
private val mAdapter by lazy {
UniversalRecyclerAdapter.Builder<UserModel>(
lifecycleOwner = this,
content = UniversalAdapterViewType.Content(R.layout.item_user,
object : BasicListener<UserModel> {
override fun onClick(model: UserModel) {
Toast.makeText(this@LoadingListingActivity, model.name, Toast.LENGTH_SHORT)
.show()
}
}),
loading = UniversalAdapterViewType.Loading(R.layout.layout_loading_full_page, defaultLoadingItems = 1),
error = UniversalAdapterViewType.Error(R.layout.item_error)).build()
}
binding.recyclerView.adapter = mAdapter.getAdapter()
mViewModel.data.observe(this, Observer { data ->
// The data type is like Resource<List<T>>
// if data.status == Status.LOADING thenn it will show the loading view
// if data.status == Status.SUCCESS then it will show the content list
// if data.status == Status.ERROR then it will show the error View and data.message will be passed to view as message variable
mAdapter.updateContent(it)
})