remove getView from functional timer and add when in sessionRoute
This commit is contained in:
		
							parent
							
								
									4996d387ad
								
							
						
					
					
						commit
						c3a9826001
					
				
					 6 changed files with 17 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -19,8 +19,4 @@ class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
 | 
			
		|||
        return hasEnded()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return CustomSessionScreen(this)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -16,8 +16,4 @@ class FunctionalEndlessTimer : FunctionalTimer(0) {
 | 
			
		|||
    override fun tick() {
 | 
			
		||||
        time.plusOne()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return EndlessSessionScreen()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -39,8 +39,4 @@ class FunctionalPomodoroTimer(
 | 
			
		|||
    override fun hasCurrentCountdownEnded(): Boolean {
 | 
			
		||||
        return time.time == 0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return BreakSessionScreen(this)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +13,4 @@ abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		|||
    abstract fun hasEnded(): Boolean
 | 
			
		||||
 | 
			
		||||
    abstract fun hasCurrentCountdownEnded(): Boolean
 | 
			
		||||
 | 
			
		||||
    abstract fun getView(): AbstractSessionScreen
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -5,8 +5,13 @@ 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.AbstractSessionScreen
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
data class SessionActions(
 | 
			
		||||
    val getTimer: () -> FunctionalTimer,
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +37,6 @@ fun SessionRoute(
 | 
			
		|||
    open: (String) -> Unit,
 | 
			
		||||
    viewModel: SessionViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    val sessionScreen: AbstractSessionScreen = viewModel.getTimer().getView()
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
 | 
			
		||||
    val mediaplayer = MediaPlayer()
 | 
			
		||||
| 
						 | 
				
			
			@ -46,8 +50,16 @@ fun SessionRoute(
 | 
			
		|||
    mediaplayer.setOnPreparedListener {
 | 
			
		||||
//        mediaplayer.start()
 | 
			
		||||
    }
 | 
			
		||||
    sessionScreen.SessionScreen(
 | 
			
		||||
 | 
			
		||||
    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,
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, mediaplayer),
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, mediaplayer)
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ abstract class AbstractSessionScreen {
 | 
			
		|||
    var timerEnd = false
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    fun SessionScreen(
 | 
			
		||||
    operator fun invoke(
 | 
			
		||||
        open: (String) -> Unit,
 | 
			
		||||
        sessionActions: SessionActions,
 | 
			
		||||
    ) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue