isSession vervangend door null waaarden
This commit is contained in:
		
							parent
							
								
									b30edf6538
								
							
						
					
					
						commit
						f46063eba1
					
				
					 3 changed files with 37 additions and 29 deletions
				
			
		|  | @ -0,0 +1,34 @@ | |||
| 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 var mediaplayer: MediaPlayer? = null | ||||
| 
 | ||||
|     fun setParameters(viewModel: SessionViewModel, mediaplayer: MediaPlayer) { | ||||
|         this.viewModel = viewModel | ||||
|         this.mediaplayer = mediaplayer | ||||
|     } | ||||
| 
 | ||||
|     suspend fun updateTimer() { | ||||
|         if (viewModel != null) { | ||||
|             while (true) { | ||||
|                 delay(1.seconds) | ||||
|                 viewModel!!.getTimer().tick() | ||||
|                 if (viewModel!!.getTimer().hasCurrentCountdownEnded() && !viewModel!!.getTimer().hasEnded()) { | ||||
|                     mediaplayer?.start() | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fun removeParameters() { | ||||
|         viewModel = null | ||||
|         mediaplayer = null | ||||
|     } | ||||
| } | ||||
|  | @ -35,7 +35,6 @@ 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 javax.inject.Singleton | ||||
| import kotlin.time.Duration.Companion.seconds | ||||
| 
 | ||||
| data class SessionActions( | ||||
|  | @ -99,7 +98,7 @@ fun SessionScreen( | |||
|             TextButton( | ||||
|                 onClick = { | ||||
|                     sessionActions.releaseMediaPlayer | ||||
| 
 | ||||
|                     InvisibleSessionManager.removeParameters() | ||||
|                     open(StudeezDestinations.HOME_SCREEN) | ||||
|                     // Vanaf hier ook naar report gaan als "end session" knop word ingedrukt | ||||
|                 }, | ||||
|  | @ -109,7 +108,7 @@ fun SessionScreen( | |||
|                     .background(Color.Transparent) | ||||
|             ) { | ||||
|                 Text( | ||||
|                     text = "End session", | ||||
|                     text = resources().getString(R.string.end_session), | ||||
|                     color = Color.Red, | ||||
|                     fontWeight = FontWeight.Bold, | ||||
|                     fontSize = 18.sp, | ||||
|  | @ -190,32 +189,6 @@ private fun Timer( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @Singleton | ||||
| object InvisibleSessionManager { | ||||
|     private lateinit var viewModel: SessionViewModel | ||||
|     private lateinit var mediaplayer: MediaPlayer | ||||
|     var isSession: Boolean = false | ||||
| 
 | ||||
|     fun setParameters(viewModel: SessionViewModel, mediaplayer: MediaPlayer) { | ||||
|         isSession = true | ||||
|         this.viewModel = viewModel | ||||
|         this.mediaplayer = mediaplayer | ||||
|     } | ||||
| 
 | ||||
|     suspend fun updateTimer() { | ||||
|         if (isSession) { | ||||
|             while (true) { | ||||
|                 delay(1.seconds) | ||||
|                 viewModel.getTimer().tick() | ||||
|                 if (viewModel.getTimer().hasCurrentCountdownEnded() && !viewModel.getTimer().hasEnded()) { | ||||
|                     mediaplayer.start() | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Preview | ||||
| @Composable | ||||
| fun TimerPreview() { | ||||
|  |  | |||
|  | @ -44,6 +44,7 @@ | |||
| 
 | ||||
|     <!-- Sessions --> | ||||
|     <string name="sessions">Sessions</string> | ||||
|     <string name="end_session">End session</string> | ||||
| 
 | ||||
|     <!-- Profile --> | ||||
|     <string name="profile">Profile</string> | ||||
|  |  | |||
		Reference in a new issue
	
	 Rune Dyselinck
						Rune Dyselinck