Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader IA] Add "Followed P2s" item to dropdown menu #20057

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Stack;

Expand Down Expand Up @@ -210,9 +211,9 @@ public class ReaderPostListFragment extends ViewPagerFragment
private int mPostSearchAdapterPos;
private int mSiteSearchAdapterPos;
private int mSearchTabsPos = NO_POSITION;
private boolean mIsUpdating;
private boolean mIsFilterableScreen;
private boolean mIsFiltered = false;
@NonNull private final HashSet<UpdateAction> mCurrentUpdateActions = new HashSet<>();
/*
* called by post adapter to load older posts when user scrolls to the last post
*/
Expand Down Expand Up @@ -1181,8 +1182,7 @@ public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
}

if (savedInstanceState != null && savedInstanceState.getBoolean(ReaderConstants.KEY_IS_REFRESHING)) {
mIsUpdating = true;
mRecyclerView.setRefreshing(true);
setIsUpdating(true, UpdateAction.REQUEST_NEWER);
}

return rootView;
Expand Down Expand Up @@ -1699,7 +1699,7 @@ private void setEmptyTitleDescriptionAndButton(boolean requestFailed) {
setEmptyTitleAndDescriptionForBookmarksList();
return;
} else if (!NetworkUtils.isNetworkAvailable(getActivity())) {
mIsUpdating = false;
clearCurrentUpdateActions();
title = getString(R.string.reader_empty_posts_no_connection);
} else if (requestFailed) {
if (isSearching()) {
Expand Down Expand Up @@ -2304,7 +2304,7 @@ public void run() {
}

private boolean isUpdating() {
return mIsUpdating;
return mCurrentUpdateActions.size() > 0;
}

/*
Expand All @@ -2321,30 +2321,45 @@ private void showLoadingProgress(boolean showProgress) {
}
}

private void setIsUpdating(boolean isUpdating, UpdateAction updateAction) {
if (!isAdded() || mIsUpdating == isUpdating) {
if (!isUpdating) {
mRecyclerView.setRefreshing(false);
}
return;
}
private void clearCurrentUpdateActions() {
if (!isAdded() || !isUpdating()) return;

if (updateAction == UpdateAction.REQUEST_OLDER) {
// show/hide progress bar at bottom if these are older posts
showLoadingProgress(isUpdating);
} else if (isUpdating) {
// show swipe-to-refresh if update started
mRecyclerView.setRefreshing(true);
mCurrentUpdateActions.clear();
updateProgressIndicators();
}

private void setIsUpdating(boolean isUpdating, @NonNull UpdateAction updateAction) {
if (!isAdded()) return;

boolean isUiUpdateNeeded;
thomashorta marked this conversation as resolved.
Show resolved Hide resolved
if (isUpdating) {
isUiUpdateNeeded = mCurrentUpdateActions.add(updateAction);
} else {
// hide swipe-to-refresh progress if update is complete
isUiUpdateNeeded = mCurrentUpdateActions.remove(updateAction);
}

if (isUiUpdateNeeded) updateProgressIndicators();
}

private void updateProgressIndicators() {
if (!isUpdating()) {
// when there's no update in progress, hide the bottom and swipe-to-refresh progress bars
showLoadingProgress(false);
mRecyclerView.setRefreshing(false);
} else if (mCurrentUpdateActions.size() == 1 && mCurrentUpdateActions.contains(UpdateAction.REQUEST_OLDER)) {
// if only older posts are being updated, show only the bottom progress bar
showLoadingProgress(true);
mRecyclerView.setRefreshing(false);
} else {
// if anything else is being updated, show only the swipe-to-refresh progress bar
showLoadingProgress(false);
mRecyclerView.setRefreshing(true);
}
mIsUpdating = isUpdating;

// if swipe-to-refresh isn't active, keep it disabled during an update - this prevents
// doing a refresh while another update is already in progress
if (mRecyclerView != null && !mRecyclerView.isRefreshing()) {
mRecyclerView.setSwipeToRefreshEnabled(!isUpdating && isSwipeToRefreshSupported());
if (!mRecyclerView.isRefreshing()) {
mRecyclerView.setSwipeToRefreshEnabled(!isUpdating() && isSwipeToRefreshSupported());
}
}

Expand Down