From e927e35d11b6338f94d6c71ae35c3b929ec5fe2d Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Wed, 15 Dec 2021 16:49:41 +0300 Subject: [PATCH] [android] Don't show PP copy pop-up menu if there is one copy option only If a PP info line like POI name or e-mail contain only one copy option then don't show the copy pop-up menu - copy it to clipboard immediately. PP info lines like coordinates and most social media links display a pop-up menu still (e.g. to copy a full social media url or a username only). Needed-for: #1616 Signed-off-by: Konstantin Pastbin --- .../maps/widget/placepage/PlacePageView.java | 40 ++++++++++++------- .../widget/placepage/PlacePhoneAdapter.java | 18 ++------- android/src/com/mapswithme/util/Utils.java | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 8045733fb6..0f6140f8d5 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -1402,10 +1402,7 @@ public class PlacePageView extends NestedScrollViewClickFixed public boolean onLongClick(View v) { final Object tag = v.getTag(); - final String tagStr = tag == null ? "" : tag.toString(); - final PopupMenu popup = new PopupMenu(getContext(), v); - final Menu menu = popup.getMenu(); final List items = new ArrayList<>(); switch (v.getId()) { @@ -1488,21 +1485,34 @@ public class PlacePageView extends NestedScrollViewClickFixed break; } - final String copyText = getResources().getString(android.R.string.copy); - for (int i = 0; i < items.size(); i++) - menu.add(Menu.NONE, i, i, String.format("%s %s", copyText, items.get(i))); - - popup.setOnMenuItemClickListener(item -> { - final int id = item.getItemId(); - final Context ctx = getContext(); - Utils.copyTextToClipboard(ctx, items.get(id)); + final Context ctx = getContext(); + if (items.size() == 1) + { + Utils.copyTextToClipboard(ctx, items.get(0)); Utils.showSnackbarAbove(mDetails, getRootView().findViewById(R.id.menu_frame), - ctx.getString(R.string.copied_to_clipboard, items.get(id))); - return true; - }); + ctx.getString(R.string.copied_to_clipboard, items.get(0))); + } + else + { + final PopupMenu popup = new PopupMenu(getContext(), v); + final Menu menu = popup.getMenu(); + final String copyText = getResources().getString(android.R.string.copy); + + for (int i = 0; i < items.size(); i++) + menu.add(Menu.NONE, i, i, String.format("%s %s", copyText, items.get(i))); + + popup.setOnMenuItemClickListener(item -> { + final int id = item.getItemId(); + Utils.copyTextToClipboard(ctx, items.get(id)); + Utils.showSnackbarAbove(mDetails, + getRootView().findViewById(R.id.menu_frame), + ctx.getString(R.string.copied_to_clipboard, items.get(id))); + return true; + }); + popup.show(); + } - popup.show(); return true; } diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePhoneAdapter.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePhoneAdapter.java index da2c6f1ad4..b9a6e22b5b 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePhoneAdapter.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePhoneAdapter.java @@ -96,21 +96,11 @@ public class PlacePhoneAdapter extends RecyclerView.Adapter { - final Context ctx = view.getContext(); - Utils.copyTextToClipboard(ctx, phoneNumber); - Utils.showSnackbarAbove(view, view.getRootView().findViewById(R.id.menu_frame), - ctx.getString(R.string.copied_to_clipboard, phoneNumber)); - return true; - }); - - popup.show(); + final Context ctx = view.getContext(); + Utils.copyTextToClipboard(ctx, phoneNumber); + Utils.showSnackbarAbove(view, view.getRootView().findViewById(R.id.menu_frame), + ctx.getString(R.string.copied_to_clipboard, phoneNumber)); return true; } } diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java index 3f38ee4223..88678b0d5f 100644 --- a/android/src/com/mapswithme/util/Utils.java +++ b/android/src/com/mapswithme/util/Utils.java @@ -155,7 +155,7 @@ public class Utils { final android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - final ClipData clip = ClipData.newPlainText("maps.me: " + text, text); + final ClipData clip = ClipData.newPlainText("Organic Maps: " + text, text); clipboard.setPrimaryClip(clip); }