Add swipe refresh layout

filtering
Floens 10 years ago
parent cb35d98854
commit da246aadae
  1. 22
      Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java
  2. 28
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java
  3. 10
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java
  4. 8
      Clover/app/src/main/java/org/floens/chan/ui/view/LoadView.java

@ -18,6 +18,7 @@
package org.floens.chan.ui.controller;
import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import org.floens.chan.Chan;
import org.floens.chan.controller.Controller;
@ -30,8 +31,9 @@ import java.util.List;
import de.greenrobot.event.EventBus;
public abstract class ThreadController extends Controller implements ThreadLayout.ThreadLayoutCallback, ImageViewerController.PreviewCallback, RootNavigationController.DrawerCallbacks {
public abstract class ThreadController extends Controller implements ThreadLayout.ThreadLayoutCallback, ImageViewerController.PreviewCallback, RootNavigationController.DrawerCallbacks, SwipeRefreshLayout.OnRefreshListener {
protected ThreadLayout threadLayout;
private SwipeRefreshLayout swipeRefreshLayout;
public ThreadController(Context context) {
super(context);
@ -45,7 +47,17 @@ public abstract class ThreadController extends Controller implements ThreadLayou
threadLayout = new ThreadLayout(context);
threadLayout.setCallback(this);
view = threadLayout;
swipeRefreshLayout = new SwipeRefreshLayout(context) {
@Override
public boolean canChildScrollUp() {
return threadLayout.canChildScrollUp();
}
};
swipeRefreshLayout.addView(threadLayout);
swipeRefreshLayout.setOnRefreshListener(this);
view = swipeRefreshLayout;
}
@Override
@ -73,6 +85,11 @@ public abstract class ThreadController extends Controller implements ThreadLayou
threadLayout.getPresenter().onForegroundChanged(message.inForeground);
}
@Override
public void onRefresh() {
threadLayout.refreshFromSwipe();
}
public void openPost(boolean open) {
threadLayout.openPost(open);
}
@ -114,6 +131,7 @@ public abstract class ThreadController extends Controller implements ThreadLayou
@Override
public void onShowPosts() {
swipeRefreshLayout.setRefreshing(false);
}
@Override

@ -66,21 +66,21 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
private enum Visible {
LOADING,
THREAD,
ERROR
ERROR;
}
private ThreadLayoutCallback callback;
private ThreadPresenter presenter;
private ThreadListLayout threadListLayout;
private ThreadListLayout threadListLayout;
private LinearLayout errorLayout;
private TextView errorText;
private Button errorRetryButton;
private PostPopupHelper postPopupHelper;
private Visible visible;
private ProgressDialog deletingDialog;
private boolean refreshedFromSwipe;
public ThreadLayout(Context context) {
super(context);
init();
@ -121,6 +121,14 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
}
}
public boolean canChildScrollUp() {
if (visible == Visible.THREAD) {
return threadListLayout.canChildScrollUp();
} else {
return true;
}
}
public boolean onBack() {
return threadListLayout.onBack();
}
@ -137,6 +145,11 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
threadListLayout.openReply(open);
}
public void refreshFromSwipe() {
refreshedFromSwipe = true;
presenter.requestData();
}
@Override
public void showPosts(ChanThread thread) {
threadListLayout.showPosts(thread, visible != Visible.THREAD);
@ -341,7 +354,12 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
this.visible = visible;
switch (visible) {
case LOADING:
setView(null);
View view = setView(null);
// TODO: cleanup
if (refreshedFromSwipe) {
refreshedFromSwipe = false;
view.setVisibility(View.GONE);
}
break;
case THREAD:
setView(threadListLayout);

@ -164,6 +164,16 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL
}
}
public boolean canChildScrollUp() {
View top = recyclerView.getChildAt(0);
if (top != null) {
if (top.getTop() == 0 && linearLayoutManager.findFirstVisibleItemPosition() == 0) {
return false;
}
}
return true;
}
public void cleanup() {
/*if (ChanBuild.DEVELOPER_MODE) {
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(showingThread.loadable);

@ -86,8 +86,8 @@ public class LoadView extends FrameLayout {
*
* @param newView the view or null for a progressbar.
*/
public void setView(View newView) {
setView(newView, true);
public View setView(View newView) {
return setView(newView, true);
}
/**
@ -97,7 +97,7 @@ public class LoadView extends FrameLayout {
* @param newView the view or null for a progressbar.
* @param animate should it be animated
*/
public void setView(View newView, boolean animate) {
public View setView(View newView, boolean animate) {
if (newView == null) {
FrameLayout progressBar = new FrameLayout(getContext());
progressBar.addView(new ProgressBar(getContext()), new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
@ -190,6 +190,8 @@ public class LoadView extends FrameLayout {
newView.setAlpha(1f);
addView(newView, getLayoutParamsForView(newView));
}
return newView;
}
public LayoutParams getLayoutParamsForView(View view) {

Loading…
Cancel
Save