mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-05-06 12:58:58 +02:00
add some Reset functionality
This commit is contained in:
parent
caef58df54
commit
fdf769dbca
@ -12,10 +12,7 @@ import android.view.ViewGroup
|
|||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.extensions.config
|
import com.simplemobiletools.clock.extensions.config
|
||||||
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
|
||||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
|
||||||
import kotlinx.android.synthetic.main.fragment_stopwatch.view.*
|
import kotlinx.android.synthetic.main.fragment_stopwatch.view.*
|
||||||
|
|
||||||
class StopwatchFragment : Fragment() {
|
class StopwatchFragment : Fragment() {
|
||||||
@ -41,7 +38,14 @@ class StopwatchFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stopwatch_reset.setOnClickListener {
|
stopwatch_reset.setOnClickListener {
|
||||||
|
updateHandler.removeCallbacksAndMessages(null)
|
||||||
|
isRunning = false
|
||||||
|
currentTicks = 0
|
||||||
|
totalTicks = 0
|
||||||
|
stopwatch_reset.beGone()
|
||||||
|
stopwatch_lap.beGone()
|
||||||
|
stopwatch_time.text = 0L.formatStopwatchTime(false)
|
||||||
|
updateIcons()
|
||||||
}
|
}
|
||||||
|
|
||||||
stopwatch_lap.setOnClickListener {
|
stopwatch_lap.setOnClickListener {
|
||||||
@ -70,12 +74,13 @@ class StopwatchFragment : Fragment() {
|
|||||||
context!!.apply {
|
context!!.apply {
|
||||||
updateTextColors(view.stopwatch_fragment)
|
updateTextColors(view.stopwatch_fragment)
|
||||||
view.stopwatch_play_pause.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, getAdjustedPrimaryColor())
|
view.stopwatch_play_pause.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, getAdjustedPrimaryColor())
|
||||||
|
view.stopwatch_reset.applyColorFilter(config.textColor)
|
||||||
}
|
}
|
||||||
updatePlayPauseIcon()
|
updateIcons()
|
||||||
updateDisplayedText()
|
updateDisplayedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePlayPauseIcon() {
|
private fun updateIcons() {
|
||||||
val drawableId = if (isRunning) R.drawable.ic_pause else R.drawable.ic_play
|
val drawableId = if (isRunning) R.drawable.ic_pause else R.drawable.ic_play
|
||||||
val iconColor = if (context!!.getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else context!!.config.textColor
|
val iconColor = if (context!!.getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else context!!.config.textColor
|
||||||
view.stopwatch_play_pause.setImageDrawable(resources.getColoredDrawableWithColor(drawableId, iconColor))
|
view.stopwatch_play_pause.setImageDrawable(resources.getColoredDrawableWithColor(drawableId, iconColor))
|
||||||
@ -83,12 +88,13 @@ class StopwatchFragment : Fragment() {
|
|||||||
|
|
||||||
private fun togglePlayPause() {
|
private fun togglePlayPause() {
|
||||||
isRunning = !isRunning
|
isRunning = !isRunning
|
||||||
updatePlayPauseIcon()
|
updateIcons()
|
||||||
view.stopwatch_lap.beVisibleIf(isRunning)
|
view.stopwatch_lap.beVisibleIf(isRunning)
|
||||||
|
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
updateHandler.post(updateRunnable)
|
updateHandler.post(updateRunnable)
|
||||||
uptimeAtStart = SystemClock.uptimeMillis()
|
uptimeAtStart = SystemClock.uptimeMillis()
|
||||||
|
view.stopwatch_reset.beVisible()
|
||||||
} else {
|
} else {
|
||||||
val prevSessionsMS = (totalTicks - currentTicks) * UPDATE_INTERVAL
|
val prevSessionsMS = (totalTicks - currentTicks) * UPDATE_INTERVAL
|
||||||
val totalDuration = SystemClock.uptimeMillis() - uptimeAtStart + prevSessionsMS
|
val totalDuration = SystemClock.uptimeMillis() - uptimeAtStart + prevSessionsMS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user