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