refactor getters/setters
This commit is contained in:
parent
1c014e6ac5
commit
9834ce4a06
6 changed files with 15 additions and 27 deletions
|
@ -3,7 +3,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
|||
class FunctionalCustomTimer(studyTime: Int): FunctionalTimer(studyTime) {
|
||||
|
||||
override fun tick() {
|
||||
if (time.getTime() == 0) {
|
||||
if (time.time == 0) {
|
||||
view = "Done!"
|
||||
} else {
|
||||
time.minOne()
|
||||
|
@ -11,6 +11,6 @@ class FunctionalCustomTimer(studyTime: Int): FunctionalTimer(studyTime) {
|
|||
}
|
||||
|
||||
override fun hasEnded(): Boolean {
|
||||
return time.getTime() == 0
|
||||
return time.time == 0
|
||||
}
|
||||
}
|
|
@ -9,19 +9,19 @@ class FunctionalPomodoroTimer(
|
|||
private var isInBreak = false
|
||||
|
||||
override fun tick() {
|
||||
if (time.getTime() == 0 && breaksRemaining == 0){
|
||||
if (time.time == 0 && breaksRemaining == 0){
|
||||
view = "Done!"
|
||||
return
|
||||
}
|
||||
|
||||
if (time.getTime() == 0) {
|
||||
if (time.time == 0) {
|
||||
if (isInBreak) {
|
||||
breaksRemaining--
|
||||
view = "Focus! ($breaksRemaining breaks remaining)"
|
||||
time.setTime(studyTime)
|
||||
time.time = studyTime
|
||||
} else {
|
||||
view = "Take a break!"
|
||||
time.setTime(breakTime)
|
||||
time.time =breakTime
|
||||
}
|
||||
isInBreak = !isInBreak
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ class FunctionalPomodoroTimer(
|
|||
}
|
||||
|
||||
override fun hasEnded(): Boolean {
|
||||
return breaksRemaining == 0 && time.getTime() == 0
|
||||
return breaksRemaining == 0 && time.time == 0
|
||||
}
|
||||
}
|
|
@ -2,16 +2,12 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
|||
|
||||
abstract class FunctionalTimer(initialValue: Int) {
|
||||
protected val time: Time = Time(initialValue)
|
||||
protected var view: String = "Focus"
|
||||
var view: String = "Focus"
|
||||
|
||||
fun getHoursMinutesSeconds(): HoursMinutesSeconds {
|
||||
return time.getAsHMS()
|
||||
}
|
||||
|
||||
fun getViewString(): String {
|
||||
return view
|
||||
}
|
||||
|
||||
abstract fun tick()
|
||||
|
||||
abstract fun hasEnded(): Boolean
|
||||
|
|
|
@ -2,7 +2,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
|||
|
||||
class Time(initialTime: Int) {
|
||||
|
||||
private var time = initialTime
|
||||
var time = initialTime
|
||||
|
||||
fun minOne() {
|
||||
time--
|
||||
|
@ -12,14 +12,6 @@ class Time(initialTime: Int) {
|
|||
time++
|
||||
}
|
||||
|
||||
fun setTime(newTime: Int) {
|
||||
time = newTime
|
||||
}
|
||||
|
||||
fun getTime(): Int {
|
||||
return time
|
||||
}
|
||||
|
||||
fun getAsHMS(): HoursMinutesSeconds {
|
||||
val hours: Int = time / (60 * 60)
|
||||
val minutes: Int = (time / (60)) % 60
|
||||
|
|
|
@ -50,7 +50,7 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
|
|||
fontSize = 80.sp
|
||||
)
|
||||
Text(
|
||||
text = viewModel.getTimer().getViewString(),
|
||||
text = viewModel.getTimer().view,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textAlign = TextAlign.Center,
|
||||
fontWeight = FontWeight.Light,
|
||||
|
|
|
@ -32,7 +32,7 @@ class TimeUnitTest {
|
|||
@Test
|
||||
fun getTime() {
|
||||
Assert.assertEquals(
|
||||
time.getTime(),
|
||||
time.time,
|
||||
seconds + minutes * 60 + hours * 60 * 60
|
||||
)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class TimeUnitTest {
|
|||
fun minOne() {
|
||||
time.minOne()
|
||||
Assert.assertEquals(
|
||||
time.getTime(),
|
||||
time.time,
|
||||
(seconds + minutes * 60 + hours * 60 * 60) - 1
|
||||
)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class TimeUnitTest {
|
|||
fun plusOne() {
|
||||
time.plusOne()
|
||||
Assert.assertEquals(
|
||||
time.getTime(),
|
||||
time.time,
|
||||
(seconds + minutes * 60 + hours * 60 * 60) + 1
|
||||
)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class TimeUnitTest {
|
|||
time.minOne()
|
||||
}
|
||||
Assert.assertEquals(
|
||||
time.getTime(),
|
||||
time.time,
|
||||
(seconds + minutes * 60 + hours * 60 * 60) - n
|
||||
)
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class TimeUnitTest {
|
|||
time.plusOne()
|
||||
}
|
||||
Assert.assertEquals(
|
||||
time.getTime(),
|
||||
time.time,
|
||||
(seconds + minutes * 60 + hours * 60 * 60) + n
|
||||
)
|
||||
}
|
||||
|
|
Reference in a new issue