Created
July 3, 2020 13:41
-
-
Save nitinsurana/cbdb17a396f84a8bae758045275815af to your computer and use it in GitHub Desktop.
quick design for categories
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
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