Skip to content

Commit

Permalink
Display distances on triangulation location headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Oct 11, 2023
1 parent 5346eb6 commit 88de8a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.text.buildSpannedString
import androidx.core.text.scale
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.kylecorry.andromeda.alerts.Alerts
Expand Down Expand Up @@ -174,18 +176,34 @@ class FragmentToolTriangulate : BoundFragment<FragmentToolTriangulateBinding>()
return
}

binding.triangulateTitle.subtitle.text = if (shouldCalculateMyLocation) {
null
} else {
// TODO: Display this on each location instead
getDistanceToDestination(2)?.let {
formatService.formatDistance(it, Units.getDecimalPlaces(it.units))
}
}
binding.location1Title.text = getLocationTitle(1)
binding.location2Title.text = getLocationTitle(2)

// TODO: Display distance between locations
}

private fun getLocationTitle(locationIdx: Int): CharSequence {
val distance = getDistanceToDestination(locationIdx)
val formattedDistance = distance?.let {
formatService.formatDistance(it, Units.getDecimalPlaces(it.units))
}
return buildSpannedString {
append(getString(if (locationIdx == 1) R.string.beacon_1 else R.string.beacon_2))
if (distance != null) {
appendLine()
scale(0.75f) {
append(
if (shouldCalculateMyLocation) {
getString(R.string.distance_away_from_self, formattedDistance)
} else {
getString(R.string.distance_away_from_destination, formattedDistance)
}
)
}
}
}
}

private fun updateInstructions() {
if (!isBound) {
return
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_tool_triangulate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rightButtonIcon="@drawable/ic_copy"
app:showSubtitle="false"
tools:title="10.0000, 40.0000" />

<com.kylecorry.trail_sense.navigation.paths.ui.PathView
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,10 @@
<string name="triangulate_self_location_1_instructions">Choose a known location that you can see and record the direction from where you are to that location.</string>
<string name="triangulate_self_location_2_instructions">Choose another known location that you can see and record the direction from where you are to that location.</string>
<string name="location_to_triangulate">Location to triangulate</string>
<!--The distance away from your current location. Ex. 30 m away-->
<string name="distance_away_from_self">%s away</string>
<!--The distance away from the destination. Ex. 30 m from destination-->
<string name="distance_away_from_destination">%s from destination</string>
<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down

0 comments on commit 88de8a7

Please sign in to comment.