[android] - make improve this map translatable

This commit is contained in:
Tobrun
2018-08-31 11:07:01 +02:00
committed by Tobrun
parent af0de6e015
commit e7642f28fe
3 changed files with 38 additions and 6 deletions

View File

@@ -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));
}
}
@@ -118,6 +122,30 @@ public class AttributionParser {
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.
*

View File

@@ -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()

View File

@@ -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());