make post text selectable

we'll see how this goes, haven't found any bugs yet.
refactor-toolbar
Floens 8 years ago
parent c7087209ef
commit bfa5fcaca7
  1. 2
      Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java
  2. 3
      Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java
  3. 143
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java
  4. 10
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java
  5. 3
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java
  6. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java
  7. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java

@ -106,7 +106,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Post post = displayList.get(getPostPosition(position)); Post post = displayList.get(getPostPosition(position));
boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo ||
post.tripcode.equals(highlightedPostTripcode); 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; break;
case TYPE_STATUS: case TYPE_STATUS:
((StatusViewHolder) holder).threadStatusCell.update(); ((StatusViewHolder) holder).threadStatusCell.update();

@ -146,7 +146,8 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
} }
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, 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) { if (this.post == post) {
return; return;
} }

@ -98,7 +98,6 @@ public class PostCell extends LinearLayout implements PostCellInterface {
private View divider; private View divider;
private View filterMatchColor; private View filterMatchColor;
private boolean commentClickable = false;
private int detailsSizePx; private int detailsSizePx;
private int iconSizePx; private int iconSizePx;
private int paddingPx; private int paddingPx;
@ -109,6 +108,7 @@ public class PostCell extends LinearLayout implements PostCellInterface {
private Theme theme; private Theme theme;
private Post post; private Post post;
private PostCellCallback callback; private PostCellCallback callback;
private boolean selectable;
private boolean highlighted; private boolean highlighted;
private boolean selected; private boolean selected;
private int markedNo; private int markedNo;
@ -143,12 +143,12 @@ public class PostCell extends LinearLayout implements PostCellInterface {
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
thumbnailView = (PostImageThumbnailView) findViewById(R.id.thumbnail_view); thumbnailView = findViewById(R.id.thumbnail_view);
title = (FastTextView) findViewById(R.id.title); title = findViewById(R.id.title);
icons = (PostIcons) findViewById(R.id.icons); icons = findViewById(R.id.icons);
comment = (TextView) findViewById(R.id.comment); comment = findViewById(R.id.comment);
replies = (FastTextView) findViewById(R.id.replies); replies = findViewById(R.id.replies);
options = (ImageView) findViewById(R.id.options); options = findViewById(R.id.options);
divider = findViewById(R.id.divider); divider = findViewById(R.id.divider);
filterMatchColor = findViewById(R.id.filter_match_color); filterMatchColor = findViewById(R.id.filter_match_color);
@ -182,55 +182,44 @@ public class PostCell extends LinearLayout implements PostCellInterface {
divider.setLayoutParams(dividerParams); divider.setLayoutParams(dividerParams);
thumbnailView.setClickable(true); thumbnailView.setClickable(true);
thumbnailView.setOnClickListener(new View.OnClickListener() { thumbnailView.setOnClickListener(v -> callback.onThumbnailClicked(post, thumbnailView));
@Override
public void onClick(View v) {
callback.onThumbnailClicked(post, thumbnailView);
}
});
thumbnailView.setRounding(dp(2)); thumbnailView.setRounding(dp(2));
replies.setOnClickListener(new View.OnClickListener() { replies.setOnClickListener(v -> {
@Override if (threadMode) {
public void onClick(View v) { int repliesFromSize;
if (threadMode) { synchronized (post.repliesFrom) {
int repliesFromSize; repliesFromSize = post.repliesFrom.size();
synchronized (post.repliesFrom) { }
repliesFromSize = post.repliesFrom.size();
}
if (repliesFromSize > 0) { if (repliesFromSize > 0) {
callback.onShowPostReplies(post); callback.onShowPostReplies(post);
}
} }
} }
}); });
options.setOnClickListener(new OnClickListener() { options.setOnClickListener(v -> {
@Override if (ThemeHelper.getInstance().getTheme().isLightTheme) {
public void onClick(View v) { options.setImageResource(R.drawable.ic_overflow_black);
if (ThemeHelper.getInstance().getTheme().isLightTheme) { }
options.setImageResource(R.drawable.ic_overflow_black);
}
List<FloatingMenuItem> items = new ArrayList<>(); List<FloatingMenuItem> items = new ArrayList<>();
callback.onPopulatePostOptions(post, items); callback.onPopulatePostOptions(post, items);
FloatingMenu menu = new FloatingMenu(getContext(), v, items); FloatingMenu menu = new FloatingMenu(getContext(), v, items);
menu.setCallback(new FloatingMenu.FloatingMenuCallback() { menu.setCallback(new FloatingMenu.FloatingMenuCallback() {
@Override @Override
public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) { public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) {
callback.onPostOptionClicked(post, item.getId()); callback.onPostOptionClicked(post, item.getId());
} }
@Override @Override
public void onFloatingMenuDismissed(FloatingMenu menu) { public void onFloatingMenuDismissed(FloatingMenu menu) {
options.setImageResource(R.drawable.ic_overflow); options.setImageResource(R.drawable.ic_overflow);
} }
}); });
menu.show(); menu.show();
}
}); });
setOnClickListener(selfClicked); setOnClickListener(selfClicked);
@ -254,9 +243,21 @@ public class PostCell extends LinearLayout implements PostCellInterface {
} }
} }
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, public void setPost(Theme theme,
boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) { final Post post,
if (this.post == post && this.highlighted == highlighted && this.selected == selected && this.markedNo == markedNo && this.showDivider == showDivider) { 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; return;
} }
@ -272,6 +273,7 @@ public class PostCell extends LinearLayout implements PostCellInterface {
this.theme = theme; this.theme = theme;
this.post = post; this.post = post;
this.callback = callback; this.callback = callback;
this.selectable = selectable;
this.highlighted = highlighted; this.highlighted = highlighted;
this.selected = selected; this.selected = selected;
this.markedNo = markedNo; this.markedNo = markedNo;
@ -416,24 +418,43 @@ public class PostCell extends LinearLayout implements PostCellInterface {
commentText = post.comment; commentText = post.comment;
} }
comment.setText(commentText);
comment.setVisibility(isEmpty(commentText) && post.image == null ? GONE : VISIBLE); comment.setVisibility(isEmpty(commentText) && post.image == null ? GONE : VISIBLE);
if (commentClickable != threadMode) { if (threadMode) {
commentClickable = threadMode; if (selectable) {
if (commentClickable) { // Setting the text to selectable creates an editor, sets up a bunch of click
comment.setMovementMethod(commentMovementMethod); // handlers and sets a movementmethod.
comment.setOnClickListener(selfClicked); // Required for the isTextSelectable check.
// We override the test and movementmethod settings.
comment.setTextIsSelectable(true);
if (noClickable) { comment.setText(commentText, TextView.BufferType.SPANNABLE);
title.setMovementMethod(titleMovementMethod);
}
} else { } else {
comment.setOnClickListener(null); comment.setText(commentText);
comment.setClickable(false); }
comment.setMovementMethod(null);
title.setMovementMethod(null); // 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; int repliesFromSize;

@ -28,7 +28,15 @@ import org.floens.chan.ui.view.ThumbnailView;
import java.util.List; import java.util.List;
public interface PostCellInterface { 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(); Post getPost();

@ -139,7 +139,8 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V
} }
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, 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) { if (this.post == post) {
return; return;
} }

@ -191,7 +191,7 @@ public class PostRepliesController extends Controller {
final Post p = getItem(position); final Post p = getItem(position);
boolean showDivider = position < getCount() - 1; 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; return (View) postCell;
} }

@ -325,7 +325,7 @@ public class ThemeSettingsController extends Controller implements View.OnClickL
themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height))); themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height)));
PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null); 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)); linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
return linearLayout; return linearLayout;

Loading…
Cancel
Save