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() | ||||
|     } | ||||
| 
 | ||||
|     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 | ||||
| 
 | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.EndlessSessionScreen | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen | ||||
| 
 | ||||
| class FunctionalEndlessTimer : FunctionalTimer(0) { | ||||
| 
 | ||||
|     override fun hasEnded(): Boolean { | ||||
|  | @ -16,4 +13,8 @@ class FunctionalEndlessTimer : FunctionalTimer(0) { | |||
|     override fun tick() { | ||||
|         time.plusOne() | ||||
|     } | ||||
| 
 | ||||
|     override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T { | ||||
|         return visitor.visitFunctionalEndlessTimer(this) | ||||
|     } | ||||
| } | ||||
|  | @ -39,4 +39,8 @@ class FunctionalPomodoroTimer( | |||
|     override fun hasCurrentCountdownEnded(): Boolean { | ||||
|         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 | ||||
| 
 | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen | ||||
| abstract class FunctionalTimer(initialValue: Int) { | ||||
|     val time: Time = Time(initialValue) | ||||
| 
 | ||||
|  | @ -13,4 +12,6 @@ abstract class FunctionalTimer(initialValue: Int) { | |||
|     abstract fun hasEnded(): 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 androidx.compose.runtime.Composable | ||||
| 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.screens.session.sessionScreens.BreakSessionScreen | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.CustomSessionScreen | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.EndlessSessionScreen | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen | ||||
| import be.ugent.sel.studeez.screens.session.sessionScreens.GetSessionScreen | ||||
| 
 | ||||
| data class SessionActions( | ||||
|     val getTimer: () -> FunctionalTimer, | ||||
|  | @ -51,12 +47,14 @@ fun SessionRoute( | |||
| //        mediaplayer.start() | ||||
|     } | ||||
| 
 | ||||
|     val sessionScreen = when (val timer = viewModel.getTimer()) { | ||||
|         is FunctionalCustomTimer -> CustomSessionScreen(timer) | ||||
|         is FunctionalPomodoroTimer -> BreakSessionScreen(timer) | ||||
|         is FunctionalEndlessTimer -> EndlessSessionScreen() | ||||
|         else -> throw java.lang.IllegalArgumentException("Unknown Timer") | ||||
|     } | ||||
|     val sessionScreen: AbstractSessionScreen = viewModel.getTimer().accept(GetSessionScreen()) | ||||
| 
 | ||||
|     //val sessionScreen = when (val timer = viewModel.getTimer()) { | ||||
|     //    is FunctionalCustomTimer -> CustomSessionScreen(timer) | ||||
|     //    is FunctionalPomodoroTimer -> BreakSessionScreen(timer) | ||||
|     //    is FunctionalEndlessTimer -> EndlessSessionScreen() | ||||
|     //    else -> throw java.lang.IllegalArgumentException("Unknown Timer") | ||||
|     //} | ||||
| 
 | ||||
|     sessionScreen( | ||||
|         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
	
	 Lukas Barragan Torres
						Lukas Barragan Torres