add a helper function for reseting stopwatch

This commit is contained in:
tibbi 2018-03-07 23:37:04 +01:00
parent f19b8140cd
commit af91f217ef

View file

@ -42,17 +42,7 @@ class StopwatchFragment : Fragment() {
}
stopwatch_reset.setOnClickListener {
updateHandler.removeCallbacksAndMessages(null)
isRunning = false
currentTicks = 0
totalTicks = 0
currentLap = 0
lapTicks = 0
laps.clear()
stopwatch_reset.beGone()
stopwatch_lap.beGone()
stopwatch_time.text = 0L.formatStopwatchTime(false)
updateIcons()
resetStopwatch()
}
stopwatch_lap.setOnClickListener {
@ -118,6 +108,23 @@ class StopwatchFragment : Fragment() {
view.stopwatch_time.text = (totalTicks * UPDATE_INTERVAL).formatStopwatchTime(false)
}
private fun resetStopwatch() {
updateHandler.removeCallbacksAndMessages(null)
isRunning = false
currentTicks = 0
totalTicks = 0
currentLap = 0
lapTicks = 0
laps.clear()
updateIcons()
view.apply {
stopwatch_reset.beGone()
stopwatch_lap.beGone()
stopwatch_time.text = 0L.formatStopwatchTime(false)
}
}
private val updateRunnable = object : Runnable {
override fun run() {
if (isRunning) {