From 96a56873c37f31d02a4282858a61fc82f5671f7d Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 21 Nov 2022 20:14:45 +0100 Subject: [PATCH] add long-click to copy username --- mastodon/src/main/AndroidManifest.xml | 1 + .../android/fragments/ProfileFragment.java | 18 ++++++++++++ .../src/main/res/layout/fragment_profile.xml | 28 +++++++++++++------ .../src/main/res/values-de-rDE/strings.xml | 1 + mastodon/src/main/res/values/strings.xml | 1 + 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/mastodon/src/main/AndroidManifest.xml b/mastodon/src/main/AndroidManifest.xml index 897069a9d..744e13420 100644 --- a/mastodon/src/main/AndroidManifest.xml +++ b/mastodon/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ + diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 5040c2f8b..c8a305f7c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -1,11 +1,16 @@ package org.joinmastodon.android.fragments; +import static android.content.Context.CLIPBOARD_SERVICE; + import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Activity; import android.app.Fragment; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Outline; @@ -14,6 +19,8 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.style.ImageSpan; @@ -34,6 +41,7 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import android.widget.Toolbar; import org.joinmastodon.android.GlobalUserPreferences; @@ -435,6 +443,16 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList // noinspection SetTextI18n username.setText('@'+account.acct+(isSelf ? ('@'+AccountSessionManager.getInstance().getAccount(accountID).domain) : "")); } + username.setOnLongClickListener(l->{ + ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); + Vibrator v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); + ClipData clip = ClipData.newPlainText("Username", '@'+account.acct+'@'+AccountSessionManager.getInstance().getAccount(accountID).domain); + clipboard.setPrimaryClip(clip); + Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) v.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); + else v.vibrate(50); + return true; + }); CharSequence parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID); if(TextUtils.isEmpty(parsedBio)){ bio.setVisibility(View.GONE); diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 8c31d928b..0efb6be06 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -205,22 +205,32 @@ android:textAlignment="viewStart" tools:text="Eugen" /> - + android:layout_marginStart="10dp" + android:layout_marginTop="0dp" + android:layout_marginBottom="-6dp" + android:layout_toStartOf="@id/profile_action_btn_wrap" > + + + Mastodon und Ihre Privatsphäre Obwohl die Mastodon-App keine Daten sammelt, kann der Server, über den Sie sich anmelden, eine andere Richtlinie haben. Nehmen Sie sich eine Minute Zeit, um die Mastodon-Datenschutzrichtlinien und die Datenschutzrichtlinien Ihres Servers zu lesen und zu akzeptieren. Ich stimme zu + In die Zwischenablage kopiert diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 2e5857519..6d3a95b8d 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -389,4 +389,5 @@ I Agree This list is empty This server does not accept new registrations. + Copied to clipboard \ No newline at end of file