Merge pull request #79 from SELab1/localisation
created studystate for functional timer to improve localisation
This commit is contained in:
commit
9fd3df68f0
8 changed files with 45 additions and 22 deletions
|
@ -4,7 +4,7 @@ class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
if (time.time == 0) {
|
if (time.time == 0) {
|
||||||
view = DONE
|
view = StudyState.DONE
|
||||||
} else {
|
} else {
|
||||||
time.minOne()
|
time.minOne()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,17 @@ class FunctionalPomodoroTimer(
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
if (time.time == 0 && breaksRemaining == 0) {
|
if (time.time == 0 && breaksRemaining == 0) {
|
||||||
view = DONE
|
view = StudyState.DONE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time.time == 0) {
|
if (time.time == 0) {
|
||||||
if (isInBreak) {
|
if (isInBreak) {
|
||||||
breaksRemaining--
|
breaksRemaining--
|
||||||
view = FOCUS_REMAINING(breaksRemaining)
|
view = StudyState.FOCUS_REMAINING
|
||||||
time.time = studyTime
|
time.time = studyTime
|
||||||
} else {
|
} else {
|
||||||
view = BREAK
|
view = StudyState.BREAK
|
||||||
time.time = breakTime
|
time.time = breakTime
|
||||||
}
|
}
|
||||||
isInBreak = !isInBreak
|
isInBreak = !isInBreak
|
||||||
|
|
|
@ -2,7 +2,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
abstract class FunctionalTimer(initialValue: Int) {
|
abstract class FunctionalTimer(initialValue: Int) {
|
||||||
val time: Time = Time(initialValue)
|
val time: Time = Time(initialValue)
|
||||||
var view: String = FOCUS
|
var view: StudyState = StudyState.FOCUS
|
||||||
|
|
||||||
fun getHoursMinutesSeconds(): HoursMinutesSeconds {
|
fun getHoursMinutesSeconds(): HoursMinutesSeconds {
|
||||||
return time.getAsHMS()
|
return time.getAsHMS()
|
||||||
|
@ -12,11 +12,8 @@ abstract class FunctionalTimer(initialValue: Int) {
|
||||||
|
|
||||||
abstract fun hasEnded(): Boolean
|
abstract fun hasEnded(): Boolean
|
||||||
|
|
||||||
companion object {
|
enum class StudyState {
|
||||||
const val FOCUS: String = "Focus"
|
FOCUS, DONE, BREAK, FOCUS_REMAINING
|
||||||
const val DONE: String = "Done!"
|
|
||||||
const val BREAK: String = "Take a break!"
|
|
||||||
val FOCUS_REMAINING: (Int) -> String = { n -> "Focus! ($n breaks remaining)" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,15 +3,21 @@ package be.ugent.sel.studeez.screens.session
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import be.ugent.sel.studeez.R
|
import be.ugent.sel.studeez.R
|
||||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
||||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer.StudyState
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
@ -44,12 +50,24 @@ fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 80.sp
|
fontSize = 80.sp
|
||||||
)
|
)
|
||||||
|
val stateString: String = when (viewModel.getTimer().view) {
|
||||||
|
StudyState.DONE -> resources().getString(R.string.state_done)
|
||||||
|
StudyState.FOCUS -> resources().getString(R.string.state_focus)
|
||||||
|
StudyState.BREAK -> resources().getString(R.string.state_take_a_break)
|
||||||
|
StudyState.FOCUS_REMAINING ->
|
||||||
|
(viewModel.getTimer() as FunctionalPomodoroTimer?)?.breaksRemaining?.let {
|
||||||
|
resources().getQuantityString(R.plurals.state_focus_remaining, it, it)
|
||||||
|
}.toString()
|
||||||
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = viewModel.getTimer().view,
|
text = stateString,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
fontWeight = FontWeight.Light,
|
fontWeight = FontWeight.Light,
|
||||||
fontSize = 30.sp
|
fontSize = 30.sp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -64,6 +64,14 @@
|
||||||
<string name="timers">Timers</string>
|
<string name="timers">Timers</string>
|
||||||
<string name="edit">Edit</string>
|
<string name="edit">Edit</string>
|
||||||
<string name="add_timer">Add timer</string>
|
<string name="add_timer">Add timer</string>
|
||||||
|
<string name="state_focus">Focus!</string>
|
||||||
|
<plurals name="state_focus_remaining">
|
||||||
|
<item quantity="zero">Focus one more time!</item>
|
||||||
|
<item quantity="one">Focus! (%d break remaining)</item>
|
||||||
|
<item quantity="other">Focus! (%d breaks remaining)</item>
|
||||||
|
</plurals>
|
||||||
|
<string name="state_done">Done!</string>
|
||||||
|
<string name="state_take_a_break">Take a break!</string>
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
|
|
|
@ -37,7 +37,7 @@ class FunctionalCustomTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
timer.tick()
|
timer.tick()
|
||||||
Assert.assertTrue(timer.hasEnded())
|
Assert.assertTrue(timer.hasEnded())
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.DONE,
|
FunctionalTimer.StudyState.DONE,
|
||||||
timer.view
|
timer.view
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class FunctionalEndlessTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
timer.tick()
|
timer.tick()
|
||||||
Assert.assertFalse(timer.hasEnded())
|
Assert.assertFalse(timer.hasEnded())
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.FOCUS,
|
FunctionalTimer.StudyState.FOCUS,
|
||||||
timer.view
|
timer.view
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
class FunctionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
private val breakTime = 10
|
private val breakTime = 10
|
||||||
private val breaks = 2
|
private val breaks = 2
|
||||||
override val hours = 0
|
override val hours = 0
|
||||||
|
@ -30,7 +30,7 @@ class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
pomodoroTimer.breaksRemaining,
|
pomodoroTimer.breaksRemaining,
|
||||||
)
|
)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.FOCUS,
|
FunctionalTimer.StudyState.FOCUS,
|
||||||
pomodoroTimer.view,
|
pomodoroTimer.view,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
pomodoroTimer.tick()
|
pomodoroTimer.tick()
|
||||||
Assert.assertTrue(pomodoroTimer.hasEnded())
|
Assert.assertTrue(pomodoroTimer.hasEnded())
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.DONE,
|
FunctionalTimer.StudyState.DONE,
|
||||||
pomodoroTimer.view,
|
pomodoroTimer.view,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
Assert.assertFalse(pomodoroTimer.hasEnded())
|
Assert.assertFalse(pomodoroTimer.hasEnded())
|
||||||
Assert.assertTrue(pomodoroTimer.isInBreak)
|
Assert.assertTrue(pomodoroTimer.isInBreak)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.BREAK,
|
FunctionalTimer.StudyState.BREAK,
|
||||||
pomodoroTimer.view
|
pomodoroTimer.view
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
}
|
}
|
||||||
Assert.assertTrue(pomodoroTimer.isInBreak)
|
Assert.assertTrue(pomodoroTimer.isInBreak)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.BREAK,
|
FunctionalTimer.StudyState.BREAK,
|
||||||
pomodoroTimer.view
|
pomodoroTimer.view
|
||||||
)
|
)
|
||||||
for (i in 0..breakTime) {
|
for (i in 0..breakTime) {
|
||||||
|
@ -91,7 +91,7 @@ class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
pomodoroTimer.breaksRemaining
|
pomodoroTimer.breaksRemaining
|
||||||
)
|
)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
FunctionalTimer.FOCUS_REMAINING(breaksRemaining),
|
FunctionalTimer.StudyState.FOCUS_REMAINING,
|
||||||
pomodoroTimer.view
|
pomodoroTimer.view
|
||||||
)
|
)
|
||||||
}
|
}
|
Reference in a new issue