diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java index 2129cc2b..98c9fb14 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java @@ -5,7 +5,13 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; +import awais.instagrabber.customviews.DirectItemContextMenu; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmLinkBinding; import awais.instagrabber.repositories.responses.User; @@ -14,6 +20,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemLink; import awais.instagrabber.repositories.responses.directmessages.DirectItemLinkContext; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.utils.Utils; public class DirectItemLinkViewHolder extends DirectItemViewHolder { @@ -80,4 +87,16 @@ public class DirectItemLinkViewHolder extends DirectItemViewHolder { protected boolean showBackground() { return true; } + + @Override + protected List getLongClickOptions() { + return ImmutableList.of( + new DirectItemContextMenu.MenuItem(R.id.copy, R.string.copy, item -> { + final DirectItemLink link = item.getLink(); + if (link == null || TextUtils.isEmpty(link.getText())) return null; + Utils.copyText(itemView.getContext(), link.getText()); + return null; + }) + ); + } } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java index 8874e818..dddd9315 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java @@ -12,11 +12,14 @@ import androidx.recyclerview.widget.ItemTouchHelper; import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; +import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.Objects; import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; +import awais.instagrabber.customviews.DirectItemContextMenu; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmMediaShareBinding; import awais.instagrabber.models.enums.DirectItemType; @@ -30,6 +33,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemFelixS import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; +import awais.instagrabber.utils.Utils; public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { private static final String TAG = DirectItemMediaShareViewHolder.class.getSimpleName(); @@ -38,6 +42,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { private final RoundingParams incomingRoundingParams; private final RoundingParams outgoingRoundingParams; private DirectItemType itemType; + private Caption caption; public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmMediaShareBinding binding, @@ -113,7 +118,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { } private void setupCaption(@NonNull final Media media) { - final Caption caption = media.getCaption(); + caption = media.getCaption(); if (caption != null) { binding.caption.setVisibility(View.VISIBLE); binding.caption.setText(caption.getText()); @@ -177,4 +182,16 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { } return super.getSwipeDirection(); } + + @Override + protected List getLongClickOptions() { + final ImmutableList.Builder builder = ImmutableList.builder(); + if (caption != null && !TextUtils.isEmpty(caption.getText())) { + builder.add(new DirectItemContextMenu.MenuItem(R.id.copy, R.string.copy_caption, item -> { + Utils.copyText(itemView.getContext(), caption.getText()); + return null; + })); + } + return builder.build(); + } } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java index bb139332..aa1666ab 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java @@ -8,13 +8,16 @@ import androidx.constraintlayout.widget.ConstraintLayout; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; +import com.google.common.collect.ImmutableList; + +import java.util.List; import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; +import awais.instagrabber.customviews.DirectItemContextMenu; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmReelShareBinding; import awais.instagrabber.models.enums.MediaItemType; -import awais.instagrabber.repositories.responses.ImageVersions2; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; @@ -22,10 +25,12 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemReelSh import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.utils.Utils; public class DirectItemReelShareViewHolder extends DirectItemViewHolder { private final LayoutDmReelShareBinding binding; + private String type; public DirectItemReelShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmReelShareBinding binding, @@ -40,7 +45,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { @Override public void bindItem(final DirectItem item, final MessageDirection messageDirection) { final DirectItemReelShare reelShare = item.getReelShare(); - final String type = reelShare.getType(); + type = reelShare.getType(); if (type == null) return; final boolean isSelf = isSelf(item); final Media media = reelShare.getMedia(); @@ -170,4 +175,20 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { protected boolean canForward() { return false; } + + @Override + protected List getLongClickOptions() { + final ImmutableList.Builder builder = ImmutableList.builder(); + if (type != null && type.equals("reply")) { + builder.add(new DirectItemContextMenu.MenuItem(R.id.copy, R.string.copy_reply, item -> { + final DirectItemReelShare reelShare = item.getReelShare(); + if (reelShare == null) return null; + final String text = reelShare.getText(); + if (TextUtils.isEmpty(text)) return null; + Utils.copyText(itemView.getContext(), text); + return null; + })); + } + return builder.build(); + } } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java index b0eaa779..d95817ea 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java @@ -2,12 +2,20 @@ package awais.instagrabber.adapters.viewholder.directmessages; import androidx.annotation.NonNull; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; +import awais.instagrabber.customviews.DirectItemContextMenu; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmTextBinding; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectThread; +import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.utils.Utils; public class DirectItemTextViewHolder extends DirectItemViewHolder { @@ -35,4 +43,15 @@ public class DirectItemTextViewHolder extends DirectItemViewHolder { protected boolean showBackground() { return true; } + + @Override + protected List getLongClickOptions() { + return ImmutableList.of( + new DirectItemContextMenu.MenuItem(R.id.copy, R.string.copy, item -> { + if (TextUtils.isEmpty(item.getText())) return null; + Utils.copyText(itemView.getContext(), item.getText()); + return null; + }) + ); + } } diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 7319700f..8f77fc7f 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -4,4 +4,5 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 40838c81..d3b7cf2b 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -475,4 +475,6 @@ Delete unsuccessful Barinsta Crash Report Select an email app to send crash logs + Copy caption + Copy reply