Skip to content

Commit

Permalink
Remove infintite scroll load indicator when reach end of feed.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Jan 26, 2016
1 parent e84ec07 commit 6b95ba1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions app/src/main/java/io/plaidapp/ui/FeedAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class FeedAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final @ColorInt int initialGifBadgeColor;

private List<PlaidItem> items;
private boolean showLoadingMore = false;
private PlaidItemSorting.NaturalOrderWeigher naturalOrderWeigher;
private ShotWeigher shotWeigher;
private StoryWeigher storyWeigher;
Expand Down Expand Up @@ -581,7 +582,7 @@ public long getItemId(int position) {

@Override
public int getItemCount() {
return getDataItemCount() + 1; // include loading footer
return getDataItemCount() + (showLoadingMore ? 1 : 0);
}

/**
Expand Down Expand Up @@ -611,6 +612,10 @@ public int getDataItemCount() {
return items.size();
}

private int getLoadingMoreItemPosition() {
return showLoadingMore ? getItemCount() - 1 : RecyclerView.NO_POSITION;
}

/**
* Which ViewHolder types require a divider decoration
*/
Expand All @@ -620,12 +625,17 @@ public Class[] getDividedViewHolderClasses() {

@Override
public void dataStartedLoading() {
notifyItemChanged(getItemCount());
if (showLoadingMore) return;
notifyItemInserted(getLoadingMoreItemPosition());
showLoadingMore = true;
}

@Override
public void dataFinishedLoading() {
notifyItemChanged(getItemCount());
if (!showLoadingMore) return;
showLoadingMore = false;
notifyItemRemoved(getLoadingMoreItemPosition());

}

/* package */ class DribbbleShotHolder extends RecyclerView.ViewHolder {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/plaidapp/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize
(HomeActivity.this),
grid.getPaddingRight() + insets.getSystemWindowInsetRight(), // landscape
grid.getPaddingBottom());
grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());

// inset the fab for the navbar
ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab
Expand Down

0 comments on commit 6b95ba1

Please sign in to comment.