Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nitinsurana/cbdb17a396f84a8bae758045275815af to your computer and use it in GitHub Desktop.
Save nitinsurana/cbdb17a396f84a8bae758045275815af to your computer and use it in GitHub Desktop.
quick design for categories
List<Integer> parent_categories
************************************************************
HomeFragment
lstCategoryWrapper -> parent_categories.forEach(pc-> viewModel.getCategory(pc.id))
.stream()
.collect(List<LiveData<Resource<CategoryWrapper>>>)
lstCategoryWrapper.forEach(LiveData<Resource≤CategoryWrapper>>> liveData->{
sliderFragment.create(liveData).attachToHomeFragment()
})
************************************************************
HomeViewModel
-> getCategory(id){
return categoryRepository.get(id): LiveData<Resource<CategoryWrapper>>
}
************************************************************
SliderFragment
onViewCreate(){
//show loader
liveData.observe(resource->{
switch(resource.status)
case SUCCESS:
//remove loader (check materialx bounce_dots example)
recyclerView.setAdapter(resource.getData().getChildFragmentList())
binding.setCategory(resource.getData().getCategory());
//See https://imgur.com/a/51xfrQ7 for example
case FAILURE:
//Remove loader & show error
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment