From bfa5fcaca7994e4eeb10819869c9b8708effb788 Mon Sep 17 00:00:00 2001 From: Floens Date: Sun, 31 Dec 2017 01:12:09 +0100 Subject: [PATCH] make post text selectable we'll see how this goes, haven't found any bugs yet. --- .../floens/chan/ui/adapter/PostAdapter.java | 2 +- .../org/floens/chan/ui/cell/CardPostCell.java | 3 +- .../org/floens/chan/ui/cell/PostCell.java | 143 ++++++++++-------- .../chan/ui/cell/PostCellInterface.java | 10 +- .../org/floens/chan/ui/cell/PostStubCell.java | 3 +- .../ui/controller/PostRepliesController.java | 2 +- .../controller/ThemeSettingsController.java | 2 +- 7 files changed, 98 insertions(+), 67 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java b/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java index dbfda9b1..20d7459a 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java @@ -106,7 +106,7 @@ public class PostAdapter extends RecyclerView.Adapter { Post post = displayList.get(getPostPosition(position)); boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || post.tripcode.equals(highlightedPostTripcode); - postViewHolder.postView.setPost(null, post, postCellCallback, highlight, post.no == selectedPost, -1, true, postViewMode); + postViewHolder.postView.setPost(null, post, postCellCallback, true, highlight, post.no == selectedPost, -1, true, postViewMode); break; case TYPE_STATUS: ((StatusViewHolder) holder).threadStatusCell.update(); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java index d6d7b5d7..8d2ddebd 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java @@ -146,7 +146,8 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On } public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) { + boolean selectable, boolean highlighted, boolean selected, int markedNo, + boolean showDivider, ChanSettings.PostViewMode postViewMode) { if (this.post == post) { return; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java index 9a98288d..65bf0149 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java @@ -98,7 +98,6 @@ public class PostCell extends LinearLayout implements PostCellInterface { private View divider; private View filterMatchColor; - private boolean commentClickable = false; private int detailsSizePx; private int iconSizePx; private int paddingPx; @@ -109,6 +108,7 @@ public class PostCell extends LinearLayout implements PostCellInterface { private Theme theme; private Post post; private PostCellCallback callback; + private boolean selectable; private boolean highlighted; private boolean selected; private int markedNo; @@ -143,12 +143,12 @@ public class PostCell extends LinearLayout implements PostCellInterface { protected void onFinishInflate() { super.onFinishInflate(); - thumbnailView = (PostImageThumbnailView) findViewById(R.id.thumbnail_view); - title = (FastTextView) findViewById(R.id.title); - icons = (PostIcons) findViewById(R.id.icons); - comment = (TextView) findViewById(R.id.comment); - replies = (FastTextView) findViewById(R.id.replies); - options = (ImageView) findViewById(R.id.options); + thumbnailView = findViewById(R.id.thumbnail_view); + title = findViewById(R.id.title); + icons = findViewById(R.id.icons); + comment = findViewById(R.id.comment); + replies = findViewById(R.id.replies); + options = findViewById(R.id.options); divider = findViewById(R.id.divider); filterMatchColor = findViewById(R.id.filter_match_color); @@ -182,55 +182,44 @@ public class PostCell extends LinearLayout implements PostCellInterface { divider.setLayoutParams(dividerParams); thumbnailView.setClickable(true); - thumbnailView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - callback.onThumbnailClicked(post, thumbnailView); - } - }); + thumbnailView.setOnClickListener(v -> callback.onThumbnailClicked(post, thumbnailView)); thumbnailView.setRounding(dp(2)); - replies.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (threadMode) { - int repliesFromSize; - synchronized (post.repliesFrom) { - repliesFromSize = post.repliesFrom.size(); - } + replies.setOnClickListener(v -> { + if (threadMode) { + int repliesFromSize; + synchronized (post.repliesFrom) { + repliesFromSize = post.repliesFrom.size(); + } - if (repliesFromSize > 0) { - callback.onShowPostReplies(post); - } + if (repliesFromSize > 0) { + callback.onShowPostReplies(post); } } }); - options.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (ThemeHelper.getInstance().getTheme().isLightTheme) { - options.setImageResource(R.drawable.ic_overflow_black); - } + options.setOnClickListener(v -> { + if (ThemeHelper.getInstance().getTheme().isLightTheme) { + options.setImageResource(R.drawable.ic_overflow_black); + } - List items = new ArrayList<>(); + List items = new ArrayList<>(); - callback.onPopulatePostOptions(post, items); + callback.onPopulatePostOptions(post, items); - FloatingMenu menu = new FloatingMenu(getContext(), v, items); - menu.setCallback(new FloatingMenu.FloatingMenuCallback() { - @Override - public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) { - callback.onPostOptionClicked(post, item.getId()); - } + FloatingMenu menu = new FloatingMenu(getContext(), v, items); + menu.setCallback(new FloatingMenu.FloatingMenuCallback() { + @Override + public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) { + callback.onPostOptionClicked(post, item.getId()); + } - @Override - public void onFloatingMenuDismissed(FloatingMenu menu) { - options.setImageResource(R.drawable.ic_overflow); - } - }); - menu.show(); - } + @Override + public void onFloatingMenuDismissed(FloatingMenu menu) { + options.setImageResource(R.drawable.ic_overflow); + } + }); + menu.show(); }); setOnClickListener(selfClicked); @@ -254,9 +243,21 @@ public class PostCell extends LinearLayout implements PostCellInterface { } } - public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) { - if (this.post == post && this.highlighted == highlighted && this.selected == selected && this.markedNo == markedNo && this.showDivider == showDivider) { + public void setPost(Theme theme, + final Post post, + PostCellInterface.PostCellCallback callback, + boolean selectable, + boolean highlighted, + boolean selected, + int markedNo, + boolean showDivider, + ChanSettings.PostViewMode postViewMode) { + if (this.post == post && + this.selectable == selectable && + this.highlighted == highlighted && + this.selected == selected && + this.markedNo == markedNo && + this.showDivider == showDivider) { return; } @@ -272,6 +273,7 @@ public class PostCell extends LinearLayout implements PostCellInterface { this.theme = theme; this.post = post; this.callback = callback; + this.selectable = selectable; this.highlighted = highlighted; this.selected = selected; this.markedNo = markedNo; @@ -416,24 +418,43 @@ public class PostCell extends LinearLayout implements PostCellInterface { commentText = post.comment; } - comment.setText(commentText); comment.setVisibility(isEmpty(commentText) && post.image == null ? GONE : VISIBLE); - if (commentClickable != threadMode) { - commentClickable = threadMode; - if (commentClickable) { - comment.setMovementMethod(commentMovementMethod); - comment.setOnClickListener(selfClicked); + if (threadMode) { + if (selectable) { + // Setting the text to selectable creates an editor, sets up a bunch of click + // handlers and sets a movementmethod. + // Required for the isTextSelectable check. + // We override the test and movementmethod settings. + comment.setTextIsSelectable(true); - if (noClickable) { - title.setMovementMethod(titleMovementMethod); - } + comment.setText(commentText, TextView.BufferType.SPANNABLE); } else { - comment.setOnClickListener(null); - comment.setClickable(false); - comment.setMovementMethod(null); - title.setMovementMethod(null); + comment.setText(commentText); + } + + // Sets focusable to auto, clickable and longclickable to true. + comment.setMovementMethod(commentMovementMethod); + + // And this sets clickable to appropriate values again. + comment.setOnClickListener(selfClicked); + + if (noClickable) { + title.setMovementMethod(titleMovementMethod); } + } else { +// comment.setTextIsSelectable(false); + + comment.setText(commentText); + + comment.setOnClickListener(null); + + comment.setClickable(false); + + // Sets focusable to auto, clickable and longclickable to false. + comment.setMovementMethod(null); + + title.setMovementMethod(null); } int repliesFromSize; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java index 6f2c291a..f073b9fe 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java @@ -28,7 +28,15 @@ import org.floens.chan.ui.view.ThumbnailView; import java.util.List; public interface PostCellInterface { - void setPost(Theme theme, Post post, PostCellCallback callback, boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode); + void setPost(Theme theme, + Post post, + PostCellCallback callback, + boolean selectable, + boolean highlighted, + boolean selected, + int markedNo, + boolean showDivider, + ChanSettings.PostViewMode postViewMode); Post getPost(); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java index 2b3e6ba5..12de32d8 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java @@ -139,7 +139,8 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V } public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) { + boolean selectable, boolean highlighted, boolean selected, int markedNo, + boolean showDivider, ChanSettings.PostViewMode postViewMode) { if (this.post == post) { return; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java index d0e39c9a..dcc8495e 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java @@ -191,7 +191,7 @@ public class PostRepliesController extends Controller { final Post p = getItem(position); boolean showDivider = position < getCount() - 1; - postCell.setPost(null, p, presenter, false, false, data.forPost.no, showDivider, ChanSettings.PostViewMode.LIST); + postCell.setPost(null, p, presenter, false, false, false, data.forPost.no, showDivider, ChanSettings.PostViewMode.LIST); return (View) postCell; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java index 8d30ca8e..20e6ce41 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java @@ -325,7 +325,7 @@ public class ThemeSettingsController extends Controller implements View.OnClickL themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height))); PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null); - postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, false, -1, true, ChanSettings.PostViewMode.LIST); + postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, false, false, -1, true, ChanSettings.PostViewMode.LIST); linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); return linearLayout;