Skip to content

Commit

Permalink
Pull-down-to-refresh for posts/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jul 31, 2016
1 parent 32795fe commit f27cfaf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Comment swiping
Ability to search comments (thanks to cpalasanu)
Ability to send and reply to private messages
Pull-down-to-refresh for posts/comments
Music is no longer paused when GIFs play (thanks to noughtmare and ccrama)
Fixed saving images with slashes in the path (thanks to 0xKD)
Action bar back button extended to allow clicking on text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -38,6 +39,7 @@
import org.quantumbadger.redreader.account.RedditAccountManager;
import org.quantumbadger.redreader.activities.BugReportActivity;
import org.quantumbadger.redreader.activities.CommentReplyActivity;
import org.quantumbadger.redreader.activities.OptionsMenuUtility;
import org.quantumbadger.redreader.adapters.FilteredCommentListingManager;
import org.quantumbadger.redreader.cache.CacheRequest;
import org.quantumbadger.redreader.common.General;
Expand Down Expand Up @@ -131,6 +133,15 @@ public CommentListingFragment(
final ScrollbarRecyclerViewManager recyclerViewManager
= new ScrollbarRecyclerViewManager(context, null, false);

if(parent instanceof OptionsMenuUtility.OptionsMenuCommentsListener) {
recyclerViewManager.enablePullToRefresh(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
((OptionsMenuUtility.OptionsMenuCommentsListener)parent).onRefreshComments();
}
});
}

mRecyclerView = recyclerViewManager.getRecyclerView();
mCommentListingManager.setLayoutManager((LinearLayoutManager) mRecyclerView.getLayoutManager());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -37,6 +38,7 @@
import org.quantumbadger.redreader.account.RedditAccount;
import org.quantumbadger.redreader.account.RedditAccountManager;
import org.quantumbadger.redreader.activities.BugReportActivity;
import org.quantumbadger.redreader.activities.OptionsMenuUtility;
import org.quantumbadger.redreader.activities.SessionChangeListener;
import org.quantumbadger.redreader.adapters.PostListingManager;
import org.quantumbadger.redreader.cache.CacheManager;
Expand Down Expand Up @@ -174,6 +176,15 @@ public PostListingFragment(
final ScrollbarRecyclerViewManager recyclerViewManager
= new ScrollbarRecyclerViewManager(context, null, false);

if(parent instanceof OptionsMenuUtility.OptionsMenuPostsListener) {
recyclerViewManager.enablePullToRefresh(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
((OptionsMenuUtility.OptionsMenuPostsListener)parent).onRefreshPosts();
}
});
}

mRecyclerView = recyclerViewManager.getRecyclerView();
mPostListingManager.setLayoutManager((LinearLayoutManager) mRecyclerView.getLayoutManager());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.quantumbadger.redreader.views;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand All @@ -29,6 +31,7 @@
public class ScrollbarRecyclerViewManager {

private final View mOuter;
private final SwipeRefreshLayout mSwipeRefreshLayout;
private final RecyclerView mRecyclerView;
private final FrameLayout mScrollbarFrame;
private final View mScrollbar;
Expand All @@ -41,10 +44,13 @@ public ScrollbarRecyclerViewManager(
final boolean attachToRoot) {

mOuter = LayoutInflater.from(context).inflate(R.layout.scrollbar_recyclerview, root, attachToRoot);
mSwipeRefreshLayout = (SwipeRefreshLayout) mOuter.findViewById(R.id.scrollbar_recyclerview_refreshlayout);
mRecyclerView = (RecyclerView) mOuter.findViewById(R.id.scrollbar_recyclerview_recyclerview);
mScrollbar = mOuter.findViewById(R.id.scrollbar_recyclerview_scrollbar);
mScrollbarFrame = (FrameLayout) mOuter.findViewById(R.id.scrollbar_recyclerview_scrollbarframe);

mSwipeRefreshLayout.setEnabled(false);

final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setHasFixedSize(true);
Expand Down Expand Up @@ -101,6 +107,11 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
});
}

public void enablePullToRefresh(@NonNull final SwipeRefreshLayout.OnRefreshListener listener) {
mSwipeRefreshLayout.setOnRefreshListener(listener);
mSwipeRefreshLayout.setEnabled(true);
}

private void showScrollbar() {
mScrollbar.animate().cancel();
mScrollbar.setAlpha(1f);
Expand Down
13 changes: 10 additions & 3 deletions src/main/res/layout/scrollbar_recyclerview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/scrollbar_recyclerview_recyclerview"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/scrollbar_recyclerview_refreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/scrollbar_recyclerview_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.v4.widget.SwipeRefreshLayout>

<FrameLayout
android:id="@+id/scrollbar_recyclerview_scrollbarframe"
Expand Down

0 comments on commit f27cfaf

Please sign in to comment.