#65 sessionscreen
This commit is contained in:
		
							parent
							
								
									ffaedf5542
								
							
						
					
					
						commit
						169a7d3469
					
				
					 2 changed files with 73 additions and 1 deletions
				
			
		|  | @ -1,2 +1,58 @@ | |||
| package be.ugent.sel.studeez.screens.session | ||||
| 
 | ||||
| import androidx.compose.foundation.layout.Column | ||||
| import androidx.compose.foundation.layout.fillMaxWidth | ||||
| import androidx.compose.material.Text | ||||
| import androidx.compose.runtime.* | ||||
| import androidx.compose.ui.Modifier | ||||
| import androidx.compose.ui.text.font.FontWeight | ||||
| import androidx.compose.ui.text.style.TextAlign | ||||
| import androidx.compose.ui.unit.TextUnit | ||||
| import androidx.compose.ui.unit.dp | ||||
| import androidx.compose.ui.unit.sp | ||||
| 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 kotlinx.coroutines.delay | ||||
| 
 | ||||
| @Composable | ||||
| fun SessionScreen( | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: SessionViewModel = hiltViewModel() | ||||
| ) { | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(R.string.start_session), | ||||
|         openAndPopUp = openAndPopUp | ||||
|     ) { | ||||
|         Timer(viewModel) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| private fun Timer(viewModel: SessionViewModel = hiltViewModel()) { | ||||
|     var tikker by remember { mutableStateOf(false) } | ||||
|     LaunchedEffect(tikker) { | ||||
|         delay(1000) | ||||
|         viewModel.getTimer().tick() | ||||
|         tikker = !tikker | ||||
|     } | ||||
| 
 | ||||
|     val hms = viewModel.getTimer().getHoursMinutesSeconds() | ||||
|     Column { | ||||
|         Text( | ||||
|             text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}", | ||||
|             modifier = Modifier.fillMaxWidth(), | ||||
|             textAlign = TextAlign.Center, | ||||
|             fontWeight = FontWeight.Bold, | ||||
|             fontSize = 80.sp | ||||
|         ) | ||||
|         Text( | ||||
|             text = viewModel.getTimer().getViewString(), | ||||
|             modifier = Modifier.fillMaxWidth(), | ||||
|             textAlign = TextAlign.Center, | ||||
|             fontWeight = FontWeight.Light, | ||||
|             fontSize = 30.sp | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|  | @ -1,4 +1,20 @@ | |||
| package be.ugent.sel.studeez.screens.session | ||||
| 
 | ||||
| class SessionViewModel { | ||||
| 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 dagger.hilt.android.lifecycle.HiltViewModel | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| @HiltViewModel | ||||
| class SessionViewModel @Inject constructor( | ||||
|     logService: LogService | ||||
| ) : StudeezViewModel(logService) { | ||||
| 
 | ||||
|     private val timer: FunctionalTimer = FunctionalPomodoroTimer(15, 5, 3) | ||||
| 
 | ||||
|     fun getTimer() : FunctionalTimer { | ||||
|         return timer | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 Lukas Barragan Torres
						Lukas Barragan Torres