diff options
author | cmp <camporter1@gmail.com> | 2023-03-11 04:38:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 04:38:43 +0000 |
commit | 9a1046eda20151d6b4df519a57cdcb7055d8e1ca (patch) | |
tree | 94763de6d791400295897b949108328b22aa7034 /app/src/main | |
parent | c4efb14d7cd1201c57f38af0c3d66e886d768d74 (diff) | |
download | infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar.gz infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar.bz2 infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar.lz infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar.xz infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.tar.zst infinity-for-reddit-9a1046eda20151d6b4df519a57cdcb7055d8e1ca.zip |
Support long press for posts and comments to copy the post or comment link. (#1313)
Diffstat (limited to '')
6 files changed, 82 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index bd94a89e..6c734576 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -6,6 +6,9 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import android.annotation.SuppressLint; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Configuration; @@ -21,6 +24,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -400,4 +404,17 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo public void unlockSwipeRightToGoBack() { } -}
\ No newline at end of file + + public void copyLink(String link) { + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard != null) { + ClipData clip = ClipData.newPlainText("simple text", link); + clipboard.setPrimaryClip(clip); + if (android.os.Build.VERSION.SDK_INT < 33) { + Toast.makeText(this, R.string.copy_success, Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(this, R.string.copy_link_failed, Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 6115195f..18e4f61b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -2578,6 +2578,19 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy shareLink(post); } }); + + shareButton.setOnLongClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return false; + } + Post post = getItem(position); + if (post != null) { + mActivity.copyLink(post.getPermalink()); + return true; + } + return false; + }); } void setBaseView(AspectRatioGifImageView iconGifImageView, @@ -3886,6 +3899,19 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } }); + shareButton.setOnLongClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return false; + } + Post post = getItem(position); + if (post != null) { + mActivity.copyLink(post.getPermalink()); + return true; + } + return false; + }); + requestListener = new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 799c13a7..7c1a8b03 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -1449,6 +1449,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler shareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), shareLinkBottomSheetFragment.getTag()); }); + mShareButton.setOnLongClickListener(view -> { + mActivity.copyLink(mPost.getPermalink()); + return true; + }); + if (mVoteButtonsOnTheRight) { ConstraintSet constraintSet = new ConstraintSet(); constraintSet.clone(mBottomConstraintLayout); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 97a0f777..08c91772 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -2691,6 +2691,19 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie shareLink(post); } }); + + shareButton.setOnLongClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return false; + } + Post post = getItem(position); + if (post != null) { + mActivity.copyLink(post.getPermalink()); + return true; + } + return false; + }); } void setBaseView(AspectRatioGifImageView iconGifImageView, @@ -4036,6 +4049,19 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + shareButton.setOnLongClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return false; + } + Post post = getItem(position); + if (post != null) { + mActivity.copyLink(post.getPermalink()); + return true; + } + return false; + }); + requestListener = new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index 4ff48bec..3ec419db 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -179,6 +179,12 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott } }); + shareTextView.setOnLongClickListener(view -> { + dismiss(); + activity.copyLink(comment.getPermalink()); + return true; + }); + copyTextView.setOnClickListener(view -> { dismiss(); CopyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java index f50e17d7..db0cb4e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java @@ -2,8 +2,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; import android.content.ActivityNotFoundException; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -136,16 +134,7 @@ public class ShareLinkBottomSheetFragment extends LandscapeExpandedRoundedBottom } private void copyLink(String link) { - ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); - if (clipboard != null) { - ClipData clip = ClipData.newPlainText("simple text", link); - clipboard.setPrimaryClip(clip); - if (android.os.Build.VERSION.SDK_INT < 33) { - Toast.makeText(activity, R.string.copy_success, Toast.LENGTH_SHORT).show(); - } - } else { - Toast.makeText(activity, R.string.copy_link_failed, Toast.LENGTH_SHORT).show(); - } + activity.copyLink(link); } @Override |