From 077d3167a088272c759007ea29eaed517f075a70 Mon Sep 17 00:00:00 2001 From: Floens Date: Tue, 26 Dec 2017 20:53:48 +0100 Subject: [PATCH] add buttons for inserting quotes and spoilers. set the height of the preview based on the expand status. --- .../chan/core/presenter/ReplyPresenter.java | 33 ++++++++++++++-- .../floens/chan/ui/layout/ReplyLayout.java | 32 +++++++++++++++- .../main/res/layout/layout_reply_input.xml | 38 ++++++++++++++++++- Clover/app/src/main/res/values/strings.xml | 2 + 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java b/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java index 70773e62..b8c82f96 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java +++ b/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java @@ -163,6 +163,10 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP if (!loadable.isThreadMode()) { callback.openSubject(moreOpen); } + callback.openCommentQuoteButton(moreOpen); + if (board.spoilers) { + callback.openCommentSpoilerButton(moreOpen); + } if (previewOpen) { callback.openFileName(moreOpen); if (board.spoilers) { @@ -273,6 +277,14 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP highlightQuotes(); } + public void commentQuoteClicked() { + commentInsert(">"); + } + + public void commentSpoilerClicked() { + commentInsert("[spoiler]", "[/spoiler]"); + } + public void quote(Post post, boolean withText) { callback.loadViewsIntoDraft(draft); @@ -293,13 +305,20 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP } } - draft.comment = new StringBuilder(draft.comment).insert(draft.selection, textToInsert).toString(); + commentInsert(textToInsert); - draft.selection += textToInsert.length(); + highlightQuotes(); + } - callback.loadDraftIntoViews(draft); + private void commentInsert(String insertBefore) { + commentInsert(insertBefore, ""); + } - highlightQuotes(); + private void commentInsert(String insertBefore, String insertAfter) { + draft.comment = new StringBuilder(draft.comment) + .insert(draft.selection, insertBefore + insertAfter).toString(); + draft.selection += insertBefore.length(); + callback.loadDraftIntoViews(draft); } @Override @@ -330,6 +349,8 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP callback.openMessage(false, true, "", false); callback.setExpanded(false); callback.openSubject(false); + callback.openCommentQuoteButton(false); + callback.openCommentSpoilerButton(false); callback.openNameOptions(false); callback.openFileName(false); callback.openSpoiler(false, false); @@ -438,6 +459,10 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP void openSubject(boolean open); + void openCommentQuoteButton(boolean open); + + void openCommentSpoilerButton(boolean open); + void openFileName(boolean open); void setFileName(String fileName); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java index 42fd27c1..77e1e8af 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java @@ -27,7 +27,9 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.FrameLayout; @@ -85,6 +87,9 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply private EditText options; private EditText fileName; private LinearLayout nameOptions; + private ViewGroup commentButtons; + private Button commentQuoteButton; + private Button commentSpoilerButton; private SelectionListeningEditText comment; private TextView commentCounter; private CheckBox spoiler; @@ -133,6 +138,9 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply options = replyInputLayout.findViewById(R.id.options); fileName = replyInputLayout.findViewById(R.id.file_name); nameOptions = replyInputLayout.findViewById(R.id.name_options); + commentButtons = replyInputLayout.findViewById(R.id.comment_buttons); + commentQuoteButton = replyInputLayout.findViewById(R.id.comment_quote); + commentSpoilerButton = replyInputLayout.findViewById(R.id.comment_spoiler); comment = replyInputLayout.findViewById(R.id.comment); commentCounter = replyInputLayout.findViewById(R.id.comment_counter); spoiler = replyInputLayout.findViewById(R.id.spoiler); @@ -143,6 +151,9 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply submit = replyInputLayout.findViewById(R.id.submit); // Setup reply layout views + commentQuoteButton.setOnClickListener(this); + commentSpoilerButton.setOnClickListener(this); + comment.addTextChangedListener(this); comment.setSelectionChangedListener(this); @@ -224,6 +235,10 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply // TODO }*/ else if (v == captchaHardReset) { authenticationLayout.hardReset(); + } else if (v == commentQuoteButton) { + presenter.commentQuoteClicked(); + } else if (v == commentSpoilerButton) { + presenter.commentSpoilerClicked(); } } @@ -336,6 +351,11 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply comment.setMaxLines(expanded ? 15 : 6); + preview.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + expanded ? dp(150) : dp(100) + )); + ValueAnimator animator = ValueAnimator.ofFloat(expanded ? 0f : 1f, expanded ? 1f : 0f); animator.setInterpolator(new DecelerateInterpolator(2f)); animator.setDuration(400); @@ -355,6 +375,16 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply subject.setVisibility(open ? View.VISIBLE : View.GONE); } + @Override + public void openCommentQuoteButton(boolean open) { + commentQuoteButton.setVisibility(open ? View.VISIBLE : View.GONE); + } + + @Override + public void openCommentSpoilerButton(boolean open) { + commentSpoilerButton.setVisibility(open ? View.VISIBLE : View.GONE); + } + @Override public void openFileName(boolean open) { fileName.setVisibility(open ? View.VISIBLE : View.GONE); @@ -386,7 +416,7 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Reply } if (show) { - ImageDecoder.decodeFileOnBackgroundThread(previewFile, dp(300), dp(200), this); + ImageDecoder.decodeFileOnBackgroundThread(previewFile, dp(400), dp(300), this); } else { spoiler.setVisibility(View.GONE); preview.setVisibility(View.GONE); diff --git a/Clover/app/src/main/res/layout/layout_reply_input.xml b/Clover/app/src/main/res/layout/layout_reply_input.xml index b7d76f1b..19310224 100644 --- a/Clover/app/src/main/res/layout/layout_reply_input.xml +++ b/Clover/app/src/main/res/layout/layout_reply_input.xml @@ -118,6 +118,40 @@ along with this program. If not, see . + + +