Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gino-m committed Oct 2, 2023
1 parent b0e106b commit ee4f070
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ constructor(
// TODO: Move to strings.xml for i18n
val df = DecimalFormat("#.##")
df.roundingMode = RoundingMode.DOWN
return "${LatLngConverter.processCoordinates(geometry.coordinates)}\n" +
"Altitude: ${df.format(altitude)}m\n" +
"Accuracy: ${df.format(accuracy)}m"
val coordinatesString = LatLngConverter.formatCoordinates(geometry.coordinates)
val altitudeString = altitude?.let { df.format(it) } ?: "?"
val accuracyString = accuracy?.let { df.format(it) } ?: "?"
return "$coordinatesString\nAltitude: $altitudeString m\nAccuracy: $accuracyString m"
}

override fun isEmpty(): Boolean = geometry == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ abstract class AbstractMapFragmentWithControls : AbstractMapContainerFragment()
return
}
val target = position.target
val processedCoordinates = LatLngConverter.processCoordinates(target)
val processedCoordinates = LatLngConverter.formatCoordinates(target)
setCurrentLocationAsInfoCard(processedCoordinates)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.math.abs
object LatLngConverter {

/** Converts the given coordinates in decimal format to D°M′S″ format. */
fun processCoordinates(coordinates: Coordinates?): String? =
fun formatCoordinates(coordinates: Coordinates?): String? =
coordinates?.let { "${convertLatToDMS(it.lat)} ${convertLongToDMS(it.lng)}" }

private fun convertLatToDMS(lat: Double): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.android.ground.ui.datacollection.tasks.point

import com.google.android.ground.model.geometry.Coordinates
import com.google.android.ground.ui.datacollection.tasks.point.LatLngConverter.processCoordinates
import com.google.android.ground.ui.datacollection.tasks.point.LatLngConverter.formatCoordinates
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -28,23 +28,23 @@ class LatLngConverterTest {

@Test
fun testProcessCoordinates_ne() {
assertThat(processCoordinates(Coordinates(10.555, 10.555)))
assertThat(formatCoordinates(Coordinates(10.555, 10.555)))
.isEqualTo("10°33'18\" N 10°33'18\" E")
}

@Test
fun testProcessCoordinates_se() {
assertThat(processCoordinates(Coordinates(-10.555, 10.555)))
assertThat(formatCoordinates(Coordinates(-10.555, 10.555)))
.isEqualTo("10°33'18\" S 10°33'18\" E")
}
@Test
fun testProcessCoordinates_nw() {
assertThat(processCoordinates(Coordinates(10.555, -10.555)))
assertThat(formatCoordinates(Coordinates(10.555, -10.555)))
.isEqualTo("10°33'18\" N 10°33'18\" W")
}
@Test
fun testProcessCoordinates_sw() {
assertThat(processCoordinates(Coordinates(-10.555, -10.555)))
assertThat(formatCoordinates(Coordinates(-10.555, -10.555)))
.isEqualTo("10°33'18\" S 10°33'18\" W")
}
}

0 comments on commit ee4f070

Please sign in to comment.