Skip to content

Commit

Permalink
Add map layer preview during calibration
Browse files Browse the repository at this point in the history
Closes #1780
  • Loading branch information
kylecorry31 committed Aug 23, 2023
1 parent 51557be commit 9029071
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ class MapCalibrationFragment : BoundFragment<FragmentMapCalibrationBinding>() {
)
)

if (showPreview) {
layerManager?.start()
}

// Populate the last known location
layerManager?.onLocationChanged(gps.location, gps.horizontalAccuracy)

Expand Down Expand Up @@ -172,6 +168,10 @@ class MapCalibrationFragment : BoundFragment<FragmentMapCalibrationBinding>() {
manager.calibrate(calibrationIndex, it)
}

binding.previewButton.setOnClickListener {
setPreviewMode(!showPreview)
}

CustomUiUtils.setButtonState(binding.zoomInBtn, false)
CustomUiUtils.setButtonState(binding.zoomOutBtn, false)

Expand All @@ -186,18 +186,6 @@ class MapCalibrationFragment : BoundFragment<FragmentMapCalibrationBinding>() {
backCallback = promptIfUnsavedChanges {
hasChanges()
}

// Set map layers
if (showPreview) {
binding.calibrationMap.setLayers(
listOf(
pathLayer,
myAccuracyLayer,
myLocationLayer,
beaconLayer
)
)
}
}

fun setOnCompleteListener(listener: () -> Unit) {
Expand Down Expand Up @@ -228,6 +216,16 @@ class MapCalibrationFragment : BoundFragment<FragmentMapCalibrationBinding>() {
}

private fun updateMapCalibration() {
val isCalibrated = isFullyCalibrated()
if (binding.previewButton.isVisible != isCalibrated) {
binding.previewButton.isVisible = isCalibrated
CustomUiUtils.setButtonState(binding.previewButton, showPreview)
}

if (!isCalibrated && showPreview){
setPreviewMode(false)
}

map = map?.copy(
calibration = map!!.calibration.copy(
calibrationPoints = manager.getCalibration(false)
Expand Down Expand Up @@ -313,6 +311,35 @@ class MapCalibrationFragment : BoundFragment<FragmentMapCalibrationBinding>() {
}
}

private fun setPreviewMode(enabled: Boolean) {
if (showPreview == enabled) {
return
}

CustomUiUtils.setButtonState(binding.previewButton, enabled)

showPreview = enabled
val layers = if (enabled) listOf(
pathLayer,
myAccuracyLayer,
myLocationLayer,
beaconLayer
) else emptyList()
binding.calibrationMap.setLayers(layers)
updateMapCalibration()

if (showPreview){
layerManager?.start()
} else {
layerManager?.stop()
}

}

private fun isFullyCalibrated(): Boolean {
return manager.getCalibration(true).size == maxPoints
}

private suspend fun save(map: PhotoMap): PhotoMap {
var updated = mapRepo.getMap(map.id) ?: return map
updated =
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_map_calibration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/preview_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:alpha="0.86"
android:text="@string/preview"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.kylecorry.trail_sense.tools.maps.ui.MapCalibrationView
android:id="@+id/calibration_map"
android:layout_width="0dp"
Expand Down

0 comments on commit 9029071

Please sign in to comment.