diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-05-13 12:18:07 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-05-13 12:18:07 +0000 |
commit | 345392a83372ae400ca886f468e7f1745e65666b (patch) | |
tree | 7a493d3bc4a6d599030888a3f2360316148f83bf /app/src/main/java/ml | |
parent | 9a994ca5312da8269394537dc37e7ea072591a6d (diff) | |
download | infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar.gz infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar.bz2 infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar.lz infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar.xz infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.tar.zst infinity-for-reddit-345392a83372ae400ca886f468e7f1745e65666b.zip |
Copy priate messages.
Diffstat (limited to '')
2 files changed, 43 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 33add2f0..dce42d12 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -225,12 +225,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor()); mActivity.startActivity(intent); }); - - ((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> { - if (((DataViewHolder) holder).contentCustomMarkwonView.getSelectionStart() == -1 && ((DataViewHolder) holder).contentCustomMarkwonView.getSelectionEnd() == -1) { - holder.itemView.performClick(); - } - }); } } } @@ -330,6 +324,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl contentCustomMarkwonView.setTextColor(mSecondaryTextColor); contentCustomMarkwonView.setMovementMethod(LinkMovementMethod.getInstance()); + + contentCustomMarkwonView.setOnClickListener(view -> { + if (contentCustomMarkwonView.getSelectionStart() == -1 && contentCustomMarkwonView.getSelectionEnd() == -1) { + itemView.performClick(); + } + }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index eaf50978..474ec4d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -1,5 +1,8 @@ package ml.docilealligator.infinityforreddit.adapters; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; @@ -11,6 +14,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -154,7 +158,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt if (holder instanceof MessageViewHolder) { mMarkwon.setMarkdown(((MessageViewHolder) holder).messageTextView, message.getBody()); - ((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> ((MessageViewHolder) holder).itemView.performClick()); if (mShowElapsedTime) { ((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getTimeUTC())); } else { @@ -164,11 +167,12 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt ((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> { if (((MessageViewHolder) holder).timeTextView.getVisibility() != View.VISIBLE) { ((MessageViewHolder) holder).timeTextView.setVisibility(View.VISIBLE); - mViewPrivateMessagesActivity.delayTransition(); + ((MessageViewHolder) holder).copyImageView.setVisibility(View.VISIBLE); } else { ((MessageViewHolder) holder).timeTextView.setVisibility(View.GONE); - mViewPrivateMessagesActivity.delayTransition(); + ((MessageViewHolder) holder).copyImageView.setVisibility(View.GONE); } + mViewPrivateMessagesActivity.delayTransition(); }); } @@ -246,17 +250,40 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt class MessageViewHolder extends RecyclerView.ViewHolder { TextView messageTextView; TextView timeTextView; + ImageView copyImageView; public MessageViewHolder(@NonNull View itemView) { super(itemView); } - void setBaseView(TextView messageTextView, TextView timeTextView) { + void setBaseView(TextView messageTextView, TextView timeTextView, ImageView copyImageView) { this.messageTextView = messageTextView; this.timeTextView = timeTextView; + this.copyImageView = copyImageView; messageTextView.setTextColor(Color.WHITE); timeTextView.setTextColor(mSecondaryTextColor); + + copyImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + + copyImageView.setOnClickListener(view -> { + Message message; + if (getBindingAdapterPosition() == 0) { + message = mMessage; + } else { + message = mMessage.getReplies().get(getBindingAdapterPosition() - 1); + } + if (message != null) { + ClipboardManager clipboard = (ClipboardManager) mViewPrivateMessagesActivity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard != null) { + ClipData clip = ClipData.newPlainText("simple text", message.getBody()); + clipboard.setPrimaryClip(clip); + Toast.makeText(mViewPrivateMessagesActivity, R.string.copy_success, Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(mViewPrivateMessagesActivity, R.string.copy_failed, Toast.LENGTH_SHORT).show(); + } + } + }); } } @@ -265,14 +292,15 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt TextView messageTextView; @BindView(R.id.time_text_view_item_private_message_sent) TextView timeTextView; + @BindView(R.id.copy_image_view_item_private_message_sent) + ImageView copyImageView; SentMessageViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - setBaseView(messageTextView, timeTextView); + setBaseView(messageTextView, timeTextView, copyImageView); messageTextView.setTextColor(mSentMessageTextColor); - } } @@ -283,11 +311,13 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt TextView messageTextView; @BindView(R.id.time_text_view_item_private_message_received) TextView timeTextView; + @BindView(R.id.copy_image_view_item_private_message_received) + ImageView copyImageView; ReceivedMessageViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - setBaseView(messageTextView, timeTextView); + setBaseView(messageTextView, timeTextView, copyImageView); messageTextView.setTextColor(mReceivedMessageTextColor); } |