visitor
This commit is contained in:
parent
c3a9826001
commit
351547f111
7 changed files with 55 additions and 16 deletions
|
@ -19,4 +19,8 @@ class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
|
||||||
return hasEnded()
|
return hasEnded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T {
|
||||||
|
return visitor.visitFunctionalCustomTimer(this)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
package be.ugent.sel.studeez.data.local.models.timer_functional
|
package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.EndlessSessionScreen
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen
|
|
||||||
|
|
||||||
class FunctionalEndlessTimer : FunctionalTimer(0) {
|
class FunctionalEndlessTimer : FunctionalTimer(0) {
|
||||||
|
|
||||||
override fun hasEnded(): Boolean {
|
override fun hasEnded(): Boolean {
|
||||||
|
@ -16,4 +13,8 @@ class FunctionalEndlessTimer : FunctionalTimer(0) {
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
time.plusOne()
|
time.plusOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T {
|
||||||
|
return visitor.visitFunctionalEndlessTimer(this)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,4 +39,8 @@ class FunctionalPomodoroTimer(
|
||||||
override fun hasCurrentCountdownEnded(): Boolean {
|
override fun hasCurrentCountdownEnded(): Boolean {
|
||||||
return time.time == 0
|
return time.time == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T {
|
||||||
|
return visitor.visitFunctionalBreakTimer(this)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package be.ugent.sel.studeez.data.local.models.timer_functional
|
package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen
|
|
||||||
abstract class FunctionalTimer(initialValue: Int) {
|
abstract class FunctionalTimer(initialValue: Int) {
|
||||||
val time: Time = Time(initialValue)
|
val time: Time = Time(initialValue)
|
||||||
|
|
||||||
|
@ -13,4 +12,6 @@ abstract class FunctionalTimer(initialValue: Int) {
|
||||||
abstract fun hasEnded(): Boolean
|
abstract fun hasEnded(): Boolean
|
||||||
|
|
||||||
abstract fun hasCurrentCountdownEnded(): Boolean
|
abstract fun hasCurrentCountdownEnded(): Boolean
|
||||||
|
|
||||||
|
abstract fun <T> accept(visitor: FunctionalTimerVisitor<T>): T
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
|
interface FunctionalTimerVisitor<T> {
|
||||||
|
|
||||||
|
fun visitFunctionalCustomTimer(functionalCustomTimer: FunctionalCustomTimer): T
|
||||||
|
|
||||||
|
fun visitFunctionalEndlessTimer(functionalEndlessTimer: FunctionalEndlessTimer): T
|
||||||
|
|
||||||
|
fun visitFunctionalBreakTimer(functionalPomodoroTimer: FunctionalPomodoroTimer): T
|
||||||
|
|
||||||
|
}
|
|
@ -5,13 +5,9 @@ import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.BreakSessionScreen
|
import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.CustomSessionScreen
|
import be.ugent.sel.studeez.screens.session.sessionScreens.GetSessionScreen
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.EndlessSessionScreen
|
|
||||||
|
|
||||||
data class SessionActions(
|
data class SessionActions(
|
||||||
val getTimer: () -> FunctionalTimer,
|
val getTimer: () -> FunctionalTimer,
|
||||||
|
@ -51,12 +47,14 @@ fun SessionRoute(
|
||||||
// mediaplayer.start()
|
// mediaplayer.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
val sessionScreen = when (val timer = viewModel.getTimer()) {
|
val sessionScreen: AbstractSessionScreen = viewModel.getTimer().accept(GetSessionScreen())
|
||||||
is FunctionalCustomTimer -> CustomSessionScreen(timer)
|
|
||||||
is FunctionalPomodoroTimer -> BreakSessionScreen(timer)
|
//val sessionScreen = when (val timer = viewModel.getTimer()) {
|
||||||
is FunctionalEndlessTimer -> EndlessSessionScreen()
|
// is FunctionalCustomTimer -> CustomSessionScreen(timer)
|
||||||
else -> throw java.lang.IllegalArgumentException("Unknown Timer")
|
// is FunctionalPomodoroTimer -> BreakSessionScreen(timer)
|
||||||
}
|
// is FunctionalEndlessTimer -> EndlessSessionScreen()
|
||||||
|
// else -> throw java.lang.IllegalArgumentException("Unknown Timer")
|
||||||
|
//}
|
||||||
|
|
||||||
sessionScreen(
|
sessionScreen(
|
||||||
open = open,
|
open = open,
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package be.ugent.sel.studeez.screens.session.sessionScreens
|
||||||
|
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimerVisitor
|
||||||
|
|
||||||
|
class GetSessionScreen : FunctionalTimerVisitor<AbstractSessionScreen> {
|
||||||
|
override fun visitFunctionalCustomTimer(functionalCustomTimer: FunctionalCustomTimer): AbstractSessionScreen {
|
||||||
|
return CustomSessionScreen(functionalCustomTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitFunctionalEndlessTimer(functionalEndlessTimer: FunctionalEndlessTimer): AbstractSessionScreen {
|
||||||
|
return EndlessSessionScreen()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitFunctionalBreakTimer(functionalPomodoroTimer: FunctionalPomodoroTimer): AbstractSessionScreen {
|
||||||
|
return BreakSessionScreen(functionalPomodoroTimer)
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue