Merge branch 'development' into session_recap
This commit is contained in:
		
						commit
						75429b2638
					
				
					 11 changed files with 66 additions and 45 deletions
				
			
		| 
						 | 
				
			
			@ -21,8 +21,8 @@ class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
 | 
			
		|||
        return hasEnded()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return CustomSessionScreen(this)
 | 
			
		||||
    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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +15,7 @@ class FunctionalEndlessTimer : FunctionalTimer(0) {
 | 
			
		|||
        totalStudyTime++
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return EndlessSessionScreen()
 | 
			
		||||
    override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T {
 | 
			
		||||
        return visitor.visitFunctionalEndlessTimer(this)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +44,7 @@ class FunctionalPomodoroTimer(
 | 
			
		|||
        return time.time == 0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun getView(): AbstractSessionScreen {
 | 
			
		||||
        return BreakSessionScreen(this)
 | 
			
		||||
    override fun <T> accept(visitor: FunctionalTimerVisitor<T>): T {
 | 
			
		||||
        return visitor.visitFunctionalBreakTimer(this)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +18,6 @@ abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		|||
 | 
			
		||||
    abstract fun hasCurrentCountdownEnded(): Boolean
 | 
			
		||||
 | 
			
		||||
    abstract fun getView(): AbstractSessionScreen
 | 
			
		||||
    fun getSessionReport(): SessionReport {
 | 
			
		||||
        return SessionReport(
 | 
			
		||||
            id = "",
 | 
			
		||||
| 
						 | 
				
			
			@ -27,4 +26,5 @@ abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		|||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
 | 
			
		|||
import androidx.compose.ui.platform.LocalContext
 | 
			
		||||
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.GetSessionScreen
 | 
			
		||||
 | 
			
		||||
data class SessionActions(
 | 
			
		||||
    val getTimer: () -> FunctionalTimer,
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +37,6 @@ fun SessionRoute(
 | 
			
		|||
    openAndPopUp: (String, 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()
 | 
			
		||||
| 
						 | 
				
			
			@ -50,8 +50,18 @@ fun SessionRoute(
 | 
			
		|||
    mediaplayer.setOnPreparedListener {
 | 
			
		||||
//        mediaplayer.start()
 | 
			
		||||
    }
 | 
			
		||||
    sessionScreen.SessionScreen(
 | 
			
		||||
 | 
			
		||||
    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,
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, openAndPopUp, mediaplayer),
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, openAndPopUp, mediaplayer)
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,10 @@ import androidx.compose.ui.Modifier
 | 
			
		|||
import androidx.compose.ui.graphics.Color
 | 
			
		||||
import androidx.compose.ui.text.font.FontWeight
 | 
			
		||||
import androidx.compose.ui.text.style.TextAlign
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import androidx.compose.ui.unit.sp
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.session.SessionActions
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +29,7 @@ abstract class AbstractSessionScreen {
 | 
			
		|||
    var timerEnd = false
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    fun SessionScreen(
 | 
			
		||||
    operator fun invoke(
 | 
			
		||||
        open: (String) -> Unit,
 | 
			
		||||
        sessionActions: SessionActions,
 | 
			
		||||
    ) {
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +67,7 @@ abstract class AbstractSessionScreen {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    private fun Timer(
 | 
			
		||||
    fun Timer(
 | 
			
		||||
        sessionActions: SessionActions,
 | 
			
		||||
    ) {
 | 
			
		||||
        var tikker by remember { mutableStateOf(false) }
 | 
			
		||||
| 
						 | 
				
			
			@ -84,8 +86,8 @@ abstract class AbstractSessionScreen {
 | 
			
		|||
 | 
			
		||||
        if (!timerEnd && sessionActions.getTimer().hasEnded()) {
 | 
			
		||||
//        sessionActions.prepareMediaPlayer()
 | 
			
		||||
            timerEnd =
 | 
			
		||||
                true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
 | 
			
		||||
             timerEnd =
 | 
			
		||||
                 true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        val hms = sessionActions.getTimer().getHoursMinutesSeconds()
 | 
			
		||||
| 
						 | 
				
			
			@ -134,4 +136,15 @@ abstract class AbstractSessionScreen {
 | 
			
		|||
    @Composable
 | 
			
		||||
    abstract fun motivationString(): String
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerPreview() {
 | 
			
		||||
    val sessionScreen = object : AbstractSessionScreen() {
 | 
			
		||||
        @Composable
 | 
			
		||||
        override fun motivationString(): String = "Test"
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    sessionScreen.Timer(sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
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 =
 | 
			
		||||
        CustomSessionScreen(functionalCustomTimer)
 | 
			
		||||
 | 
			
		||||
    override fun visitFunctionalEndlessTimer(functionalEndlessTimer: FunctionalEndlessTimer): AbstractSessionScreen =
 | 
			
		||||
        EndlessSessionScreen()
 | 
			
		||||
 | 
			
		||||
    override fun visitFunctionalBreakTimer(functionalPomodoroTimer: FunctionalPomodoroTimer): AbstractSessionScreen =
 | 
			
		||||
        BreakSessionScreen(functionalPomodoroTimer)
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue