From 07d6a357881a50294e356dcbceb86ae2fdad35e2 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 30 Dec 2020 15:16:05 +0500 Subject: [PATCH 1/3] Fix #10395 --- .../builders/AmenityMenuBuilder.java | 178 ++++++++++++++++-- 1 file changed, 158 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 12b1b0d497..60dd2ae2c1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -15,10 +15,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.core.content.ContextCompat; - import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -65,6 +61,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; + +import androidx.annotation.NonNull; +import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.content.ContextCompat; public class AmenityMenuBuilder extends MenuBuilder { @@ -86,18 +87,20 @@ public class AmenityMenuBuilder extends MenuBuilder { protected void buildNearestWikiRow(View view) { } - private void buildRow(View view, int iconId, String text, String textPrefix, + private void buildRow(View view, int iconId, String text, String textPrefix, String baseSocialMediaUrl, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) { - buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textPrefix, collapsable, collapsableView, textColor, + buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textPrefix, baseSocialMediaUrl, + collapsable, collapsableView, textColor, isWiki, isText, needLinks, isPhoneNumber, isUrl, matchWidthDivider, textLinesLimit); } protected void buildRow(final View view, Drawable icon, final String text, final String textPrefix, - boolean collapsable, final CollapsableView collapsableView, - int textColor, boolean isWiki, boolean isText, boolean needLinks, - boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) { + final String baseSocialMediaUrl, boolean collapsable, + final CollapsableView collapsableView, int textColor, boolean isWiki, + boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, + boolean matchWidthDivider, int textLinesLimit) { if (!isFirstRow()) { buildRowDivider(view); @@ -305,8 +308,15 @@ public class AmenityMenuBuilder extends MenuBuilder { WikipediaArticleWikiLinkFragment.showInstance(mapActivity.getSupportFragmentManager(), text); } } else { + String fullSocialMediaUrl; + if (baseSocialMediaUrl == null) { + fullSocialMediaUrl = text; + } else { + fullSocialMediaUrl = baseSocialMediaUrl + text; + } + Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(text)); + intent.setData(Uri.parse(fullSocialMediaUrl)); v.getContext().startActivity(intent); } } @@ -359,6 +369,7 @@ public class AmenityMenuBuilder extends MenuBuilder { continue; } + String baseSocialMediaUrl = null; String textPrefix = ""; CollapsableView collapsableView = null; boolean collapsable = false; @@ -392,6 +403,80 @@ public class AmenityMenuBuilder extends MenuBuilder { isUrl = true; } + if (!isUrl) { + isUrl = true; + baseSocialMediaUrl = "https://"; + + switch (key) { + case "facebook": + if (!vl.contains("facebook.com")) { + baseSocialMediaUrl = baseSocialMediaUrl + "www.facebook.com/"; + } + break; + + case "vk": + if (!vl.startsWith("vk.com")) { + baseSocialMediaUrl = baseSocialMediaUrl + "vk.com/"; + } + break; + + case "instagram": + if (!vl.contains("instagram.com")) { + baseSocialMediaUrl = baseSocialMediaUrl + "www.instagram.com/"; + } + break; + + case "twitter": + if (!vl.startsWith("twitter.com")) { + baseSocialMediaUrl = baseSocialMediaUrl + "twitter.com/"; + } + break; + + case "youtube": + // Only can process URL with domains and without HTTP, + // because account may be channel and user + if (!vl.contains("youtube.com")) { + baseSocialMediaUrl = null; + isUrl = false; + } + break; + + case "ok": + if (!vl.startsWith("ok.ru")) { + baseSocialMediaUrl = baseSocialMediaUrl + "ok.ru"; + } + break; + + case "telegram": + // Telegram can have different domens (t.me, tgme.pro,..) + String telegramUrlWithoutHttp = "[a-zA-Z0-9-]+\\.[a-zA-Z0-9-]+/[a-zA-Z0-9_]+"; + if (Pattern.matches(telegramUrlWithoutHttp, vl)) { + baseSocialMediaUrl = baseSocialMediaUrl + vl; + } else { + baseSocialMediaUrl = baseSocialMediaUrl + "t.me/"; + } + break; + + case "flickr": + if (!vl.contains("flickr.com")) { + baseSocialMediaUrl = baseSocialMediaUrl + "www.flickr.com/photos/"; + } + break; + + case "linkedin": + if (!vl.contains("linkedin.com")) { + baseSocialMediaUrl = null; + isUrl = false; + } + break; + + default: + isUrl = false; + baseSocialMediaUrl = null; + break; + } + } + if (pType != null && !pType.isText()) { String categoryName = pType.getPoiAdditionalCategory(); if (!Algorithms.isEmpty(categoryName)) { @@ -553,13 +638,13 @@ public class AmenityMenuBuilder extends MenuBuilder { vl, collapsable, collapsableView, 0, false, true, true, 0, "", false, false, matchWidthDivider, 0); } else if (icon != null) { - row = new AmenityInfoRow(key, icon, textPrefix, vl, collapsable, collapsableView, - textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, - isPhoneNumber, isUrl, matchWidthDivider, 0); + row = new AmenityInfoRow(key, icon, textPrefix, vl, baseSocialMediaUrl, collapsable, + collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, + poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0); } else { - row = new AmenityInfoRow(key, iconId, textPrefix, vl, collapsable, collapsableView, - textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, - isPhoneNumber, isUrl, matchWidthDivider, 0); + row = new AmenityInfoRow(key, iconId, textPrefix, vl, baseSocialMediaUrl, collapsable, + collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, + poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0); } if (isDescription) { descriptions.add(row); @@ -768,12 +853,14 @@ public class AmenityMenuBuilder extends MenuBuilder { public void buildAmenityRow(View view, AmenityInfoRow info) { if (info.icon != null) { - buildRow(view, info.icon, info.text, info.textPrefix, info.collapsable, info.collapsableView, - info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, + buildRow(view, info.icon, info.text, info.textPrefix, info.baseSocialMediaUrl, + info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, + info.needLinks, info.isPhoneNumber, info.isUrl, info.matchWidthDivider, info.textLinesLimit); } else { - buildRow(view, info.iconId, info.text, info.textPrefix, info.collapsable, info.collapsableView, - info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, + buildRow(view, info.iconId, info.text, info.textPrefix, info.baseSocialMediaUrl, + info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, + info.needLinks, info.isPhoneNumber, info.isUrl, info.matchWidthDivider, info.textLinesLimit); } } @@ -883,6 +970,7 @@ public class AmenityMenuBuilder extends MenuBuilder { private int iconId; private String textPrefix; private String text; + private String baseSocialMediaUrl; private CollapsableView collapsableView; private boolean collapsable; private int textColor; @@ -941,5 +1029,55 @@ public class AmenityMenuBuilder extends MenuBuilder { this.matchWidthDivider = matchWidthDivider; this.textLinesLimit = textLinesLimit; } + + public AmenityInfoRow(String key, Drawable icon, String textPrefix, String text, + String baseSocialMediaUrl, boolean collapsable, + CollapsableView collapsableView, int textColor, boolean isWiki, + boolean isText, boolean needLinks, int order, String name, + boolean isPhoneNumber, boolean isUrl, + boolean matchWidthDivider, int textLinesLimit) { + this.key = key; + this.icon = icon; + this.textPrefix = textPrefix; + this.text = text; + this.baseSocialMediaUrl = baseSocialMediaUrl; + this.collapsable = collapsable; + this.collapsableView = collapsableView; + this.textColor = textColor; + this.isWiki = isWiki; + this.isText = isText; + this.needLinks = needLinks; + this.order = order; + this.name = name; + this.isPhoneNumber = isPhoneNumber; + this.isUrl = isUrl; + this.matchWidthDivider = matchWidthDivider; + this.textLinesLimit = textLinesLimit; + } + + public AmenityInfoRow(String key, int iconId, String textPrefix, String text, + String baseSocialMediaUrl, boolean collapsable, + CollapsableView collapsableView, int textColor, boolean isWiki, + boolean isText, boolean needLinks, int order, String name, + boolean isPhoneNumber, boolean isUrl, + boolean matchWidthDivider, int textLinesLimit) { + this.key = key; + this.iconId = iconId; + this.textPrefix = textPrefix; + this.text = text; + this.baseSocialMediaUrl = baseSocialMediaUrl; + this.collapsable = collapsable; + this.collapsableView = collapsableView; + this.textColor = textColor; + this.isWiki = isWiki; + this.isText = isText; + this.needLinks = needLinks; + this.order = order; + this.name = name; + this.isPhoneNumber = isPhoneNumber; + this.isUrl = isUrl; + this.matchWidthDivider = matchWidthDivider; + this.textLinesLimit = textLinesLimit; + } } } From 6415db6230cb1f8bf8aba02d98be2477b01cc145 Mon Sep 17 00:00:00 2001 From: cepprice Date: Sat, 2 Jan 2021 01:01:39 +0500 Subject: [PATCH 2/3] Refactor to simplify code --- .../builders/AmenityMenuBuilder.java | 230 ++++++------------ 1 file changed, 78 insertions(+), 152 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 60dd2ae2c1..25976b644f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -87,17 +87,17 @@ public class AmenityMenuBuilder extends MenuBuilder { protected void buildNearestWikiRow(View view) { } - private void buildRow(View view, int iconId, String text, String textPrefix, String baseSocialMediaUrl, + private void buildRow(View view, int iconId, String text, String textPrefix, String socialMediaUrl, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) { - buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textPrefix, baseSocialMediaUrl, + buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textPrefix, socialMediaUrl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, isPhoneNumber, isUrl, matchWidthDivider, textLinesLimit); } protected void buildRow(final View view, Drawable icon, final String text, final String textPrefix, - final String baseSocialMediaUrl, boolean collapsable, + final String socialMediaUrl, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) { @@ -308,15 +308,9 @@ public class AmenityMenuBuilder extends MenuBuilder { WikipediaArticleWikiLinkFragment.showInstance(mapActivity.getSupportFragmentManager(), text); } } else { - String fullSocialMediaUrl; - if (baseSocialMediaUrl == null) { - fullSocialMediaUrl = text; - } else { - fullSocialMediaUrl = baseSocialMediaUrl + text; - } - + String uri = socialMediaUrl == null ? text : socialMediaUrl; Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(fullSocialMediaUrl)); + intent.setData(Uri.parse(uri)); v.getContext().startActivity(intent); } } @@ -369,7 +363,7 @@ public class AmenityMenuBuilder extends MenuBuilder { continue; } - String baseSocialMediaUrl = null; + String socialMediaUrl = null; String textPrefix = ""; CollapsableView collapsableView = null; boolean collapsable = false; @@ -401,79 +395,10 @@ public class AmenityMenuBuilder extends MenuBuilder { if (vl.startsWith("http://") || vl.startsWith("https://") || vl.startsWith("HTTP://") || vl.startsWith("HTTPS://")) { isUrl = true; - } - - if (!isUrl) { - isUrl = true; - baseSocialMediaUrl = "https://"; - - switch (key) { - case "facebook": - if (!vl.contains("facebook.com")) { - baseSocialMediaUrl = baseSocialMediaUrl + "www.facebook.com/"; - } - break; - - case "vk": - if (!vl.startsWith("vk.com")) { - baseSocialMediaUrl = baseSocialMediaUrl + "vk.com/"; - } - break; - - case "instagram": - if (!vl.contains("instagram.com")) { - baseSocialMediaUrl = baseSocialMediaUrl + "www.instagram.com/"; - } - break; - - case "twitter": - if (!vl.startsWith("twitter.com")) { - baseSocialMediaUrl = baseSocialMediaUrl + "twitter.com/"; - } - break; - - case "youtube": - // Only can process URL with domains and without HTTP, - // because account may be channel and user - if (!vl.contains("youtube.com")) { - baseSocialMediaUrl = null; - isUrl = false; - } - break; - - case "ok": - if (!vl.startsWith("ok.ru")) { - baseSocialMediaUrl = baseSocialMediaUrl + "ok.ru"; - } - break; - - case "telegram": - // Telegram can have different domens (t.me, tgme.pro,..) - String telegramUrlWithoutHttp = "[a-zA-Z0-9-]+\\.[a-zA-Z0-9-]+/[a-zA-Z0-9_]+"; - if (Pattern.matches(telegramUrlWithoutHttp, vl)) { - baseSocialMediaUrl = baseSocialMediaUrl + vl; - } else { - baseSocialMediaUrl = baseSocialMediaUrl + "t.me/"; - } - break; - - case "flickr": - if (!vl.contains("flickr.com")) { - baseSocialMediaUrl = baseSocialMediaUrl + "www.flickr.com/photos/"; - } - break; - - case "linkedin": - if (!vl.contains("linkedin.com")) { - baseSocialMediaUrl = null; - isUrl = false; - } - break; - - default: - isUrl = false; - baseSocialMediaUrl = null; - break; + } else { + socialMediaUrl = getSocialMediaUrl(key, vl); + if (socialMediaUrl != null) { + isUrl = true; } } @@ -635,14 +560,14 @@ public class AmenityMenuBuilder extends MenuBuilder { AmenityInfoRow row; if (isDescription) { row = new AmenityInfoRow(key, R.drawable.ic_action_note_dark, textPrefix, - vl, collapsable, collapsableView, 0, false, true, - true, 0, "", false, false, matchWidthDivider, 0); + vl, null, collapsable, collapsableView, 0, false, + true, true, 0, "", false, false, matchWidthDivider, 0); } else if (icon != null) { - row = new AmenityInfoRow(key, icon, textPrefix, vl, baseSocialMediaUrl, collapsable, + row = new AmenityInfoRow(key, icon, textPrefix, vl, socialMediaUrl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0); } else { - row = new AmenityInfoRow(key, iconId, textPrefix, vl, baseSocialMediaUrl, collapsable, + row = new AmenityInfoRow(key, iconId, textPrefix, vl, socialMediaUrl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0); } @@ -691,8 +616,11 @@ public class AmenityMenuBuilder extends MenuBuilder { } boolean cuisineOrDish = categoryName.equals(Amenity.CUISINE) || categoryName.equals(Amenity.DISH); CollapsableView collapsableView = getPoiTypeCollapsableView(view.getContext(), true, categoryTypes, true, cuisineOrDish ? cuisineRow : null); - infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, pType.getPoiAdditionalCategoryTranslation(), sb.toString(), true, collapsableView, - 0, false, false, false, pType.getOrder(), pType.getKeyName(), false, false, false, 1)); + infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, + pType.getPoiAdditionalCategoryTranslation(), sb.toString(), null, + true, collapsableView, 0, false, false, + false, pType.getOrder(), pType.getKeyName(), false, + false, false, 1)); } } @@ -707,8 +635,10 @@ public class AmenityMenuBuilder extends MenuBuilder { } sb.append(pt.getTranslation()); } - infoRows.add(new AmenityInfoRow(poiCategory.getKeyName(), icon, poiCategory.getTranslation(), sb.toString(), true, collapsableView, - 0, false, false, false, 40, poiCategory.getKeyName(), false, false, false, 1)); + infoRows.add(new AmenityInfoRow(poiCategory.getKeyName(), icon, + poiCategory.getTranslation(), sb.toString(), null, true, + collapsableView, 0, false, false, false, 40, + poiCategory.getKeyName(), false, false, false, 1)); } Collections.sort(infoRows, new Comparator() { @@ -748,9 +678,11 @@ public class AmenityMenuBuilder extends MenuBuilder { if (processNearestWiki() && nearestWiki.size() > 0) { AmenityInfoRow wikiInfo = new AmenityInfoRow( - "nearest_wiki", R.drawable.ic_plugin_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, - getCollapsableWikiView(view.getContext(), true), - 0, false, false, false, 1000, null, false, false, false, 0); + "nearest_wiki", R.drawable.ic_plugin_wikipedia, null, + app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", null, + true, getCollapsableWikiView(view.getContext(), true), + 0, false, false, false, 1000, null, false, + false, false, 0); buildAmenityRow(view, wikiInfo); } @@ -853,12 +785,12 @@ public class AmenityMenuBuilder extends MenuBuilder { public void buildAmenityRow(View view, AmenityInfoRow info) { if (info.icon != null) { - buildRow(view, info.icon, info.text, info.textPrefix, info.baseSocialMediaUrl, + buildRow(view, info.icon, info.text, info.textPrefix, info.socialMediaUrl, info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, info.isUrl, info.matchWidthDivider, info.textLinesLimit); } else { - buildRow(view, info.iconId, info.text, info.textPrefix, info.baseSocialMediaUrl, + buildRow(view, info.iconId, info.text, info.textPrefix, info.socialMediaUrl, info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, info.isUrl, info.matchWidthDivider, info.textLinesLimit); @@ -964,13 +896,53 @@ public class AmenityMenuBuilder extends MenuBuilder { return new CollapsableView(view, this, collapsed); } + private String getSocialMediaUrl(String key, String value) { + // Regex for url without protocol, with at least 2 valid domains, slash and at least one + // char after it (e.g. a-c.com/a) + String urlMask = "[a-zA-Z0-9]+[-]*[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+[-]*[a-zA-Z0-9]+)+\\/.+"; + + if (Pattern.matches(urlMask, value)) { + return "https://" + value; + } + + // Remove leading and closing slashes + StringBuilder sb = new StringBuilder(value.trim()); + if (sb.charAt(0) == '/') { + sb.deleteCharAt(0); + } + int lastIdx = sb.length() - 1; + if (sb.charAt(lastIdx) == '/') { + sb.deleteCharAt(lastIdx); + } + + // It cannot be username + if (sb.indexOf("/") != -1 || sb.indexOf(" ") != -1) { + return null; + } + + Map urls = new HashMap<>(7); + urls.put("facebook", "https://facebook.com/%s"); + urls.put("vk", "https://vk.com/%s"); + urls.put("instagram", "https://instagram.com/%s"); + urls.put("twitter", "https://twitter.com/%s"); + urls.put("ok", "https://ok.ru/%s"); + urls.put("telegram", "https://t.me/%s"); + urls.put("flickr", "https://flickr.com/%s"); + + if (urls.containsKey(key)) { + return String.format(urls.get(key), value); + } else { + return null; + } + } + private static class AmenityInfoRow { private String key; private Drawable icon; private int iconId; private String textPrefix; private String text; - private String baseSocialMediaUrl; + private String socialMediaUrl; private CollapsableView collapsableView; private boolean collapsable; private int textColor; @@ -985,14 +957,16 @@ public class AmenityMenuBuilder extends MenuBuilder { private int textLinesLimit; public AmenityInfoRow(String key, Drawable icon, String textPrefix, String text, - boolean collapsable, CollapsableView collapsableView, - int textColor, boolean isWiki, boolean isText, boolean needLinks, - int order, String name, boolean isPhoneNumber, boolean isUrl, + String socialMediaUrl, boolean collapsable, + CollapsableView collapsableView, int textColor, boolean isWiki, + boolean isText, boolean needLinks, int order, String name, + boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) { this.key = key; this.icon = icon; this.textPrefix = textPrefix; this.text = text; + this.socialMediaUrl = socialMediaUrl; this.collapsable = collapsable; this.collapsableView = collapsableView; this.textColor = textColor; @@ -1008,55 +982,7 @@ public class AmenityMenuBuilder extends MenuBuilder { } public AmenityInfoRow(String key, int iconId, String textPrefix, String text, - boolean collapsable, CollapsableView collapsableView, - int textColor, boolean isWiki, boolean isText, boolean needLinks, - int order, String name, boolean isPhoneNumber, boolean isUrl, - boolean matchWidthDivider, int textLinesLimit) { - this.key = key; - this.iconId = iconId; - this.textPrefix = textPrefix; - this.text = text; - this.collapsable = collapsable; - this.collapsableView = collapsableView; - this.textColor = textColor; - this.isWiki = isWiki; - this.isText = isText; - this.needLinks = needLinks; - this.order = order; - this.name = name; - this.isPhoneNumber = isPhoneNumber; - this.isUrl = isUrl; - this.matchWidthDivider = matchWidthDivider; - this.textLinesLimit = textLinesLimit; - } - - public AmenityInfoRow(String key, Drawable icon, String textPrefix, String text, - String baseSocialMediaUrl, boolean collapsable, - CollapsableView collapsableView, int textColor, boolean isWiki, - boolean isText, boolean needLinks, int order, String name, - boolean isPhoneNumber, boolean isUrl, - boolean matchWidthDivider, int textLinesLimit) { - this.key = key; - this.icon = icon; - this.textPrefix = textPrefix; - this.text = text; - this.baseSocialMediaUrl = baseSocialMediaUrl; - this.collapsable = collapsable; - this.collapsableView = collapsableView; - this.textColor = textColor; - this.isWiki = isWiki; - this.isText = isText; - this.needLinks = needLinks; - this.order = order; - this.name = name; - this.isPhoneNumber = isPhoneNumber; - this.isUrl = isUrl; - this.matchWidthDivider = matchWidthDivider; - this.textLinesLimit = textLinesLimit; - } - - public AmenityInfoRow(String key, int iconId, String textPrefix, String text, - String baseSocialMediaUrl, boolean collapsable, + String socialMediaUrl, boolean collapsable, CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, int order, String name, boolean isPhoneNumber, boolean isUrl, @@ -1065,7 +991,7 @@ public class AmenityMenuBuilder extends MenuBuilder { this.iconId = iconId; this.textPrefix = textPrefix; this.text = text; - this.baseSocialMediaUrl = baseSocialMediaUrl; + this.socialMediaUrl = socialMediaUrl; this.collapsable = collapsable; this.collapsableView = collapsableView; this.textColor = textColor; From ef39c2f79b8044ad9e7ba7a8cb2648c9f0bb3b00 Mon Sep 17 00:00:00 2001 From: cepprice Date: Mon, 4 Jan 2021 02:36:07 +0500 Subject: [PATCH 3/3] =?UTF-8?q?Remove=20ex=D1=81essive=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapcontextmenu/builders/AmenityMenuBuilder.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 25976b644f..0a6ebe16d9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -61,7 +61,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import androidx.annotation.NonNull; import androidx.appcompat.view.ContextThemeWrapper; @@ -897,14 +896,6 @@ public class AmenityMenuBuilder extends MenuBuilder { } private String getSocialMediaUrl(String key, String value) { - // Regex for url without protocol, with at least 2 valid domains, slash and at least one - // char after it (e.g. a-c.com/a) - String urlMask = "[a-zA-Z0-9]+[-]*[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+[-]*[a-zA-Z0-9]+)+\\/.+"; - - if (Pattern.matches(urlMask, value)) { - return "https://" + value; - } - // Remove leading and closing slashes StringBuilder sb = new StringBuilder(value.trim()); if (sb.charAt(0) == '/') { @@ -916,8 +907,8 @@ public class AmenityMenuBuilder extends MenuBuilder { } // It cannot be username - if (sb.indexOf("/") != -1 || sb.indexOf(" ") != -1) { - return null; + if (sb.indexOf("/") != -1) { + return "https://" + value; } Map urls = new HashMap<>(7);