Fix live statistics not disappearing when track cleared.

This commit is contained in:
voussoir 2022-04-06 21:30:33 -07:00
parent ac5c3c2dd5
commit b01a900fd3
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 39 additions and 21 deletions

View file

@ -90,11 +90,20 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
saveTrack()
}
layout.clearButton.setOnClickListener {
if (track.wayPoints.isNotEmpty()) {
YesNoDialog(this as YesNoDialog.YesNoDialogListener).show(context = activity as Context, type = Keys.DIALOG_DELETE_CURRENT_RECORDING, message = R.string.dialog_delete_current_recording_message, yesButton = R.string.dialog_delete_current_recording_button_discard)
} else {
if (track.wayPoints.isEmpty())
{
// This might seem useless since it's already empty, but there are other UI updates
// that occur as part of cleartrack so we may as well take advantage of those.
trackerService.clearTrack()
}
else {
YesNoDialog(this as YesNoDialog.YesNoDialogListener).show(
context=activity as Context,
type = Keys.DIALOG_DELETE_CURRENT_RECORDING,
message = R.string.dialog_delete_current_recording_message,
yesButton = R.string.dialog_delete_current_recording_button_discard
)
}
}
return layout.rootView

View file

@ -201,13 +201,22 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
}
}
/* Update live statics */
fun updateLiveStatics(distance: Float, duration: Long, trackingState: Int) {
// toggle visibility
val trackingActive: Boolean = trackingState != Keys.STATE_TRACKING_NOT_STARTED
liveStatisticsDistanceView.isVisible = trackingActive
liveStatisticsDurationView.isVisible = trackingActive
if (trackingState == Keys.STATE_TRACKING_NOT_STARTED)
{
liveStatisticsDistanceView.isGone = true
liveStatisticsDurationView.isGone = true
liveStatisticsDistanceOutlineView.isGone = true
liveStatisticsDurationOutlineView.isGone = true
}
else
{
liveStatisticsDistanceView.isVisible = true
liveStatisticsDurationView.isVisible = true
liveStatisticsDistanceOutlineView.isVisible = true
liveStatisticsDurationOutlineView.isVisible = true
// update distance and duration (and add outline)
val distanceString: String = LengthUnitHelper.convertDistanceToString(distance, useImperial)
liveStatisticsDistanceView.text = distanceString
@ -219,12 +228,12 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
liveStatisticsDurationOutlineView.text = durationString
liveStatisticsDurationOutlineView.paint.strokeWidth = 5f
liveStatisticsDurationOutlineView.paint.style = Paint.Style.STROKE
}
}
/* Toggles state of main button and additional buttons (save & resume) */
fun updateMainButton(trackingState: Int) {
fun updateMainButton(trackingState: Int)
{
when (trackingState) {
Keys.STATE_TRACKING_NOT_STARTED -> {
mainButton.setIconResource(R.drawable.ic_fiber_manual_record_inactive_24dp)