From 8e95ed75abb68100afd2572831bc71ee8dd51917 Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Mon, 24 Jun 2019 09:32:06 -0400 Subject: [PATCH] Fix recycler and empty view hide/show logic The `emptyViewHandler` already handles hiding and showing both the empty view and the recycler view on data changes, so this commit removes this part of the logic from the episodes fragment. It also hides the empty view right after creating the recycle adapter for the first time (when the fragment is created) to prevent the progress bar and the empty view from being displayed at the same time. `createRecycleAdapter()` signature was changed to make it explicit that it depends on both the `recyclerView` and `emptyViewHandler`. Similarly, `onFragmentLoaded()`, since it also depends on the new data that gets loaded. --- .../fragment/AllEpisodesFragment.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index 922e7d321..391140258 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -309,21 +309,19 @@ public class AllEpisodesFragment extends Fragment { emptyView.attachToRecyclerView(recyclerView); emptyView.setTitle(R.string.no_all_episodes_head_label); emptyView.setMessage(R.string.no_all_episodes_label); - emptyView.hide(); - createRecycleAdapter(); + createRecycleAdapter(recyclerView, emptyView); + emptyView.hide(); return root; } - private void onFragmentLoaded() { - if (episodes.size() > 0) { - recyclerView.setVisibility(View.VISIBLE); - listAdapter.notifyDataSetChanged(); - } else { - createRecycleAdapter(); - recyclerView.setVisibility(View.GONE); - emptyView.updateAdapter(listAdapter); + private void onFragmentLoaded(List episodes) { + this.episodes = episodes; + listAdapter.notifyDataSetChanged(); + + if (episodes.size() == 0) { + createRecycleAdapter(recyclerView, emptyView); } restoreScrollPosition(); @@ -334,12 +332,12 @@ public class AllEpisodesFragment extends Fragment { * Currently, we need to recreate the list adapter in order to be able to undo last item via the * snackbar. See #3084 for details. */ - private void createRecycleAdapter() { + private void createRecycleAdapter(RecyclerView recyclerView, EmptyViewHandler emptyViewHandler) { MainActivity mainActivity = (MainActivity) getActivity(); listAdapter = new AllEpisodesRecycleAdapter(mainActivity, itemAccess, showOnlyNewEpisodes()); listAdapter.setHasStableIds(true); recyclerView.setAdapter(listAdapter); - emptyView.updateAdapter(listAdapter); + emptyViewHandler.updateAdapter(listAdapter); } private final AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { @@ -455,10 +453,8 @@ public class AllEpisodesFragment extends Fragment { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(data -> { - recyclerView.setVisibility(View.VISIBLE); progLoading.setVisibility(View.GONE); - episodes = data; - onFragmentLoaded(); + onFragmentLoaded(data); }, error -> Log.e(TAG, Log.getStackTraceString(error))); }