add copy link item and change copyText
use haptic feedback instead of vibrator
This commit is contained in:
parent
b32e322749
commit
81b82c75a2
|
@ -288,11 +288,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||||
followingBtn.setOnClickListener(this::onFollowersOrFollowingClick);
|
followingBtn.setOnClickListener(this::onFollowersOrFollowingClick);
|
||||||
|
|
||||||
username.setOnLongClickListener(v->{
|
username.setOnLongClickListener(v->{
|
||||||
String username=account.acct;
|
String usernameString=account.acct;
|
||||||
if(!username.contains("@")){
|
if(!usernameString.contains("@")){
|
||||||
username+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
|
usernameString+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
|
||||||
}
|
}
|
||||||
UiUtils.copyText(getActivity(), '@'+username);
|
UiUtils.copyText(username, '@'+usernameString);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onShareLongClick(View v){
|
private boolean onShareLongClick(View v){
|
||||||
UiUtils.copyText(v.getContext(), item.status.url);
|
UiUtils.copyText(v, item.status.url);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,8 +203,10 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
|
||||||
args.putParcelable("status", Parcels.wrap(item.status));
|
args.putParcelable("status", Parcels.wrap(item.status));
|
||||||
args.putParcelable("reportAccount", Parcels.wrap(item.status.account));
|
args.putParcelable("reportAccount", Parcels.wrap(item.status.account));
|
||||||
Nav.go(item.parentFragment.getActivity(), ReportReasonChoiceFragment.class, args);
|
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);
|
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){
|
}else if(id==R.id.follow){
|
||||||
if(relationship==null)
|
if(relationship==null)
|
||||||
return true;
|
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.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.unpin).setVisible(item.status!=null && isOwnPost && item.status.pinned);
|
||||||
menu.findItem(R.id.open_in_browser).setVisible(item.status!=null);
|
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 blockDomain=menu.findItem(R.id.block_domain);
|
||||||
MenuItem mute=menu.findItem(R.id.mute);
|
MenuItem mute=menu.findItem(R.id.mute);
|
||||||
MenuItem block=menu.findItem(R.id.block);
|
MenuItem block=menu.findItem(R.id.block);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class ClickableLinksDelegate {
|
||||||
private TextView view;
|
private TextView view;
|
||||||
|
|
||||||
private final Runnable longClickRunnable = () -> {
|
private final Runnable longClickRunnable = () -> {
|
||||||
if (selectedSpan != null) selectedSpan.onLongClick(view.getContext());
|
if (selectedSpan != null) selectedSpan.onLongClick(view);
|
||||||
};
|
};
|
||||||
|
|
||||||
public ClickableLinksDelegate(TextView view) {
|
public ClickableLinksDelegate(TextView view) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.joinmastodon.android.ui.text;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
import android.text.style.CharacterStyle;
|
import android.text.style.CharacterStyle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
@ -40,8 +41,8 @@ public class LinkSpan extends CharacterStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLongClick(Context context) {
|
public void onLongClick(View view) {
|
||||||
UiUtils.copyText(context, getType() == Type.URL ? link : text);
|
UiUtils.copyText(view, getType() == Type.URL ? link : text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLink(){
|
public String getLink(){
|
||||||
|
|
|
@ -32,6 +32,7 @@ import android.provider.OpenableColumns;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -810,14 +811,13 @@ public class UiUtils{
|
||||||
launchWebBrowser(context, url);
|
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));
|
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
|
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();
|
Toast.makeText(context, R.string.text_copied, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
v.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
|
|
||||||
else vibrator.vibrate(50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSystemProperty(String key){
|
private static String getSystemProperty(String key){
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
<item android:id="@+id/follow" android:title="@string/follow_user"/>
|
<item android:id="@+id/follow" android:title="@string/follow_user"/>
|
||||||
<item android:id="@+id/report" android:title="@string/report_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/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"/>
|
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
|
||||||
</menu>
|
</menu>
|
|
@ -87,4 +87,5 @@
|
||||||
<string name="sk_reblog_with_visibility">Reblog with visibility</string>
|
<string name="sk_reblog_with_visibility">Reblog with visibility</string>
|
||||||
<string name="sk_quote_post">Post about this</string>
|
<string name="sk_quote_post">Post about this</string>
|
||||||
<string name="sk_hashtags_you_follow">Hashtags you follow</string>
|
<string name="sk_hashtags_you_follow">Hashtags you follow</string>
|
||||||
|
<string name="sk_copy_link_to_post">Copy link to post</string>
|
||||||
</resources>
|
</resources>
|
|
@ -1,2 +1,3 @@
|
||||||
- Reblog with specific visibility on long-click
|
- Reblog with specific visibility on long-click
|
||||||
- List of followed hashtags
|
- List of followed hashtags
|
||||||
|
- Long-click links to copy them
|
||||||
|
|
Loading…
Reference in New Issue