summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-11-23 16:38:32 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-11-29 13:24:28 +0100
commitd54bc6af40b2b6bca78b20c4be5c67207663e87d (patch)
tree9c7a40856e358bf135f87ed3c4c51101f94feafc
parent8789c148ddd8df25b63d0760fae326036b07f726 (diff)
downloadqtlocation-mapboxgl-d54bc6af40b2b6bca78b20c4be5c67207663e87d.tar.gz
[android] require context in AttributionParser.Builder
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java12
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java3
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java39
4 files changed, 20 insertions, 36 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 025207cc2d..16020891b1 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
@@ -241,13 +241,17 @@ public class AttributionParser {
* </p>
*/
public static class Options {
- private WeakReference<Context> context;
+ private final WeakReference<Context> context;
private boolean withImproveMap = true;
private boolean withCopyrightSign = true;
private boolean withTelemetryAttribution = false;
private boolean withMapboxAttribution = true;
private String[] attributionDataStringArray;
+ public Options(@NonNull Context context) {
+ this.context = new WeakReference<>(context);
+ }
+
@NonNull
public Options withAttributionData(String... attributionData) {
this.attributionDataStringArray = attributionData;
@@ -279,12 +283,6 @@ public class AttributionParser {
}
@NonNull
- public Options withContext(Context context) {
- this.context = new WeakReference<>(context);
- return this;
- }
-
- @NonNull
public AttributionParser build() {
if (attributionDataStringArray == null) {
throw new IllegalStateException("Using builder without providing attribution data");
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 d4d51b24da..c27dbd7517 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
@@ -187,10 +187,9 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
}
}
- return new AttributionParser.Options()
+ return new AttributionParser.Options(context)
.withCopyrightSign(true)
.withImproveMap(true)
- .withContext(context)
.withTelemetryAttribution(true)
.withAttributionData(attributions.toArray(new String[attributions.size()]))
.build().getAttributions();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 411f44f284..bc25da025d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -447,7 +447,7 @@ public class MapSnapshotter {
*/
@NonNull
private String createAttributionString(MapSnapshot mapSnapshot, boolean shortText) {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(context)
.withAttributionData(mapSnapshot.getAttributions())
.withCopyrightSign(false)
.withImproveMap(false)
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 eea522cede..ed9f4be47f 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
@@ -20,9 +20,8 @@ public class AttributionParseTest {
@Test
public void testParseAttributionStringSatellite() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(SATELLITE_ATTRIBUTION)
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -54,9 +53,8 @@ public class AttributionParseTest {
@Test
public void testParseAttributionStringStreets() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -84,10 +82,9 @@ public class AttributionParseTest {
@Test
public void testParseAttributionWithoutMapbox() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.withMapboxAttribution(false)
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -111,9 +108,8 @@ public class AttributionParseTest {
@Test
public void testParseAttributionArrayString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
@@ -144,10 +140,9 @@ public class AttributionParseTest {
@Test
public void testHideImproveThisMapAttributionArrayString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(SATELLITE_ATTRIBUTION)
.withImproveMap(false)
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 3, attributionList.size());
@@ -174,10 +169,9 @@ public class AttributionParseTest {
@Test
public void testParseHideCopyrightAttributionArrayString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
.withCopyrightSign(false)
- .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
@@ -208,11 +202,10 @@ public class AttributionParseTest {
@Test
public void testOutputWithoutCopyRightString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.withCopyrightSign(false)
.withImproveMap(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -225,10 +218,9 @@ public class AttributionParseTest {
@Test
public void testOutputWithCopyRightString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.withImproveMap(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -240,12 +232,11 @@ public class AttributionParseTest {
@Test
public void testOutputWithoutCopyRightWithoutMapboxString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.withCopyrightSign(false)
.withImproveMap(false)
.withMapboxAttribution(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -257,11 +248,10 @@ public class AttributionParseTest {
@Test
public void testOutputWithCopyRightWithoutMapboxString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.withImproveMap(false)
.withMapboxAttribution(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -273,12 +263,11 @@ public class AttributionParseTest {
@Test
public void testOutputSatelliteString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
.withImproveMap(false)
.withCopyrightSign(false)
.withMapboxAttribution(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -290,12 +279,11 @@ public class AttributionParseTest {
@Test
public void testShortOpenStreetMapString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
.withImproveMap(false)
.withCopyrightSign(false)
.withMapboxAttribution(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -307,11 +295,10 @@ public class AttributionParseTest {
@Test
public void testShortOpenStreetMapWithoutCopyrightString() throws Exception {
- AttributionParser attributionParser = new AttributionParser.Options()
+ AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
.withImproveMap(false)
.withCopyrightSign(false)
- .withContext(RuntimeEnvironment.application)
.build();
assertEquals(