merge with dev
This commit is contained in:
		
						commit
						51c8fb122d
					
				
					 40 changed files with 890 additions and 444 deletions
				
			
		| 
						 | 
				
			
			@ -11,26 +11,21 @@ import be.ugent.sel.studeez.R
 | 
			
		|||
import be.ugent.sel.studeez.common.composable.BasicButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.ext.basicButton
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun HomeRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: HomeViewModel,
 | 
			
		||||
    drawerViewModel: DrawerViewModel,
 | 
			
		||||
    navBarViewModel: NavigationBarViewModel,
 | 
			
		||||
    drawerActions: DrawerActions,
 | 
			
		||||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
) {
 | 
			
		||||
    HomeScreen(
 | 
			
		||||
        onStartSessionClick = { viewModel.onStartSessionClick(open) },
 | 
			
		||||
        drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp),
 | 
			
		||||
        navigationBarActions = getNavigationBarActions(navBarViewModel, open),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,12 +35,11 @@ fun HomeScreen(
 | 
			
		|||
    drawerActions: DrawerActions,
 | 
			
		||||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.home),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        action = { FriendsAction() }
 | 
			
		||||
        barAction = { FriendsAction() }
 | 
			
		||||
    ) {
 | 
			
		||||
        BasicButton(R.string.start_session, Modifier.basicButton()) {
 | 
			
		||||
            onStartSessionClick()
 | 
			
		||||
| 
						 | 
				
			
			@ -69,6 +63,6 @@ fun HomeScreenPreview() {
 | 
			
		|||
    HomeScreen(
 | 
			
		||||
        onStartSessionClick = {},
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {})
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,6 @@ import androidx.compose.runtime.Composable
 | 
			
		|||
import androidx.compose.runtime.getValue
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.BasicTextButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.LabelledInputField
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,15 +11,12 @@ import androidx.compose.runtime.mutableStateOf
 | 
			
		|||
import androidx.compose.runtime.remember
 | 
			
		||||
import androidx.compose.runtime.setValue
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.Headline
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import kotlinx.coroutines.CoroutineScope
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,13 +38,14 @@ fun getProfileActions(
 | 
			
		|||
@Composable
 | 
			
		||||
fun ProfileRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: ProfileViewModel,
 | 
			
		||||
    drawerActions: DrawerActions,
 | 
			
		||||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
) {
 | 
			
		||||
    ProfileScreen(
 | 
			
		||||
        profileActions = getProfileActions(viewModel, open),
 | 
			
		||||
        drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp),
 | 
			
		||||
        navigationBarActions = getNavigationBarActions(hiltViewModel(), open),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +63,7 @@ fun ProfileScreen(
 | 
			
		|||
        title = resources().getString(AppText.profile),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        action = { EditAction(onClick = profileActions.onEditProfileClick) }
 | 
			
		||||
        barAction = { EditAction(onClick = profileActions.onEditProfileClick) }
 | 
			
		||||
    ) {
 | 
			
		||||
        Headline(text = (username ?: resources().getString(R.string.no_username)))
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -90,6 +88,6 @@ fun ProfileScreenPreview() {
 | 
			
		|||
    ProfileScreen(
 | 
			
		||||
        profileActions = ProfileActions({ null }, {}),
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {})
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
import javax.inject.Singleton
 | 
			
		||||
import kotlin.time.Duration.Companion.seconds
 | 
			
		||||
 | 
			
		||||
@Singleton
 | 
			
		||||
object InvisibleSessionManager {
 | 
			
		||||
    private var viewModel: SessionViewModel? = null
 | 
			
		||||
    private lateinit var mediaPlayer: MediaPlayer
 | 
			
		||||
 | 
			
		||||
    fun setParameters(viewModel: SessionViewModel, mediaplayer: MediaPlayer) {
 | 
			
		||||
        this.viewModel = viewModel
 | 
			
		||||
        this.mediaPlayer = mediaplayer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    suspend fun updateTimer() {
 | 
			
		||||
        viewModel?.let {
 | 
			
		||||
            while (!it.getTimer().hasEnded()) {
 | 
			
		||||
                delay(1.seconds)
 | 
			
		||||
                it.getTimer().tick()
 | 
			
		||||
                if (it.getTimer().hasCurrentCountdownEnded()) {
 | 
			
		||||
                    mediaPlayer.start()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,56 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
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.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,
 | 
			
		||||
    val getTask: () -> String,
 | 
			
		||||
    val startMediaPlayer: () -> Unit,
 | 
			
		||||
    val releaseMediaPlayer: () -> Unit,
 | 
			
		||||
    val endSession: () -> Unit
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
private fun getSessionActions(
 | 
			
		||||
    viewModel: SessionViewModel,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    mediaplayer: MediaPlayer,
 | 
			
		||||
): SessionActions {
 | 
			
		||||
    return SessionActions(
 | 
			
		||||
        getTimer = viewModel::getTimer,
 | 
			
		||||
        getTask = viewModel::getTask,
 | 
			
		||||
        endSession = { viewModel.endSession(openAndPopUp) },
 | 
			
		||||
        startMediaPlayer = mediaplayer::start,
 | 
			
		||||
        releaseMediaPlayer = mediaplayer::release,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: SessionViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
 | 
			
		||||
    val mediaplayer = MediaPlayer.create(context, uri)
 | 
			
		||||
    mediaplayer.isLooping = false
 | 
			
		||||
 | 
			
		||||
    InvisibleSessionManager.setParameters(
 | 
			
		||||
        viewModel = viewModel,
 | 
			
		||||
        mediaplayer = mediaplayer
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    val sessionScreen: AbstractSessionScreen = viewModel.getTimer().accept(GetSessionScreen(mediaplayer))
 | 
			
		||||
 | 
			
		||||
    sessionScreen(
 | 
			
		||||
        open = open,
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, openAndPopUp, mediaplayer)
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,212 +0,0 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
import android.media.RingtoneManager
 | 
			
		||||
import android.net.Uri
 | 
			
		||||
import androidx.compose.foundation.background
 | 
			
		||||
import androidx.compose.foundation.border
 | 
			
		||||
import androidx.compose.foundation.layout.Box
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.layout.fillMaxWidth
 | 
			
		||||
import androidx.compose.foundation.layout.padding
 | 
			
		||||
import androidx.compose.foundation.shape.RoundedCornerShape
 | 
			
		||||
import androidx.compose.material.Text
 | 
			
		||||
import androidx.compose.material.TextButton
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.runtime.LaunchedEffect
 | 
			
		||||
import androidx.compose.runtime.getValue
 | 
			
		||||
import androidx.compose.runtime.mutableStateOf
 | 
			
		||||
import androidx.compose.runtime.remember
 | 
			
		||||
import androidx.compose.runtime.setValue
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.graphics.Color
 | 
			
		||||
import androidx.compose.ui.platform.LocalContext
 | 
			
		||||
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.R
 | 
			
		||||
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.StudyState
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
import kotlin.time.Duration.Companion.seconds
 | 
			
		||||
 | 
			
		||||
var timerEnd = false
 | 
			
		||||
 | 
			
		||||
data class SessionActions(
 | 
			
		||||
    val getTimer: () -> FunctionalTimer,
 | 
			
		||||
    val getTask: () -> String,
 | 
			
		||||
    val prepareMediaPlayer: () -> Unit,
 | 
			
		||||
    val releaseMediaPlayer: () -> Unit,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
fun getSessionActions(
 | 
			
		||||
    viewModel: SessionViewModel,
 | 
			
		||||
    mediaplayer: MediaPlayer,
 | 
			
		||||
): SessionActions {
 | 
			
		||||
    return SessionActions(
 | 
			
		||||
        getTimer = viewModel::getTimer,
 | 
			
		||||
        getTask = viewModel::getTask,
 | 
			
		||||
        prepareMediaPlayer = mediaplayer::prepareAsync,
 | 
			
		||||
        releaseMediaPlayer = mediaplayer::release,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    viewModel: SessionViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
 | 
			
		||||
    val mediaplayer = MediaPlayer()
 | 
			
		||||
    mediaplayer.setDataSource(context, uri)
 | 
			
		||||
    mediaplayer.setOnCompletionListener {
 | 
			
		||||
        mediaplayer.stop()
 | 
			
		||||
        if (timerEnd) {
 | 
			
		||||
//            mediaplayer.release()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    mediaplayer.setOnPreparedListener {
 | 
			
		||||
//        mediaplayer.start()
 | 
			
		||||
    }
 | 
			
		||||
    SessionScreen(
 | 
			
		||||
        open = open,
 | 
			
		||||
        sessionActions = getSessionActions(viewModel, mediaplayer),
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionScreen(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    sessionActions: SessionActions,
 | 
			
		||||
) {
 | 
			
		||||
    Column(
 | 
			
		||||
        modifier = Modifier.padding(10.dp)
 | 
			
		||||
    ) {
 | 
			
		||||
        Timer(
 | 
			
		||||
            sessionActions = sessionActions,
 | 
			
		||||
        )
 | 
			
		||||
        Box(
 | 
			
		||||
            contentAlignment = Alignment.Center, modifier = Modifier
 | 
			
		||||
                .fillMaxWidth()
 | 
			
		||||
                .padding(50.dp)
 | 
			
		||||
        ) {
 | 
			
		||||
            TextButton(
 | 
			
		||||
                onClick = {
 | 
			
		||||
                    sessionActions.releaseMediaPlayer
 | 
			
		||||
                    open(StudeezDestinations.HOME_SCREEN)
 | 
			
		||||
                    // Vanaf hier ook naar report gaan als "end session" knop word ingedrukt
 | 
			
		||||
                },
 | 
			
		||||
                modifier = Modifier
 | 
			
		||||
                    .padding(horizontal = 20.dp)
 | 
			
		||||
                    .border(1.dp, Color.Red, RoundedCornerShape(32.dp))
 | 
			
		||||
                    .background(Color.Transparent)
 | 
			
		||||
            ) {
 | 
			
		||||
                Text(
 | 
			
		||||
                    text = "End session",
 | 
			
		||||
                    color = Color.Red,
 | 
			
		||||
                    fontWeight = FontWeight.Bold,
 | 
			
		||||
                    fontSize = 18.sp,
 | 
			
		||||
                    modifier = Modifier.padding(1.dp)
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
private fun Timer(
 | 
			
		||||
    sessionActions: SessionActions,
 | 
			
		||||
) {
 | 
			
		||||
    var tikker by remember { mutableStateOf(false) }
 | 
			
		||||
    LaunchedEffect(tikker) {
 | 
			
		||||
        delay(1.seconds)
 | 
			
		||||
        sessionActions.getTimer().tick()
 | 
			
		||||
        tikker = !tikker
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (
 | 
			
		||||
        sessionActions.getTimer().hasCurrentCountdownEnded() && !sessionActions.getTimer()
 | 
			
		||||
            .hasEnded()
 | 
			
		||||
    ) {
 | 
			
		||||
//        sessionActions.prepareMediaPlayer()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!timerEnd && sessionActions.getTimer().hasEnded()) {
 | 
			
		||||
//        sessionActions.prepareMediaPlayer()
 | 
			
		||||
        timerEnd =
 | 
			
		||||
            true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val hms = sessionActions.getTimer().getHoursMinutesSeconds()
 | 
			
		||||
    Column {
 | 
			
		||||
        Text(
 | 
			
		||||
            text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
 | 
			
		||||
            modifier = Modifier
 | 
			
		||||
                .fillMaxWidth()
 | 
			
		||||
                .padding(50.dp),
 | 
			
		||||
            textAlign = TextAlign.Center,
 | 
			
		||||
            fontWeight = FontWeight.Bold,
 | 
			
		||||
            fontSize = 40.sp,
 | 
			
		||||
        )
 | 
			
		||||
        val stateString: String = when (sessionActions.getTimer().view) {
 | 
			
		||||
            StudyState.DONE -> resources().getString(R.string.state_done)
 | 
			
		||||
            StudyState.FOCUS -> resources().getString(R.string.state_focus)
 | 
			
		||||
            StudyState.BREAK -> resources().getString(R.string.state_take_a_break)
 | 
			
		||||
            StudyState.FOCUS_REMAINING -> (sessionActions.getTimer() as FunctionalPomodoroTimer?)?.breaksRemaining?.let {
 | 
			
		||||
                resources().getQuantityString(R.plurals.state_focus_remaining, it, it)
 | 
			
		||||
            }.toString()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Text(
 | 
			
		||||
            text = stateString,
 | 
			
		||||
            modifier = Modifier.fillMaxWidth(),
 | 
			
		||||
            textAlign = TextAlign.Center,
 | 
			
		||||
            fontWeight = FontWeight.Light,
 | 
			
		||||
            fontSize = 30.sp
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        Box(
 | 
			
		||||
            contentAlignment = Alignment.Center, modifier = Modifier
 | 
			
		||||
                .fillMaxWidth()
 | 
			
		||||
                .padding(50.dp)
 | 
			
		||||
        ) {
 | 
			
		||||
            Box(
 | 
			
		||||
                contentAlignment = Alignment.Center,
 | 
			
		||||
                modifier = Modifier
 | 
			
		||||
                    .padding(16.dp)
 | 
			
		||||
                    .background(Color.Blue, RoundedCornerShape(32.dp))
 | 
			
		||||
            ) {
 | 
			
		||||
                Text(
 | 
			
		||||
                    text = sessionActions.getTask(),
 | 
			
		||||
                    color = Color.White,
 | 
			
		||||
                    fontSize = 18.sp,
 | 
			
		||||
                    fontWeight = FontWeight.Bold,
 | 
			
		||||
                    modifier = Modifier.padding(vertical = 4.dp, horizontal = 20.dp)
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerPreview() {
 | 
			
		||||
    Timer(sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionPreview() {
 | 
			
		||||
    SessionScreen(
 | 
			
		||||
        open = {},
 | 
			
		||||
        sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +1,21 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session
 | 
			
		||||
 | 
			
		||||
import be.ugent.sel.studeez.data.SelectedTimerState
 | 
			
		||||
import be.ugent.sel.studeez.data.SessionReportState
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import be.ugent.sel.studeez.data.SelectedTimerState
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
class SessionViewModel @Inject constructor(
 | 
			
		||||
    private val selectedTimerState: SelectedTimerState,
 | 
			
		||||
    private val sessionReportState: SessionReportState,
 | 
			
		||||
    logService: LogService
 | 
			
		||||
) : StudeezViewModel(logService) {
 | 
			
		||||
 | 
			
		||||
    private val timer: FunctionalTimer = FunctionalPomodoroTimer(15, 5, 3)
 | 
			
		||||
    private val task : String = "No task selected" // placeholder for tasks implementation
 | 
			
		||||
 | 
			
		||||
    fun getTimer() : FunctionalTimer {
 | 
			
		||||
| 
						 | 
				
			
			@ -24,4 +25,9 @@ class SessionViewModel @Inject constructor(
 | 
			
		|||
    fun getTask(): String {
 | 
			
		||||
        return task
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun endSession(openAndPopUp: (String, String) -> Unit) {
 | 
			
		||||
        sessionReportState.sessionReport = getTimer().getSessionReport()
 | 
			
		||||
        openAndPopUp(StudeezDestinations.SESSION_RECAP, StudeezDestinations.SESSION_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,138 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session.sessionScreens
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.background
 | 
			
		||||
import androidx.compose.foundation.border
 | 
			
		||||
import androidx.compose.foundation.layout.Box
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.layout.fillMaxWidth
 | 
			
		||||
import androidx.compose.foundation.layout.padding
 | 
			
		||||
import androidx.compose.foundation.shape.RoundedCornerShape
 | 
			
		||||
import androidx.compose.material.Text
 | 
			
		||||
import androidx.compose.material.TextButton
 | 
			
		||||
import androidx.compose.runtime.*
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
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.screens.session.SessionActions
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
import kotlin.time.Duration.Companion.seconds
 | 
			
		||||
 | 
			
		||||
abstract class AbstractSessionScreen {
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    operator fun invoke(
 | 
			
		||||
        open: (String) -> Unit,
 | 
			
		||||
        sessionActions: SessionActions,
 | 
			
		||||
    ) {
 | 
			
		||||
        Column(
 | 
			
		||||
            modifier = Modifier.padding(10.dp)
 | 
			
		||||
        ) {
 | 
			
		||||
            Timer(
 | 
			
		||||
                sessionActions = sessionActions,
 | 
			
		||||
            )
 | 
			
		||||
            Box(
 | 
			
		||||
                contentAlignment = Alignment.Center, modifier = Modifier
 | 
			
		||||
                    .fillMaxWidth()
 | 
			
		||||
                    .padding(50.dp)
 | 
			
		||||
            ) {
 | 
			
		||||
                TextButton(
 | 
			
		||||
                    onClick = {
 | 
			
		||||
                        sessionActions.releaseMediaPlayer
 | 
			
		||||
                        sessionActions.endSession()
 | 
			
		||||
                    },
 | 
			
		||||
                    modifier = Modifier
 | 
			
		||||
                        .padding(horizontal = 20.dp)
 | 
			
		||||
                        .border(1.dp, Color.Red, RoundedCornerShape(32.dp))
 | 
			
		||||
                        .background(Color.Transparent)
 | 
			
		||||
                ) {
 | 
			
		||||
                    Text(
 | 
			
		||||
                        text = "End session",
 | 
			
		||||
                        color = Color.Red,
 | 
			
		||||
                        fontWeight = FontWeight.Bold,
 | 
			
		||||
                        fontSize = 18.sp,
 | 
			
		||||
                        modifier = Modifier.padding(1.dp)
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    fun Timer(
 | 
			
		||||
        sessionActions: SessionActions,
 | 
			
		||||
    ) {
 | 
			
		||||
        var tikker by remember { mutableStateOf(false) }
 | 
			
		||||
        LaunchedEffect(tikker) {
 | 
			
		||||
            delay(1.seconds)
 | 
			
		||||
            sessionActions.getTimer().tick()
 | 
			
		||||
            callMediaPlayer()
 | 
			
		||||
            tikker = !tikker
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        val hms = sessionActions.getTimer().getHoursMinutesSeconds()
 | 
			
		||||
        Column {
 | 
			
		||||
            Text(
 | 
			
		||||
                text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
 | 
			
		||||
                modifier = Modifier
 | 
			
		||||
                    .fillMaxWidth()
 | 
			
		||||
                    .padding(50.dp),
 | 
			
		||||
                textAlign = TextAlign.Center,
 | 
			
		||||
                fontWeight = FontWeight.Bold,
 | 
			
		||||
                fontSize = 40.sp,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            Text(
 | 
			
		||||
                text = motivationString(),
 | 
			
		||||
                modifier = Modifier.fillMaxWidth(),
 | 
			
		||||
                textAlign = TextAlign.Center,
 | 
			
		||||
                fontWeight = FontWeight.Light,
 | 
			
		||||
                fontSize = 30.sp
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            Box(
 | 
			
		||||
                contentAlignment = Alignment.Center, modifier = Modifier
 | 
			
		||||
                    .fillMaxWidth()
 | 
			
		||||
                    .padding(50.dp)
 | 
			
		||||
            ) {
 | 
			
		||||
                Box(
 | 
			
		||||
                    contentAlignment = Alignment.Center,
 | 
			
		||||
                    modifier = Modifier
 | 
			
		||||
                        .padding(16.dp)
 | 
			
		||||
                        .background(Color.Blue, RoundedCornerShape(32.dp))
 | 
			
		||||
                ) {
 | 
			
		||||
                    Text(
 | 
			
		||||
                        text = sessionActions.getTask(),
 | 
			
		||||
                        color = Color.White,
 | 
			
		||||
                        fontSize = 18.sp,
 | 
			
		||||
                        fontWeight = FontWeight.Bold,
 | 
			
		||||
                        modifier = Modifier.padding(vertical = 4.dp, horizontal = 20.dp)
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    abstract fun motivationString(): String
 | 
			
		||||
 | 
			
		||||
    abstract fun callMediaPlayer()
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerPreview() {
 | 
			
		||||
    val sessionScreen = object : AbstractSessionScreen() {
 | 
			
		||||
        @Composable
 | 
			
		||||
        override fun motivationString(): String = "Test"
 | 
			
		||||
        override fun callMediaPlayer() {}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    sessionScreen.Timer(sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}, {}))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session.sessionScreens
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
class BreakSessionScreen(
 | 
			
		||||
    private val funPomoDoroTimer: FunctionalPomodoroTimer,
 | 
			
		||||
    private var mediaplayer: MediaPlayer?
 | 
			
		||||
): AbstractSessionScreen() {
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    override fun motivationString(): String {
 | 
			
		||||
        if (funPomoDoroTimer.isInBreak) {
 | 
			
		||||
            return resources().getString(AppText.state_take_a_break)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (funPomoDoroTimer.hasEnded()) {
 | 
			
		||||
            return resources().getString(AppText.state_done)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return resources().getQuantityString(
 | 
			
		||||
            R.plurals.state_focus_remaining,
 | 
			
		||||
            funPomoDoroTimer.breaksRemaining,
 | 
			
		||||
            funPomoDoroTimer.breaksRemaining
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun callMediaPlayer() {
 | 
			
		||||
        if (funPomoDoroTimer.hasEnded()) {
 | 
			
		||||
            mediaplayer?.let { it: MediaPlayer ->
 | 
			
		||||
                it.setOnCompletionListener {
 | 
			
		||||
                    it.release()
 | 
			
		||||
                    mediaplayer = null
 | 
			
		||||
                }
 | 
			
		||||
                it.start()
 | 
			
		||||
            }
 | 
			
		||||
        } else if (funPomoDoroTimer.hasCurrentCountdownEnded()) {
 | 
			
		||||
            mediaplayer?.start()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session.sessionScreens
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CustomSessionScreen(
 | 
			
		||||
    private val functionalTimer: FunctionalCustomTimer,
 | 
			
		||||
    private var mediaplayer: MediaPlayer?
 | 
			
		||||
): AbstractSessionScreen() {
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    override fun motivationString(): String {
 | 
			
		||||
        if (functionalTimer.hasEnded()) {
 | 
			
		||||
            return resources().getString(AppText.state_done)
 | 
			
		||||
        }
 | 
			
		||||
        return resources().getString(AppText.state_focus)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun callMediaPlayer() {
 | 
			
		||||
        if (functionalTimer.hasEnded()) {
 | 
			
		||||
            mediaplayer?.let { it: MediaPlayer ->
 | 
			
		||||
                it.setOnCompletionListener {
 | 
			
		||||
                    it.release()
 | 
			
		||||
                    mediaplayer = null
 | 
			
		||||
                }
 | 
			
		||||
                it.start()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session.sessionScreens
 | 
			
		||||
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EndlessSessionScreen : AbstractSessionScreen() {
 | 
			
		||||
 | 
			
		||||
    @Composable
 | 
			
		||||
    override fun motivationString(): String {
 | 
			
		||||
        return resources().getString(AppText.state_focus)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun callMediaPlayer() {}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session.sessionScreens
 | 
			
		||||
 | 
			
		||||
import android.media.MediaPlayer
 | 
			
		||||
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(private val mediaplayer: MediaPlayer?) : FunctionalTimerVisitor<AbstractSessionScreen> {
 | 
			
		||||
    override fun visitFunctionalCustomTimer(functionalCustomTimer: FunctionalCustomTimer): AbstractSessionScreen =
 | 
			
		||||
        CustomSessionScreen(functionalCustomTimer, mediaplayer)
 | 
			
		||||
 | 
			
		||||
    override fun visitFunctionalEndlessTimer(functionalEndlessTimer: FunctionalEndlessTimer): AbstractSessionScreen =
 | 
			
		||||
        EndlessSessionScreen()
 | 
			
		||||
 | 
			
		||||
    override fun visitFunctionalBreakTimer(functionalPomodoroTimer: FunctionalPomodoroTimer): AbstractSessionScreen =
 | 
			
		||||
        BreakSessionScreen(functionalPomodoroTimer, mediaplayer)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,67 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session_recap
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.material.ButtonDefaults
 | 
			
		||||
import androidx.compose.material.Text
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.graphics.Color
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.BasicButton
 | 
			
		||||
import be.ugent.sel.studeez.common.ext.basicButton
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.SessionReport
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_functional.Time
 | 
			
		||||
 | 
			
		||||
data class SessionRecapActions(
 | 
			
		||||
    val getSessionReport: () -> SessionReport,
 | 
			
		||||
    val saveSession: () -> Unit,
 | 
			
		||||
    val discardSession: () -> Unit
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
fun getSessionRecapActions(
 | 
			
		||||
    viewModel: SessionRecapViewModel,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
): SessionRecapActions {
 | 
			
		||||
    return SessionRecapActions(
 | 
			
		||||
        viewModel::getSessionReport,
 | 
			
		||||
        {viewModel.saveSession(openAndPopUp)},
 | 
			
		||||
        {viewModel.discardSession(openAndPopUp)}
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionRecapRoute(
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    modifier: Modifier = Modifier,
 | 
			
		||||
    viewModel: SessionRecapViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    SessionRecapScreen(
 | 
			
		||||
        modifier = modifier,
 | 
			
		||||
        getSessionRecapActions(viewModel, openAndPopUp)
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionRecapScreen(modifier: Modifier, sessionRecapActions: SessionRecapActions) {
 | 
			
		||||
    val sessionReport: SessionReport = sessionRecapActions.getSessionReport()
 | 
			
		||||
    val studyTime: Int = sessionReport.studyTime
 | 
			
		||||
    val hms: HoursMinutesSeconds = Time(studyTime).getAsHMS()
 | 
			
		||||
    Column(
 | 
			
		||||
        modifier = modifier
 | 
			
		||||
    ) {
 | 
			
		||||
        Text(text = "You studied: ${hms.hours} : ${hms.minutes} : ${hms.seconds}")
 | 
			
		||||
 | 
			
		||||
        BasicButton(
 | 
			
		||||
            R.string.save, Modifier.basicButton()
 | 
			
		||||
        ) {
 | 
			
		||||
            sessionRecapActions.saveSession()
 | 
			
		||||
        }
 | 
			
		||||
        BasicButton(
 | 
			
		||||
            R.string.discard, Modifier.basicButton(),
 | 
			
		||||
            colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red)
 | 
			
		||||
        ) {
 | 
			
		||||
            sessionRecapActions.discardSession()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session_recap
 | 
			
		||||
 | 
			
		||||
import be.ugent.sel.studeez.data.SessionReportState
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.SessionReport
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.domain.SessionDAO
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
class SessionRecapViewModel @Inject constructor(
 | 
			
		||||
    sessionReportState: SessionReportState,
 | 
			
		||||
    private val sessionDAO: SessionDAO,
 | 
			
		||||
    logService: LogService
 | 
			
		||||
) : StudeezViewModel(logService) {
 | 
			
		||||
 | 
			
		||||
    private val report: SessionReport = sessionReportState.sessionReport!!
 | 
			
		||||
 | 
			
		||||
    fun getSessionReport(): SessionReport {
 | 
			
		||||
        return report
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun saveSession(open: (String, String) -> Unit) {
 | 
			
		||||
        sessionDAO.saveSession(getSessionReport())
 | 
			
		||||
        open(StudeezDestinations.HOME_SCREEN, StudeezDestinations.SESSION_RECAP)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun discardSession(open: (String, String) -> Unit) {
 | 
			
		||||
        open(StudeezDestinations.HOME_SCREEN, StudeezDestinations.SESSION_RECAP)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.splash
 | 
			
		||||
 | 
			
		||||
import android.window.SplashScreen
 | 
			
		||||
import androidx.compose.foundation.background
 | 
			
		||||
import androidx.compose.foundation.layout.Arrangement
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,25 +1,17 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.timer_overview
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.layout.Arrangement
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.lazy.LazyColumn
 | 
			
		||||
import androidx.compose.foundation.lazy.items
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.runtime.collectAsState
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.BasicButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.DrawerScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.StealthButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.TimerEntry
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.ext.basicButton
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
 | 
			
		||||
| 
						 | 
				
			
			@ -50,56 +42,48 @@ fun getTimerOverviewActions(
 | 
			
		|||
@Composable
 | 
			
		||||
fun TimerOverviewRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: TimerOverviewViewModel,
 | 
			
		||||
    drawerViewModel: DrawerViewModel,
 | 
			
		||||
    navBarViewModel: NavigationBarViewModel,
 | 
			
		||||
    drawerActions: DrawerActions,
 | 
			
		||||
) {
 | 
			
		||||
    TimerOverviewScreen(
 | 
			
		||||
        timerOverviewActions = getTimerOverviewActions(viewModel, open),
 | 
			
		||||
        drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp),
 | 
			
		||||
        navigationBarActions = getNavigationBarActions(navBarViewModel, open),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerOverviewScreen(
 | 
			
		||||
    timerOverviewActions: TimerOverviewActions,
 | 
			
		||||
    drawerActions: DrawerActions,
 | 
			
		||||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
    drawerActions: DrawerActions
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList())
 | 
			
		||||
 | 
			
		||||
    // TODO moet geen primary screen zijn: geen navbar nodig
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
    DrawerScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.timers),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        drawerActions = drawerActions
 | 
			
		||||
    ) {
 | 
			
		||||
        Column {
 | 
			
		||||
            LazyColumn(
 | 
			
		||||
                verticalArrangement = Arrangement.spacedBy(7.dp)
 | 
			
		||||
            ) {
 | 
			
		||||
                // Default Timers, cannot be edited
 | 
			
		||||
                items(timerOverviewActions.getDefaultTimers()) {
 | 
			
		||||
                    TimerEntry(timerInfo = it) {}
 | 
			
		||||
                }
 | 
			
		||||
                // User timers, can be edited
 | 
			
		||||
                items(timers.value) { timerInfo ->
 | 
			
		||||
                    TimerEntry(
 | 
			
		||||
                        timerInfo = timerInfo,
 | 
			
		||||
                    ) {
 | 
			
		||||
                        StealthButton(
 | 
			
		||||
                            text = R.string.edit,
 | 
			
		||||
                            onClick = { timerOverviewActions.onEditClick(timerInfo) }
 | 
			
		||||
                        )
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
        LazyColumn {
 | 
			
		||||
            // Default Timers, cannot be edited
 | 
			
		||||
            items(timerOverviewActions.getDefaultTimers()) {
 | 
			
		||||
                TimerEntry(timerInfo = it) {}
 | 
			
		||||
            }
 | 
			
		||||
            BasicButton(R.string.add_timer, Modifier.basicButton()) {
 | 
			
		||||
                timerOverviewActions.open(StudeezDestinations.ADD_TIMER_SCREEN)
 | 
			
		||||
            // User timers, can be edited
 | 
			
		||||
            items(timers.value) { timerInfo ->
 | 
			
		||||
                TimerEntry(
 | 
			
		||||
                    timerInfo = timerInfo,
 | 
			
		||||
                ) {
 | 
			
		||||
                    StealthButton(
 | 
			
		||||
                        text = R.string.edit,
 | 
			
		||||
                        onClick = { timerOverviewActions.onEditClick(timerInfo) }
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            item {
 | 
			
		||||
                BasicButton(R.string.add_timer, Modifier.basicButton()) {
 | 
			
		||||
                    timerOverviewActions.open(StudeezDestinations.ADD_TIMER_SCREEN)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -118,7 +102,6 @@ fun TimerOverviewPreview() {
 | 
			
		|||
            {},
 | 
			
		||||
            {}
 | 
			
		||||
        ),
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {})
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,22 +1,14 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.timer_selection
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.layout.Arrangement
 | 
			
		||||
import androidx.compose.foundation.lazy.LazyColumn
 | 
			
		||||
import androidx.compose.foundation.lazy.items
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.runtime.collectAsState
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.StealthButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.TimerEntry
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
| 
						 | 
				
			
			@ -40,43 +32,37 @@ fun getTimerSelectionActions(
 | 
			
		|||
@Composable
 | 
			
		||||
fun TimerSelectionRoute(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    popUp: () -> Unit,
 | 
			
		||||
    viewModel: TimerSelectionViewModel,
 | 
			
		||||
    drawerViewModel: DrawerViewModel,
 | 
			
		||||
    navBarViewModel: NavigationBarViewModel,
 | 
			
		||||
) {
 | 
			
		||||
    TimerSelectionScreen(
 | 
			
		||||
        timerSelectionActions = getTimerSelectionActions(viewModel, open),
 | 
			
		||||
        drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp),
 | 
			
		||||
        navigationBarActions = getNavigationBarActions(navBarViewModel, open),
 | 
			
		||||
        popUp = popUp
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerSelectionScreen(
 | 
			
		||||
    timerSelectionActions: TimerSelectionActions,
 | 
			
		||||
    drawerActions: DrawerActions,
 | 
			
		||||
    navigationBarActions: NavigationBarActions,
 | 
			
		||||
    popUp: () -> Unit
 | 
			
		||||
) {
 | 
			
		||||
    val timers = timerSelectionActions.getAllTimers().collectAsState(initial = emptyList())
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
    SecondaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.timers),
 | 
			
		||||
        drawerActions = drawerActions,
 | 
			
		||||
        navigationBarActions = navigationBarActions,
 | 
			
		||||
        popUp = popUp
 | 
			
		||||
    ) {
 | 
			
		||||
        LazyColumn(
 | 
			
		||||
            verticalArrangement = Arrangement.spacedBy(7.dp),
 | 
			
		||||
        ) {
 | 
			
		||||
        LazyColumn {
 | 
			
		||||
            // All timers
 | 
			
		||||
            items(timers.value) { timerInfo ->
 | 
			
		||||
                TimerEntry(
 | 
			
		||||
                    timerInfo = timerInfo,
 | 
			
		||||
                ) {
 | 
			
		||||
                    StealthButton(
 | 
			
		||||
                        text = R.string.start,
 | 
			
		||||
                        onClick = { timerSelectionActions.startSession(timerInfo) }
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
                    leftButton = {
 | 
			
		||||
                        StealthButton(
 | 
			
		||||
                            text = R.string.start,
 | 
			
		||||
                            onClick = { timerSelectionActions.startSession(timerInfo) }
 | 
			
		||||
                        )
 | 
			
		||||
                    }
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -87,7 +73,6 @@ fun TimerSelectionScreen(
 | 
			
		|||
fun TimerSelectionPreview() {
 | 
			
		||||
    TimerSelectionScreen(
 | 
			
		||||
        timerSelectionActions = TimerSelectionActions({ flowOf() }, {}),
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {}),
 | 
			
		||||
        popUp = {}
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue