diff --git a/geo/src/main/java/org/odk/collect/geo/selection/SelectionMapFragment.kt b/geo/src/main/java/org/odk/collect/geo/selection/SelectionMapFragment.kt index 8abf1f2413a..e3a64c1a133 100644 --- a/geo/src/main/java/org/odk/collect/geo/selection/SelectionMapFragment.kt +++ b/geo/src/main/java/org/odk/collect/geo/selection/SelectionMapFragment.kt @@ -388,7 +388,7 @@ class SelectionMapFragment( val pointIds = map.addMarkers(markerDescriptions) val lineIds = lines.fold(listOf()) { ids, item -> - ids + map.addPolyLine(LineDescription(item.points, item.strokeWidth, item.strokeColor, false, false)) + ids + map.addPolyLine(LineDescription(item.points, item.strokeWidth, item.strokeColor)) } val polygonIds = polygons.fold(listOf()) { ids, item -> ids + map.addPolygon(PolygonDescription(item.points, item.strokeWidth, item.strokeColor, item.fillColor)) diff --git a/maps/src/main/java/org/odk/collect/maps/LineDescription.kt b/maps/src/main/java/org/odk/collect/maps/LineDescription.kt index ce4351c645f..e863d3d7f51 100644 --- a/maps/src/main/java/org/odk/collect/maps/LineDescription.kt +++ b/maps/src/main/java/org/odk/collect/maps/LineDescription.kt @@ -3,11 +3,11 @@ package org.odk.collect.maps import org.odk.collect.androidshared.utils.toColorInt data class LineDescription( - val points: List, - private val strokeWidth: String?, - private val strokeColor: String?, - val draggable: Boolean, - val closed: Boolean + val points: List = emptyList(), + private val strokeWidth: String? = null, + private val strokeColor: String? = null, + val draggable: Boolean = false, + val closed: Boolean = false ) { @JvmOverloads fun getStrokeWidth(forMapbox: Boolean = false): Float { diff --git a/maps/src/main/java/org/odk/collect/maps/PolygonDescription.kt b/maps/src/main/java/org/odk/collect/maps/PolygonDescription.kt index f27e64b8184..f97442bb661 100644 --- a/maps/src/main/java/org/odk/collect/maps/PolygonDescription.kt +++ b/maps/src/main/java/org/odk/collect/maps/PolygonDescription.kt @@ -4,10 +4,10 @@ import androidx.core.graphics.ColorUtils import org.odk.collect.androidshared.utils.toColorInt data class PolygonDescription( - val points: List, - private val strokeWidth: String?, - private val strokeColor: String?, - private val fillColor: String? + val points: List = emptyList(), + private val strokeWidth: String? = null, + private val strokeColor: String? = null, + private val fillColor: String? = null ) { fun getStrokeWidth(): Float { return try { diff --git a/maps/src/test/java/org/odk/collect/maps/LineDescriptionTest.kt b/maps/src/test/java/org/odk/collect/maps/LineDescriptionTest.kt index d0050981570..cf8c5c39f0d 100644 --- a/maps/src/test/java/org/odk/collect/maps/LineDescriptionTest.kt +++ b/maps/src/test/java/org/odk/collect/maps/LineDescriptionTest.kt @@ -10,49 +10,49 @@ import org.junit.runner.RunWith class LineDescriptionTest { @Test fun `getStrokeWidth returns the default value when the passed one is null`() { - val lineDescription = LineDescription(emptyList(), null, null, false, false) + val lineDescription = LineDescription() assertThat(lineDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns the default value when the passed one is invalid`() { - val lineDescription = LineDescription(emptyList(), "blah", null, false, false) + val lineDescription = LineDescription(strokeWidth = "blah") assertThat(lineDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns the default value when the passed one is not greater than or equal to zero`() { - val lineDescription = LineDescription(emptyList(), "-1", null, false, false) + val lineDescription = LineDescription(strokeWidth = "-1") assertThat(lineDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns custom value when the passed one is a valid int number`() { - val lineDescription = LineDescription(emptyList(), "10", null, false, false) + val lineDescription = LineDescription(strokeWidth = "10") assertThat(lineDescription.getStrokeWidth(), equalTo(10f)) } @Test fun `getStrokeWidth returns custom value when the passed one is a valid float number`() { - val lineDescription = LineDescription(emptyList(), "10.5", null, false, false) + val lineDescription = LineDescription(strokeWidth = "10.5") assertThat(lineDescription.getStrokeWidth(), equalTo(10.5f)) } @Test fun `getStrokeColor returns the default color when the passed one is null`() { - val lineDescription = LineDescription(emptyList(), null, null, false, false) + val lineDescription = LineDescription() assertThat(lineDescription.getStrokeColor(), equalTo(MapConsts.DEFAULT_STROKE_COLOR)) } @Test fun `getStrokeColor returns the default color when the passed one is invalid`() { - val lineDescription = LineDescription(emptyList(), null, "blah", false, false) + val lineDescription = LineDescription(strokeColor = "blah") assertThat(lineDescription.getStrokeColor(), equalTo(MapConsts.DEFAULT_STROKE_COLOR)) } @Test fun `getStrokeColor returns custom color when it is valid`() { - val lineDescription = LineDescription(emptyList(), null, "#aaccee", false, false) + val lineDescription = LineDescription(strokeColor = "#aaccee") assertThat(lineDescription.getStrokeColor(), equalTo(-5583634)) } } diff --git a/maps/src/test/java/org/odk/collect/maps/PolygonDescriptionTest.kt b/maps/src/test/java/org/odk/collect/maps/PolygonDescriptionTest.kt index a8a0fe0b27c..d697012b98b 100644 --- a/maps/src/test/java/org/odk/collect/maps/PolygonDescriptionTest.kt +++ b/maps/src/test/java/org/odk/collect/maps/PolygonDescriptionTest.kt @@ -10,67 +10,67 @@ import org.junit.runner.RunWith class PolygonDescriptionTest { @Test fun `getStrokeWidth returns the default value when the passed one is null`() { - val polygonDescription = PolygonDescription(emptyList(), null, null, null) + val polygonDescription = PolygonDescription() assertThat(polygonDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns the default value when the passed one is invalid`() { - val polygonDescription = PolygonDescription(emptyList(), "blah", null, null) + val polygonDescription = PolygonDescription(strokeWidth = "blah") assertThat(polygonDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns the default value when the passed one is not greater than or equal to zero`() { - val polygonDescription = PolygonDescription(emptyList(), "-1", null, null) + val polygonDescription = PolygonDescription(strokeWidth = "-1") assertThat(polygonDescription.getStrokeWidth(), equalTo(MapConsts.DEFAULT_STROKE_WIDTH)) } @Test fun `getStrokeWidth returns custom value when the passed one is a valid int number`() { - val polygonDescription = PolygonDescription(emptyList(), "10", null, null) + val polygonDescription = PolygonDescription(strokeWidth = "10") assertThat(polygonDescription.getStrokeWidth(), equalTo(10f)) } @Test fun `getStrokeWidth returns custom value when the passed one is a valid float number`() { - val polygonDescription = PolygonDescription(emptyList(), "10.5", null, null) + val polygonDescription = PolygonDescription(strokeWidth = "10.5") assertThat(polygonDescription.getStrokeWidth(), equalTo(10.5f)) } @Test fun `getStrokeColor returns the default color when the passed one is null`() { - val polygonDescription = PolygonDescription(emptyList(), "0", null, null) + val polygonDescription = PolygonDescription() assertThat(polygonDescription.getStrokeColor(), equalTo(MapConsts.DEFAULT_STROKE_COLOR)) } @Test fun `getStrokeColor returns the default color when the passed one is invalid`() { - val polygonDescription = PolygonDescription(emptyList(), "0", "blah", null) + val polygonDescription = PolygonDescription(strokeColor = "blah") assertThat(polygonDescription.getStrokeColor(), equalTo(MapConsts.DEFAULT_STROKE_COLOR)) } @Test fun `getStrokeColor returns custom color when it is valid`() { - val polygonDescription = PolygonDescription(emptyList(), "0", "#aaccee", null) + val polygonDescription = PolygonDescription(strokeColor = "#aaccee") assertThat(polygonDescription.getStrokeColor(), equalTo(-5583634)) } @Test fun `getFillColor returns the default color when the passed one is null`() { - val polygonDescription = PolygonDescription(emptyList(), "0", null, null) + val polygonDescription = PolygonDescription() assertThat(polygonDescription.getFillColor(), equalTo(1157562368)) } @Test fun `getFillColor returns the default color when the passed one is invalid`() { - val polygonDescription = PolygonDescription(emptyList(), "0", null, "blah") + val polygonDescription = PolygonDescription(fillColor = "blah") assertThat(polygonDescription.getFillColor(), equalTo(1157562368)) } @Test fun `getFillColor returns custom color when it is valid`() { - val polygonDescription = PolygonDescription(emptyList(), "0", null, "#aaccee") + val polygonDescription = PolygonDescription(fillColor = "#aaccee") assertThat(polygonDescription.getFillColor(), equalTo(1152044270)) } }