From 345392a83372ae400ca886f468e7f1745e65666b Mon Sep 17 00:00:00 2001 From: Docile-Alligator Date: Fri, 13 May 2022 20:18:07 +0800 Subject: Copy priate messages. --- .../adapters/MessageRecyclerViewAdapter.java | 12 +++--- .../PrivateMessagesDetailRecyclerViewAdapter.java | 44 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) (limited to 'app/src/main/java') 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 { - if (((DataViewHolder) holder).contentCustomMarkwonView.getSelectionStart() == -1 && ((DataViewHolder) holder).contentCustomMarkwonView.getSelectionEnd() == -1) { - holder.itemView.performClick(); - } - }); } } } @@ -330,6 +324,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { + 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); } -- cgit v1.2.3