Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. @Override
  2.     public void onActivityCreated(Bundle savedInstanceState) {
  3.         super.onActivityCreated(savedInstanceState);
  4.         categoryViewModel = ViewModelProviders.of(this).get(CategoryViewModel.class);
  5.  
  6.         CombinedLiveData<Resource<List<Category>>, Resource<List<Category>>> categoryAndRegions = new CombinedLiveData<>(categoryViewModel.getCategories(Constants.NEWS_CATEGORY_SET), categoryViewModel.getCategories(Constants.CATEGORIES_REGIONS));
  7.  
  8.         categoryAndRegions.observe(getViewLifecycleOwner(), resourceResourcePair -> {
  9.             if (resourceResourcePair != null) {
  10.                 if (resourceResourcePair.first.status == Resource.Status.LOADING || resourceResourcePair.second.status == Resource.Status.LOADING) {
  11.                     loadingView.setVisibility(View.VISIBLE);
  12.                 }
  13.  
  14.                 if (resourceResourcePair.first.status == Resource.Status.SUCCESS || resourceResourcePair.second.status == Resource.Status.SUCCESS) {
  15.                     if (mIsRegionsView) {
  16.                         sectionsAdapter.submitList(resourceResourcePair.second.data);
  17.                     } else {
  18.                         resourceResourcePair.first.data.add(0, new Category(
  19.                                 -1,
  20.                                 Constants.CATEGORIES_REGIONS,
  21.                                 getString(R.string.regions),
  22.                                 "",
  23.                                 "",
  24.                                 "",
  25.                                 "",
  26.                                 "",
  27.                                 "",
  28.                                 "",
  29.                                 "",
  30.                                 "",
  31.                                 ""));
  32.                         sectionsAdapter.submitList(resourceResourcePair.first.data);
  33.                     }
  34.                 }
  35.             }
  36.         });
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement