mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-05 14:14:47 +01:00
Support long press for posts and comments to copy the post or comment link. (#1313)
This commit is contained in:
parent
c4efb14d7c
commit
9a1046eda2
@ -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() {
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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(),
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user