Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - make improve this map translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Sep 4, 2018
1 parent af0de6e commit e7642f2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
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;
Expand Down Expand Up @@ -104,6 +105,9 @@ private void parseUrlSpan(SpannableStringBuilder htmlBuilder, URLSpan urlSpan) {
String url = urlSpan.getURL();
if (isUrlValid(url)) {
String anchor = parseAnchorValue(htmlBuilder, urlSpan);
if (isImproveThisMapAnchor(anchor)) {
anchor = translateImproveThisMapAnchor(anchor);
}
attributions.add(new Attribution(anchor, url));
}
}
Expand All @@ -118,6 +122,30 @@ private boolean isUrlValid(String url) {
return isValidForImproveThisMap(url) && isValidForMapbox(url);
}

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ private Set<Attribution> build() {
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testParseAttributionStringSatellite() throws Exception {
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());
Expand Down Expand Up @@ -75,7 +75,7 @@ public void testParseAttributionStringStreets() throws Exception {
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++;
Expand All @@ -102,7 +102,7 @@ public void testParseAttributionWithoutMapbox() throws Exception {
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++;
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testParseAttributionArrayString() throws Exception {
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());
Expand Down Expand Up @@ -195,7 +195,7 @@ public void testParseHideCopyrightAttributionArrayString() throws Exception {
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());
Expand Down

0 comments on commit e7642f2

Please sign in to comment.