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() saveTrack()
} }
layout.clearButton.setOnClickListener { layout.clearButton.setOnClickListener {
if (track.wayPoints.isNotEmpty()) { if (track.wayPoints.isEmpty())
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 { // 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() 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 return layout.rootView

View file

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