Merge branch 'development' into sessionscreen_ui
This commit is contained in:
		
						commit
						9d2c53d4e6
					
				
					 26 changed files with 477 additions and 79 deletions
				
			
		| 
						 | 
				
			
			@ -15,14 +15,7 @@ class HomeViewModel @Inject constructor(
 | 
			
		|||
    logService: LogService
 | 
			
		||||
) : StudeezViewModel(logService) {
 | 
			
		||||
 | 
			
		||||
    fun onStartSessionClick(openAndPopUp: (String) -> Unit) {
 | 
			
		||||
        openAndPopUp(StudeezDestinations.SESSION_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onLogoutClick(openAndPopup: (String, String) -> Unit) {
 | 
			
		||||
        launchCatching {
 | 
			
		||||
            accountDAO.signOut()
 | 
			
		||||
            openAndPopup(LOGIN_SCREEN, HOME_SCREEN)
 | 
			
		||||
        }
 | 
			
		||||
    fun onStartSessionClick(open: (String) -> Unit) {
 | 
			
		||||
        open(StudeezDestinations.TIMER_SELECTION_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -14,16 +14,28 @@ import androidx.compose.material.Text
 | 
			
		|||
import androidx.compose.material.TextButton
 | 
			
		||||
import androidx.compose.runtime.*
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
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.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.unit.dp
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import androidx.compose.ui.unit.sp
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
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.resources
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
import kotlin.time.Duration.Companion.seconds
 | 
			
		||||
 | 
			
		||||
var timerEnd = false
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +43,6 @@ var timerEnd = false
 | 
			
		|||
fun SessionScreen(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: SessionViewModel = hiltViewModel()
 | 
			
		||||
) {
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
 | 
			
		||||
| 
						 | 
				
			
			@ -86,9 +97,9 @@ fun SessionScreen(
 | 
			
		|||
private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: MediaPlayer) {
 | 
			
		||||
    var tikker by remember { mutableStateOf(false) }
 | 
			
		||||
    LaunchedEffect(tikker) {
 | 
			
		||||
        delay(1000)
 | 
			
		||||
        delay(1.seconds)
 | 
			
		||||
        viewModel.getTimer().tick()
 | 
			
		||||
        tikker = !tikker
 | 
			
		||||
        ticker = !ticker
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (viewModel.getTimer().hasCurrentCountdownEnded() && !viewModel.getTimer().hasEnded()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -111,8 +122,18 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: Me
 | 
			
		|||
            fontWeight = FontWeight.Bold,
 | 
			
		||||
            fontSize = 40.sp,
 | 
			
		||||
        )
 | 
			
		||||
        val stateString: String = when (viewModel.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 ->
 | 
			
		||||
                (viewModel.getTimer() as FunctionalPomodoroTimer?)?.breaksRemaining?.let {
 | 
			
		||||
                    resources().getQuantityString(R.plurals.state_focus_remaining, it, it)
 | 
			
		||||
            }.toString()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Text(
 | 
			
		||||
            text = viewModel.getTimer().getViewString(),
 | 
			
		||||
            text = stateString,
 | 
			
		||||
            modifier = Modifier.fillMaxWidth(),
 | 
			
		||||
            textAlign = TextAlign.Center,
 | 
			
		||||
            fontWeight = FontWeight.Light,
 | 
			
		||||
| 
						 | 
				
			
			@ -142,4 +163,6 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: Me
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,14 +1,15 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.session
 | 
			
		||||
 | 
			
		||||
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.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import be.ugent.sel.studeez.data.SelectedTimerState
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
class SessionViewModel @Inject constructor(
 | 
			
		||||
    private val selectedTimerState: SelectedTimerState,
 | 
			
		||||
    logService: LogService
 | 
			
		||||
) : StudeezViewModel(logService) {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -16,7 +17,7 @@ class SessionViewModel @Inject constructor(
 | 
			
		|||
    private val task : String = "No task selected" // placeholder for tasks implementation
 | 
			
		||||
 | 
			
		||||
    fun getTimer() : FunctionalTimer {
 | 
			
		||||
        return timer
 | 
			
		||||
        return selectedTimerState.selectedTimer!!
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun getTask(): String {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.timer_overview
 | 
			
		||||
 | 
			
		||||
import androidx.annotation.StringRes
 | 
			
		||||
import androidx.compose.foundation.layout.Arrangement
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.layout.Row
 | 
			
		||||
| 
						 | 
				
			
			@ -46,12 +47,12 @@ fun TimerOverviewScreen(
 | 
			
		|||
            ) {
 | 
			
		||||
                // Default Timers, cannot be edited
 | 
			
		||||
                items(viewModel.getDefaultTimers()) {
 | 
			
		||||
                    TimerEntry(timerInfo = it, canEdit = false)
 | 
			
		||||
                    TimerEntry(timerInfo = it, canDisplay = false)
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // User timers, can be edited
 | 
			
		||||
                items(timers.value) {
 | 
			
		||||
                    TimerEntry(timerInfo = it, true) { timerInfo ->
 | 
			
		||||
                    TimerEntry(timerInfo = it, true, R.string.edit) { timerInfo ->
 | 
			
		||||
                        viewModel.update(timerInfo)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +66,12 @@ fun TimerOverviewScreen(
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerEntry(timerInfo: TimerInfo, canEdit: Boolean, update: (TimerInfo) -> Unit = {}) {
 | 
			
		||||
fun TimerEntry(
 | 
			
		||||
    timerInfo: TimerInfo,
 | 
			
		||||
    canDisplay: Boolean,
 | 
			
		||||
    @StringRes buttonName: Int = -1,
 | 
			
		||||
    buttonFunction: (TimerInfo) -> Unit = {}
 | 
			
		||||
) {
 | 
			
		||||
    Row(
 | 
			
		||||
        verticalAlignment = Alignment.CenterVertically,
 | 
			
		||||
        modifier = Modifier.fillMaxWidth(),
 | 
			
		||||
| 
						 | 
				
			
			@ -83,9 +89,9 @@ fun TimerEntry(timerInfo: TimerInfo, canEdit: Boolean, update: (TimerInfo) -> Un
 | 
			
		|||
                fontSize = 15.sp
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
        if (canEdit) {
 | 
			
		||||
            BasicButton(R.string.edit, Modifier.card()) {
 | 
			
		||||
                // TODO
 | 
			
		||||
        if (canDisplay) {
 | 
			
		||||
            BasicButton(buttonName, Modifier.card()) {
 | 
			
		||||
                buttonFunction(timerInfo)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
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.*
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.screens.timer_overview.TimerEntry
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun TimerSelectionScreen(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: TimerSelectionViewModel = hiltViewModel()
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    val timers = viewModel.getAllTimers().collectAsState(initial = emptyList())
 | 
			
		||||
 | 
			
		||||
    PrimaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.timers),
 | 
			
		||||
        open = open,
 | 
			
		||||
        openAndPopUp = openAndPopUp,
 | 
			
		||||
    ) {
 | 
			
		||||
 | 
			
		||||
        LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
 | 
			
		||||
 | 
			
		||||
            // All timers
 | 
			
		||||
            items(timers.value) {
 | 
			
		||||
                TimerEntry(
 | 
			
		||||
                    timerInfo = it,
 | 
			
		||||
                    canDisplay = true,
 | 
			
		||||
                    buttonName = R.string.start
 | 
			
		||||
                ) { timerInfo ->
 | 
			
		||||
                    viewModel.startSession(open, timerInfo)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.timer_selection
 | 
			
		||||
 | 
			
		||||
import be.ugent.sel.studeez.data.SelectedTimerState
 | 
			
		||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.domain.TimerDAO
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import kotlinx.coroutines.flow.Flow
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
class TimerSelectionViewModel @Inject constructor(
 | 
			
		||||
    private val timerDAO: TimerDAO,
 | 
			
		||||
    private val selectedTimerState: SelectedTimerState,
 | 
			
		||||
    logService: LogService
 | 
			
		||||
) : StudeezViewModel(logService) {
 | 
			
		||||
 | 
			
		||||
    fun getAllTimers() : Flow<List<TimerInfo>> {
 | 
			
		||||
        return timerDAO.getAllTimers()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun startSession(open: (String) -> Unit, timerInfo: TimerInfo) {
 | 
			
		||||
        selectedTimerState.selectedTimer = timerInfo.getFunctionalTimer()
 | 
			
		||||
        open(StudeezDestinations.SESSION_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +0,0 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.timers
 | 
			
		||||
 | 
			
		||||
class TimerScreen {
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue