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

@ -66,21 +66,21 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
private enum Visible { private enum Visible {
LOADING, LOADING,
THREAD, THREAD,
ERROR ERROR;
} }
private ThreadLayoutCallback callback; private ThreadLayoutCallback callback;
private ThreadPresenter presenter; private ThreadPresenter presenter;
private ThreadListLayout threadListLayout;
private ThreadListLayout threadListLayout;
private LinearLayout errorLayout; private LinearLayout errorLayout;
private TextView errorText; private TextView errorText;
private Button errorRetryButton; private Button errorRetryButton;
private PostPopupHelper postPopupHelper; private PostPopupHelper postPopupHelper;
private Visible visible; private Visible visible;
private ProgressDialog deletingDialog; private ProgressDialog deletingDialog;
private boolean refreshedFromSwipe;
public ThreadLayout(Context context) { public ThreadLayout(Context context) {
super(context); super(context);
init(); 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() { public boolean onBack() {
return threadListLayout.onBack(); return threadListLayout.onBack();
} }
@ -137,6 +145,11 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
threadListLayout.openReply(open); threadListLayout.openReply(open);
} }
public void refreshFromSwipe() {
refreshedFromSwipe = true;
presenter.requestData();
}
@Override @Override
public void showPosts(ChanThread thread) { public void showPosts(ChanThread thread) {
threadListLayout.showPosts(thread, visible != Visible.THREAD); threadListLayout.showPosts(thread, visible != Visible.THREAD);
@ -341,7 +354,12 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres
this.visible = visible; this.visible = visible;
switch (visible) { switch (visible) {
case LOADING: case LOADING:
setView(null); View view = setView(null);
// TODO: cleanup
if (refreshedFromSwipe) {
refreshedFromSwipe = false;
view.setVisibility(View.GONE);
}
break; break;
case THREAD: case THREAD:
setView(threadListLayout); 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() { public void cleanup() {
/*if (ChanBuild.DEVELOPER_MODE) { /*if (ChanBuild.DEVELOPER_MODE) {
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(showingThread.loadable); 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. * @param newView the view or null for a progressbar.
*/ */
public void setView(View newView) { public View setView(View newView) {
setView(newView, true); return setView(newView, true);
} }
/** /**
@ -97,7 +97,7 @@ public class LoadView extends FrameLayout {
* @param newView the view or null for a progressbar. * @param newView the view or null for a progressbar.
* @param animate should it be animated * @param animate should it be animated
*/ */
public void setView(View newView, boolean animate) { public View setView(View newView, boolean animate) {
if (newView == null) { if (newView == null) {
FrameLayout progressBar = new FrameLayout(getContext()); FrameLayout progressBar = new FrameLayout(getContext());
progressBar.addView(new ProgressBar(getContext()), new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); 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); newView.setAlpha(1f);
addView(newView, getLayoutParamsForView(newView)); addView(newView, getLayoutParamsForView(newView));
} }
return newView;
} }
public LayoutParams getLayoutParamsForView(View view) { public LayoutParams getLayoutParamsForView(View view) {

Loading…
Cancel
Save