summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-08-31 11:07:01 +0200
committerTobrun <tobrun.van.nuland@gmail.com>2018-08-31 12:12:09 +0200
commit5089490c7b608bb8a3838830bb5aafbebe589050 (patch)
tree4c8da441206de6481c257a653f23866e3b8f05dc
parent5c8ad4de473e7c040d3812aa0c345a83a51cae2b (diff)
downloadqtlocation-mapboxgl-upstream/tvn-improve-this-map.tar.gz
[android] - make improve this map translatableupstream/tvn-improve-this-map
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java28
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java10
3 files changed, 38 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
index 3e75a34b4a..ccba0f9300 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
@@ -20,6 +20,7 @@ import java.util.Set;
*/
public class AttributionParser {
+ private static final String IMPROVE_THIS_MAP = "Improve this map";
private final WeakReference<Context> context;
private final Set<Attribution> attributions = new LinkedHashSet<>();
private final String attributionData;
@@ -104,6 +105,9 @@ public class AttributionParser {
String url = urlSpan.getURL();
if (isUrlValid(url)) {
String anchor = parseAnchorValue(htmlBuilder, urlSpan);
+ if (isImproveThisMapAnchor(anchor)) {
+ anchor = translateImproveThisMapAnchor(anchor);
+ }
attributions.add(new Attribution(anchor, url));
}
}
@@ -119,6 +123,30 @@ public class AttributionParser {
}
/**
+ * Invoked to validate if an anchor is equal to Improve this map coming from tilesets.
+ *
+ * @param anchor the anchor to be validated
+ * @return if the url is valid
+ */
+ private boolean isImproveThisMapAnchor(String anchor) {
+ return anchor.equals(IMPROVE_THIS_MAP);
+ }
+
+ /**
+ * Invoked to replace the english Improve this map with localized variant.
+ *
+ * @param anchor the anchor to be translated
+ * @return the translated anchor
+ */
+ private String translateImproveThisMapAnchor(String anchor) {
+ Context context = this.context.get();
+ if (context != null) {
+ anchor = context.getString(R.string.mapbox_telemetryImproveMap);
+ }
+ return anchor;
+ }
+
+ /**
* Invoked to validate if an url is valid for the improve map configuration.
*
* @param url the url to be validated
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
index a56e964294..8510806e79 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
@@ -171,8 +171,12 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
}
List<String> attributions = new ArrayList<>();
+ String attribution;
for (Source source : mapboxMap.getSources()) {
- attributions.add(source.getAttribution());
+ attribution = source.getAttribution();
+ if (!attribution.isEmpty()) {
+ attributions.add(source.getAttribution());
+ }
}
return new AttributionParser.Options()
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
index 7eacda43c3..6838138e55 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
@@ -41,7 +41,7 @@ public class AttributionParseTest {
break;
case 2:
assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
- assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
@@ -75,7 +75,7 @@ public class AttributionParseTest {
break;
case 2:
assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
- assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
}
counter++;
@@ -102,7 +102,7 @@ public class AttributionParseTest {
break;
case 1:
assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
- assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
}
counter++;
@@ -131,7 +131,7 @@ public class AttributionParseTest {
break;
case 2:
assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
- assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
@@ -195,7 +195,7 @@ public class AttributionParseTest {
break;
case 2:
assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
- assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());