add copy link item and change copyText

use haptic feedback instead of vibrator
This commit is contained in:
sk 2022-12-23 18:08:56 +01:00
parent b32e322749
commit 81b82c75a2
9 changed files with 20 additions and 13 deletions

View File

@ -288,11 +288,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
followingBtn.setOnClickListener(this::onFollowersOrFollowingClick);
username.setOnLongClickListener(v->{
String username=account.acct;
if(!username.contains("@")){
username+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
String usernameString=account.acct;
if(!usernameString.contains("@")){
usernameString+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
}
UiUtils.copyText(getActivity(), '@'+username);
UiUtils.copyText(username, '@'+usernameString);
return true;
});

View File

@ -263,7 +263,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
}
private boolean onShareLongClick(View v){
UiUtils.copyText(v.getContext(), item.status.url);
UiUtils.copyText(v, item.status.url);
return true;
}

View File

@ -203,8 +203,10 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
args.putParcelable("status", Parcels.wrap(item.status));
args.putParcelable("reportAccount", Parcels.wrap(item.status.account));
Nav.go(item.parentFragment.getActivity(), ReportReasonChoiceFragment.class, args);
}else if(id==R.id.open_in_browser){
}else if(id==R.id.open_in_browser) {
UiUtils.launchWebBrowser(activity, item.status.url);
}else if(id==R.id.copy_link){
UiUtils.copyText(parent, item.status.url);
}else if(id==R.id.follow){
if(relationship==null)
return true;
@ -320,6 +322,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
menu.findItem(R.id.pin).setVisible(item.status!=null && isOwnPost && !item.status.pinned);
menu.findItem(R.id.unpin).setVisible(item.status!=null && isOwnPost && item.status.pinned);
menu.findItem(R.id.open_in_browser).setVisible(item.status!=null);
menu.findItem(R.id.copy_link).setVisible(item.status!=null);
MenuItem blockDomain=menu.findItem(R.id.block_domain);
MenuItem mute=menu.findItem(R.id.mute);
MenuItem block=menu.findItem(R.id.block);

View File

@ -24,7 +24,7 @@ public class ClickableLinksDelegate {
private TextView view;
private final Runnable longClickRunnable = () -> {
if (selectedSpan != null) selectedSpan.onLongClick(view.getContext());
if (selectedSpan != null) selectedSpan.onLongClick(view);
};
public ClickableLinksDelegate(TextView view) {

View File

@ -3,6 +3,7 @@ package org.joinmastodon.android.ui.text;
import android.content.Context;
import android.text.TextPaint;
import android.text.style.CharacterStyle;
import android.view.View;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -40,8 +41,8 @@ public class LinkSpan extends CharacterStyle {
}
}
public void onLongClick(Context context) {
UiUtils.copyText(context, getType() == Type.URL ? link : text);
public void onLongClick(View view) {
UiUtils.copyText(view, getType() == Type.URL ? link : text);
}
public String getLink(){

View File

@ -32,6 +32,7 @@ import android.provider.OpenableColumns;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -810,14 +811,13 @@ public class UiUtils{
launchWebBrowser(context, url);
}
public static void copyText(Context context, String text) {
public static void copyText(View v, String text) {
Context context = v.getContext();
context.getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText(null, text));
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.TIRAMISU || UiUtils.isMIUI()){ // Android 13+ SystemUI shows its own thing when you put things into the clipboard
Toast.makeText(context, R.string.text_copied, Toast.LENGTH_SHORT).show();
}
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
else vibrator.vibrate(50);
v.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
}
private static String getSystemProperty(String key){

View File

@ -11,5 +11,6 @@
<item android:id="@+id/follow" android:title="@string/follow_user"/>
<item android:id="@+id/report" android:title="@string/report_user"/>
<item android:id="@+id/bookmark" android:title="@string/add_bookmark"/>
<item android:id="@+id/copy_link" android:title="@string/sk_copy_link_to_post"/>
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
</menu>

View File

@ -87,4 +87,5 @@
<string name="sk_reblog_with_visibility">Reblog with visibility</string>
<string name="sk_quote_post">Post about this</string>
<string name="sk_hashtags_you_follow">Hashtags you follow</string>
<string name="sk_copy_link_to_post">Copy link to post</string>
</resources>

View File

@ -1,2 +1,3 @@
- Reblog with specific visibility on long-click
- List of followed hashtags
- Long-click links to copy them