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.
This commit is contained in:
Anderson Mesquita 2019-06-24 09:32:06 -04:00
parent bb8b1fc58f
commit 8e95ed75ab
1 changed files with 11 additions and 15 deletions

View File

@ -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);
private void onFragmentLoaded(List<FeedItem> episodes) {
this.episodes = episodes;
listAdapter.notifyDataSetChanged();
} else {
createRecycleAdapter();
recyclerView.setVisibility(View.GONE);
emptyView.updateAdapter(listAdapter);
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)));
}