Timer speelt notificatie bij het start en einde van een pauze
This commit is contained in:
		
							parent
							
								
									2071b31f72
								
							
						
					
					
						commit
						18d11ffbbd
					
				
					 3 changed files with 38 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -16,4 +16,7 @@ abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		|||
 | 
			
		||||
    abstract fun hasEnded(): Boolean
 | 
			
		||||
 | 
			
		||||
    fun hasCurrentCountdownEnded(): Boolean {
 | 
			
		||||
        return time.getTime() == 0
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +1,14 @@
 | 
			
		|||
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.*
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -10,6 +16,7 @@ import androidx.compose.runtime.*
 | 
			
		|||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -20,13 +27,15 @@ import be.ugent.sel.studeez.domain.implementation.LogServiceImpl
 | 
			
		|||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import kotlinx.coroutines.delay
 | 
			
		||||
 | 
			
		||||
var timerEnd = false
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun SessionScreen(
 | 
			
		||||
    open: (String) -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: SessionViewModel = hiltViewModel()
 | 
			
		||||
) {
 | 
			
		||||
   Column(
 | 
			
		||||
    Column(
 | 
			
		||||
       modifier = Modifier.padding(10.dp)
 | 
			
		||||
   ) {
 | 
			
		||||
        Timer(viewModel)
 | 
			
		||||
| 
						 | 
				
			
			@ -65,6 +74,25 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
 | 
			
		|||
        tikker = !tikker
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
 | 
			
		||||
    val mediaplayer = MediaPlayer.create(context, uri)
 | 
			
		||||
    mediaplayer.setOnCompletionListener {
 | 
			
		||||
        mediaplayer.stop()
 | 
			
		||||
        if (timerEnd) {
 | 
			
		||||
            mediaplayer.release()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (viewModel.getTimer().hasCurrentCountdownEnded() && !viewModel.getTimer().hasEnded()) {
 | 
			
		||||
        mediaplayer.start()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!timerEnd && viewModel.getTimer().hasEnded()) {
 | 
			
		||||
        mediaplayer.start()
 | 
			
		||||
        timerEnd = true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val hms = viewModel.getTimer().getHoursMinutesSeconds()
 | 
			
		||||
    Column {
 | 
			
		||||
        Text(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue