From 65d07c40437d2d6a7810302d05c7e0ce29be0e26 Mon Sep 17 00:00:00 2001 From: Floens Date: Thu, 4 Jun 2015 19:31:29 +0200 Subject: [PATCH] Add reply FAB --- .../chan/ui/controller/BrowseController.java | 5 -- .../chan/ui/controller/ThreadController.java | 8 +-- .../ui/controller/ViewThreadController.java | 5 -- .../floens/chan/ui/layout/ThreadLayout.java | 58 ++++++++++++++----- .../chan/ui/layout/ThreadListLayout.java | 11 +++- .../main/res/layout/cell_thread_status.xml | 3 +- .../app/src/main/res/layout/layout_thread.xml | 38 ++++++++++++ 7 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 Clover/app/src/main/res/layout/layout_thread.xml diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/BrowseController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/BrowseController.java index 387c0231..02580378 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/BrowseController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/BrowseController.java @@ -44,7 +44,6 @@ import java.util.List; public class BrowseController extends ThreadController implements ToolbarMenuItem.ToolbarMenuItemCallback, ThreadLayout.ThreadLayoutCallback, FloatingMenu.FloatingMenuCallback { private static final int REFRESH_ID = 1; - private static final int POST_ID = 2; private static final int SEARCH_ID = 101; private static final int SHARE_ID = 102; @@ -68,7 +67,6 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte navigationItem.hasBack = false; menu.addItem(new ToolbarMenuItem(context, this, REFRESH_ID, R.drawable.ic_refresh_white_24dp)); - menu.addItem(new ToolbarMenuItem(context, this, POST_ID, R.drawable.ic_create_white_24dp)); ToolbarMenuItem overflow = menu.createOverflow(this); @@ -85,9 +83,6 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte case REFRESH_ID: threadLayout.getPresenter().requestData(); break; - case POST_ID: - openPost(true); - break; } } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java index d69aa7b9..3027bf25 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java @@ -19,8 +19,10 @@ package org.floens.chan.ui.controller; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; +import android.view.LayoutInflater; import org.floens.chan.Chan; +import org.floens.chan.R; import org.floens.chan.controller.Controller; import org.floens.chan.core.model.Loadable; import org.floens.chan.core.model.PostImage; @@ -45,7 +47,7 @@ public abstract class ThreadController extends Controller implements ThreadLayou EventBus.getDefault().register(this); - threadLayout = new ThreadLayout(context); + threadLayout = (ThreadLayout) LayoutInflater.from(context).inflate(R.layout.layout_thread, null); threadLayout.setCallback(this); swipeRefreshLayout = new SwipeRefreshLayout(context) { @Override @@ -90,10 +92,6 @@ public abstract class ThreadController extends Controller implements ThreadLayou threadLayout.refreshFromSwipe(); } - public void openPost(boolean open) { - threadLayout.openPost(open); - } - public void presentRepliesController(Controller controller) { presentController(controller); } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java index 8797c711..065b3916 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java @@ -38,7 +38,6 @@ import java.util.Arrays; import static org.floens.chan.utils.AndroidUtils.getAttrColor; public class ViewThreadController extends ThreadController implements ThreadLayout.ThreadLayoutCallback, ToolbarMenuItem.ToolbarMenuItemCallback { - private static final int POST_ID = 1; private static final int PIN_ID = 2; private static final int REFRESH_ID = 101; private static final int SEARCH_ID = 102; @@ -64,7 +63,6 @@ public class ViewThreadController extends ThreadController implements ThreadLayo navigationItem.hasDrawer = true; navigationItem.menu = new ToolbarMenu(context); - navigationItem.menu.addItem(new ToolbarMenuItem(context, this, POST_ID, R.drawable.ic_create_white_24dp)); pinItem = navigationItem.menu.addItem(new ToolbarMenuItem(context, this, PIN_ID, R.drawable.ic_bookmark_outline_white_24dp)); navigationItem.createOverflow(context, this, Arrays.asList( new FloatingMenuItem(REFRESH_ID, context.getString(R.string.action_reload)), @@ -154,9 +152,6 @@ public class ViewThreadController extends ThreadController implements ThreadLayo case PIN_ID: setPinIconState(threadLayout.getPresenter().pin()); break; - case POST_ID: - openPost(true); - break; } } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java index 4e7f89cc..8d743dc3 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java @@ -25,9 +25,12 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.DialogInterface; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.FloatingActionButton; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.animation.DecelerateInterpolator; import android.widget.Button; import android.widget.CheckBox; import android.widget.LinearLayout; @@ -62,16 +65,19 @@ import static org.floens.chan.utils.AndroidUtils.getString; /** * Wrapper around ThreadListLayout, so that it cleanly manages between loadbar and listview. */ -public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPresenterCallback, PostPopupHelper.PostPopupHelperCallback, View.OnClickListener { +public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.ThreadPresenterCallback, PostPopupHelper.PostPopupHelperCallback, View.OnClickListener, ThreadListLayout.ReplyLayoutStateCallback { private enum Visible { LOADING, THREAD, ERROR; } + private ThreadLayoutCallback callback; private ThreadPresenter presenter; + private LoadView loadView; + private FloatingActionButton replyButton; private ThreadListLayout threadListLayout; private LinearLayout errorLayout; @@ -81,26 +87,31 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres private Visible visible; private ProgressDialog deletingDialog; private boolean refreshedFromSwipe; + private boolean showingReplyButton = false; + public ThreadLayout(Context context) { super(context); - init(); } public ThreadLayout(Context context, AttributeSet attrs) { super(context, attrs); - init(); } public ThreadLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(); } - private void init() { + @Override + protected void onFinishInflate() { + super.onFinishInflate(); presenter = new ThreadPresenter(this); + loadView = (LoadView) findViewById(R.id.loadview); + replyButton = (FloatingActionButton) findViewById(R.id.reply_button); + replyButton.setOnClickListener(this); + threadListLayout = (ThreadListLayout) LayoutInflater.from(getContext()).inflate(R.layout.layout_thread_list, this, false); - threadListLayout.setCallbacks(presenter, presenter, presenter, presenter); + threadListLayout.setCallbacks(presenter, presenter, presenter, presenter, this); postPopupHelper = new PostPopupHelper(getContext(), presenter, this); @@ -118,6 +129,8 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres public void onClick(View v) { if (v == errorRetryButton) { presenter.requestData(); + } else if (v == replyButton) { + threadListLayout.openReply(true); } } @@ -141,15 +154,16 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres return presenter; } - public void openPost(boolean open) { - threadListLayout.openReply(open); - } - public void refreshFromSwipe() { refreshedFromSwipe = true; presenter.requestData(); } + @Override + public void replyLayoutOpen(boolean open) { + showReplyButton(!open); + } + @Override public void showPosts(ChanThread thread) { threadListLayout.showPosts(thread, visible != Visible.THREAD); @@ -285,7 +299,7 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres @Override public void quote(Post post, boolean withText) { - openPost(true); + threadListLayout.openReply(true); threadListLayout.getReplyPresenter().quote(post, withText); } @@ -339,6 +353,20 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres return postPopupHelper.isOpen(); } + private void showReplyButton(boolean show) { + if (show != showingReplyButton) { + showingReplyButton = show; + replyButton.animate() + .setInterpolator(new DecelerateInterpolator(2f)) + .setStartDelay(show ? 100 : 0) + .setDuration(200) + .alpha(show ? 1f : 0f) + .scaleX(show ? 1f : 0f) + .scaleY(show ? 1f : 0f) + .start(); + } + } + private void switchVisible(Visible visible) { if (this.visible != visible) { if (this.visible != null) { @@ -347,6 +375,7 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres threadListLayout.cleanup(); postPopupHelper.popAll(); showSearch(false); + showReplyButton(false); break; } } @@ -354,7 +383,7 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres this.visible = visible; switch (visible) { case LOADING: - View view = setView(null); + View view = loadView.setView(null); // TODO: cleanup if (refreshedFromSwipe) { refreshedFromSwipe = false; @@ -362,10 +391,11 @@ public class ThreadLayout extends LoadView implements ThreadPresenter.ThreadPres } break; case THREAD: - setView(threadListLayout); + loadView.setView(threadListLayout); + showReplyButton(true); break; case ERROR: - setView(errorLayout); + loadView.setView(errorLayout); break; } } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java index 8d30a968..d427e39d 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java @@ -53,6 +53,7 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL private PostAdapter postAdapter; private ChanThread showingThread; private ThreadListLayoutCallback callback; + private ReplyLayoutStateCallback replyLayoutStateCallback; private boolean replyOpen; public ThreadListLayout(Context context, AttributeSet attrs) { @@ -74,8 +75,11 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL recyclerView.setLayoutManager(linearLayoutManager); } - public void setCallbacks(PostAdapter.PostAdapterCallback postAdapterCallback, PostCell.PostCellCallback postCellCallback, ThreadStatusCell.Callback statusCellCallback, ThreadListLayoutCallback callback) { + public void setCallbacks(PostAdapter.PostAdapterCallback postAdapterCallback, PostCell.PostCellCallback postCellCallback, + ThreadStatusCell.Callback statusCellCallback, ThreadListLayoutCallback callback, + ReplyLayoutStateCallback replyLayoutStateCallback) { this.callback = callback; + this.replyLayoutStateCallback = replyLayoutStateCallback; postAdapter = new PostAdapter(recyclerView, postAdapterCallback, postCellCallback, statusCellCallback); recyclerView.setAdapter(postAdapter); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -109,6 +113,7 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL } else { AndroidUtils.hideKeyboard(reply); } + replyLayoutStateCallback.replyLayoutOpen(open); } } @@ -251,4 +256,8 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL void requestNewPostLoad(); } + + public interface ReplyLayoutStateCallback { + void replyLayoutOpen(boolean open); + } } diff --git a/Clover/app/src/main/res/layout/cell_thread_status.xml b/Clover/app/src/main/res/layout/cell_thread_status.xml index 7c176711..8afc2628 100644 --- a/Clover/app/src/main/res/layout/cell_thread_status.xml +++ b/Clover/app/src/main/res/layout/cell_thread_status.xml @@ -17,13 +17,14 @@ along with this program. If not, see . --> diff --git a/Clover/app/src/main/res/layout/layout_thread.xml b/Clover/app/src/main/res/layout/layout_thread.xml new file mode 100644 index 00000000..b07f431a --- /dev/null +++ b/Clover/app/src/main/res/layout/layout_thread.xml @@ -0,0 +1,38 @@ + + + + + + + +