Update timer sets/rounds to count down instead of counting up
This commit is contained in:
parent
f21754a0be
commit
46cb0e3c0a
4 changed files with 64 additions and 43 deletions
|
@ -92,16 +92,8 @@ class ActiveTimerFragment : Fragment() {
|
|||
timerBackground.setBackgroundColor(backgroundColor)
|
||||
playPauseButton.setImageDrawable(requireContext().getDrawable(state.playPauseIcon))
|
||||
timeRemaining.text = state.timeRemaining
|
||||
timerSets.text = getString(
|
||||
R.string.timer_sets_formatted,
|
||||
state.currentSet,
|
||||
state.totalSets
|
||||
)
|
||||
timerRounds.text = getString(
|
||||
R.string.timer_rounds_formatted,
|
||||
state.currentRound,
|
||||
state.totalRounds
|
||||
)
|
||||
timerSets.text = state.currentSet.toString()
|
||||
timerRounds.text = state.currentRound.toString()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
|
@ -38,7 +38,10 @@ class ActiveTimerViewModel : ViewModel() {
|
|||
if (timerJob == null || timer.id != timerId) {
|
||||
logger.d(message = "Initializing with Timer id $timerId")
|
||||
timer = timerDao.getById(timerId)
|
||||
currentSet = timer.sets
|
||||
currentRound = timer.cycles
|
||||
timeRemaining = timer.warmUpDuration
|
||||
currentPhase = Phase.WARM_UP
|
||||
timerState.postValue(
|
||||
TimerRunningState(
|
||||
timer,
|
||||
|
@ -132,13 +135,13 @@ class ActiveTimerViewModel : ViewModel() {
|
|||
}
|
||||
Phase.HIGH_INTENSITY -> {
|
||||
when {
|
||||
currentSet < timer.sets -> {
|
||||
currentSet++
|
||||
currentSet > 1 -> {
|
||||
currentSet--
|
||||
currentPhase = Phase.LOW_INTENSITY
|
||||
timeRemaining = timer.lowIntensityDuration
|
||||
}
|
||||
currentRound < timer.cycles -> {
|
||||
currentRound++
|
||||
currentRound > 1 -> {
|
||||
currentRound--
|
||||
currentPhase = Phase.REST
|
||||
timeRemaining = timer.restDuration
|
||||
}
|
||||
|
@ -149,7 +152,7 @@ class ActiveTimerViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
Phase.REST -> {
|
||||
currentSet = 1
|
||||
currentSet = timer.sets
|
||||
currentPhase = Phase.LOW_INTENSITY
|
||||
timeRemaining = timer.lowIntensityDuration
|
||||
}
|
||||
|
@ -169,16 +172,16 @@ class ActiveTimerViewModel : ViewModel() {
|
|||
}
|
||||
Phase.LOW_INTENSITY -> {
|
||||
when {
|
||||
currentSet == 1 && currentRound == 1 -> {
|
||||
currentSet == timer.sets && currentRound == timer.cycles -> {
|
||||
currentPhase = Phase.WARM_UP
|
||||
timeRemaining = timer.warmUpDuration
|
||||
}
|
||||
currentSet == 1 && currentRound > 1 -> {
|
||||
currentSet == timer.sets && currentRound < timer.cycles -> {
|
||||
currentPhase = Phase.REST
|
||||
timeRemaining = timer.restDuration
|
||||
}
|
||||
else -> {
|
||||
currentSet--
|
||||
currentSet++
|
||||
currentPhase = Phase.HIGH_INTENSITY
|
||||
timeRemaining = timer.highIntensityDuration
|
||||
}
|
||||
|
@ -189,7 +192,7 @@ class ActiveTimerViewModel : ViewModel() {
|
|||
timeRemaining = timer.lowIntensityDuration
|
||||
}
|
||||
Phase.REST -> {
|
||||
currentRound--
|
||||
currentRound++
|
||||
currentPhase = Phase.HIGH_INTENSITY
|
||||
currentSet = timer.sets
|
||||
timeRemaining = timer.highIntensityDuration
|
||||
|
@ -216,9 +219,7 @@ sealed class IntervalTimerActiveState {
|
|||
val timerName: String,
|
||||
val timeRemaining: String,
|
||||
val currentSet: Int,
|
||||
val totalSets: Int,
|
||||
val currentRound: Int,
|
||||
val totalRounds: Int,
|
||||
@ColorRes val timerBackground: Int,
|
||||
@DrawableRes val playPauseIcon: Int
|
||||
) : IntervalTimerActiveState() {
|
||||
|
@ -234,8 +235,6 @@ sealed class IntervalTimerActiveState {
|
|||
timeRemaining = timeRemaining.toIntervalDuration().toString(),
|
||||
currentSet = currentSet,
|
||||
currentRound = currentRound,
|
||||
totalSets = timer.sets,
|
||||
totalRounds = timer.cycles,
|
||||
timerBackground = phase.colorRes,
|
||||
playPauseIcon = if (timerRunning) R.drawable.ic_pause else R.drawable.ic_play_arrow
|
||||
)
|
||||
|
|
|
@ -34,37 +34,65 @@
|
|||
android:id="@+id/timerLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="playPauseButton,timerSets,timerRounds,timeRemaining,skipNextButton,skipPreviousButton" />
|
||||
app:constraint_referenced_ids="playPauseButton,setsContainer,roundsContainer,timeRemaining,skipNextButton,skipPreviousButton" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timerSets"
|
||||
<LinearLayout
|
||||
android:id="@+id/setsContainer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/timerRounds"
|
||||
app:layout_constraintEnd_toStartOf="@+id/roundsContainer"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:text="Set: 4/5" />
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timerRounds"
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_set"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timerSets"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
|
||||
tools:text="5" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/roundsContainer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/timerSets"
|
||||
tools:text="Round: 4/5" />
|
||||
app:layout_constraintStart_toEndOf="@+id/setsContainer">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_round"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timerRounds"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
|
||||
tools:text="4" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/timerInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="top"
|
||||
app:constraint_referenced_ids="timerSets,timerRounds" />
|
||||
app:constraint_referenced_ids="setsContainer,roundsContainer" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timeRemaining"
|
||||
|
@ -72,7 +100,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline2"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline1"
|
||||
android:textColor="@color/colorOnSurface"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playPauseButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -83,8 +111,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/skipPreviousButton"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:contentDescription="@string/skip_previous"
|
||||
android:scaleType="fitCenter"
|
||||
|
@ -98,8 +126,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/playPauseButton"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:contentDescription="@string/start_timer"
|
||||
android:scaleType="fitCenter"
|
||||
|
@ -111,8 +139,8 @@
|
|||
|
||||
<ImageButton
|
||||
android:id="@+id/skipNextButton"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:contentDescription="@string/skip_next"
|
||||
android:scaleType="fitCenter"
|
||||
|
|
|
@ -20,4 +20,6 @@
|
|||
<string name="title_item_detail">Item Detail</string>
|
||||
<string name="timer_sets_formatted">Set: %1$d/%2$d</string>
|
||||
<string name="timer_rounds_formatted">Round: %1$d/%2$d</string>
|
||||
<string name="label_set">Set</string>
|
||||
<string name="label_round">Round</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue