Use different messages when copying URLs, permissions and version names

This commit is contained in:
Tobias_Groza
2023-10-12 18:00:54 +02:00
parent 6bae586d80
commit defe6c3f64
4 changed files with 22 additions and 5 deletions

View File

@@ -49,6 +49,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.util.Consumer;
import androidx.core.util.Supplier;
@@ -889,12 +890,25 @@ public final class Utils {
}
/**
* Copy text to the clipboard and show a toast informing the user that the text has been copied.
* Copy text to the clipboard and show a toast informing the user that something has been copied.
* @param context the context to use
* @param label the label used in the clipboard
* @param text the text to copy
*/
public static void copyToClipboard(@NonNull Context context, @Nullable String label, @NonNull String text) {
public static void copyToClipboard(@NonNull Context context, @Nullable String label,
@NonNull String text) {
copyToClipboard(context, label, text, R.string.copied_to_clipboard);
}
/**
* Copy text to the clipboard and show a toast informing the user that the text has been copied.
* @param context the context to use
* @param label the label used in the clipboard
* @param text the text to copy
* @param message the message to show in the toast
*/
public static void copyToClipboard(@NonNull Context context, @Nullable String label,
@NonNull String text, @StringRes int message) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) {
// permission denied
@@ -905,7 +919,7 @@ public final class Utils {
if (Build.VERSION.SDK_INT < 33) {
// Starting with Android 13 (SDK 33) there is a system dialog with more clipboard actions
// shown automatically so there is no need to inform the user about the copy action.
Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
// should not happen, something went wrong internally

View File

@@ -231,7 +231,8 @@ public class AppSecurityPermissions {
@Override
public boolean onLongClick(View v) {
Utils.copyToClipboard(getContext(), String.valueOf(perm.label), perm.name);
Utils.copyToClipboard(getContext(), String.valueOf(perm.label),
perm.name, R.string.copied_permission_to_clipboard);
return true;
}

View File

@@ -1308,7 +1308,7 @@ public class AppDetailsRecyclerViewAdapter
parent.addView(view);
view.setOnClickListener(v -> onLinkClicked(url));
view.setOnLongClickListener(v -> {
Utils.copyToClipboard(context, text, url);
Utils.copyToClipboard(context, text, url, R.string.copied_url_to_clipboard);
return true;
});
}

View File

@@ -741,4 +741,6 @@ This often occurs with apps installed via Google Play or other sources, if they
<item quantity="other">Updated %1$d years ago</item>
</plurals>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="copied_url_to_clipboard">Copied URL to clipboard</string>
<string name="copied_permission_to_clipboard">Copied permission name to clipboard</string>
</resources>