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.data.local.models.timer_functional.FunctionalTimer.StudyState
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
data class SessionActions(
|
data class SessionActions(
|
||||||
|
@ -99,7 +98,7 @@ fun SessionScreen(
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
sessionActions.releaseMediaPlayer
|
sessionActions.releaseMediaPlayer
|
||||||
|
InvisibleSessionManager.removeParameters()
|
||||||
open(StudeezDestinations.HOME_SCREEN)
|
open(StudeezDestinations.HOME_SCREEN)
|
||||||
// Vanaf hier ook naar report gaan als "end session" knop word ingedrukt
|
// Vanaf hier ook naar report gaan als "end session" knop word ingedrukt
|
||||||
},
|
},
|
||||||
|
@ -109,7 +108,7 @@ fun SessionScreen(
|
||||||
.background(Color.Transparent)
|
.background(Color.Transparent)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "End session",
|
text = resources().getString(R.string.end_session),
|
||||||
color = Color.Red,
|
color = Color.Red,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 18.sp,
|
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
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun TimerPreview() {
|
fun TimerPreview() {
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
<!-- Sessions -->
|
<!-- Sessions -->
|
||||||
<string name="sessions">Sessions</string>
|
<string name="sessions">Sessions</string>
|
||||||
|
<string name="end_session">End session</string>
|
||||||
|
|
||||||
<!-- Profile -->
|
<!-- Profile -->
|
||||||
<string name="profile">Profile</string>
|
<string name="profile">Profile</string>
|
||||||
|
|
Reference in a new issue