give soundplayer to visitor
This commit is contained in:
parent
53bdf7d215
commit
346b24aabe
5 changed files with 3 additions and 305 deletions
|
@ -5,32 +5,23 @@ import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
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
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.AbstractSessionScreen
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.GetSessionScreen
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.composables.BreakSessionScreenComposable
|
|
||||||
import be.ugent.sel.studeez.screens.session.sessionScreens.composables.GetSessionScreenComposable
|
import be.ugent.sel.studeez.screens.session.sessionScreens.composables.GetSessionScreenComposable
|
||||||
|
|
||||||
data class SessionActions(
|
data class SessionActions(
|
||||||
val getTimer: () -> FunctionalTimer,
|
val getTimer: () -> FunctionalTimer,
|
||||||
val getTask: () -> String,
|
val getTask: () -> String,
|
||||||
val startMediaPlayer: () -> Unit,
|
|
||||||
val releaseMediaPlayer: () -> Unit,
|
|
||||||
val endSession: () -> Unit
|
val endSession: () -> Unit
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun getSessionActions(
|
private fun getSessionActions(
|
||||||
viewModel: SessionViewModel,
|
viewModel: SessionViewModel,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
openAndPopUp: (String, String) -> Unit,
|
||||||
mediaplayer: MediaPlayer,
|
|
||||||
): SessionActions {
|
): SessionActions {
|
||||||
return SessionActions(
|
return SessionActions(
|
||||||
getTimer = viewModel::getTimer,
|
getTimer = viewModel::getTimer,
|
||||||
getTask = viewModel::getTask,
|
getTask = viewModel::getTask,
|
||||||
endSession = { viewModel.endSession(openAndPopUp) },
|
endSession = { viewModel.endSession(openAndPopUp) },
|
||||||
startMediaPlayer = mediaplayer::start,
|
|
||||||
releaseMediaPlayer = mediaplayer::release,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +41,9 @@ fun SessionRoute(
|
||||||
mediaplayer = mediaplayer
|
mediaplayer = mediaplayer
|
||||||
)
|
)
|
||||||
|
|
||||||
val sessionActions = getSessionActions(viewModel, openAndPopUp, mediaplayer)
|
val soundPlayer = SoundPlayer(LocalContext.current)
|
||||||
val sessionScreen = viewModel.getTimer().accept(GetSessionScreenComposable(mediaplayer, open, sessionActions))
|
val sessionActions = getSessionActions(viewModel, openAndPopUp)
|
||||||
|
val sessionScreen = viewModel.getTimer().accept(GetSessionScreenComposable(soundPlayer, open, sessionActions))
|
||||||
|
|
||||||
sessionScreen()
|
sessionScreen()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,150 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.session.sessionScreens
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.border
|
|
||||||
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
|
|
||||||
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.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
|
|
||||||
import be.ugent.sel.studeez.screens.session.SessionActions
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlin.time.Duration.Companion.seconds
|
|
||||||
|
|
||||||
abstract class AbstractSessionScreen {
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
operator fun invoke(
|
|
||||||
open: (String) -> Unit,
|
|
||||||
sessionActions: SessionActions,
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(10.dp)
|
|
||||||
) {
|
|
||||||
Timer(
|
|
||||||
sessionActions = sessionActions,
|
|
||||||
)
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.Center, modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(50.dp)
|
|
||||||
) {
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
sessionActions.releaseMediaPlayer
|
|
||||||
sessionActions.endSession()
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = 20.dp)
|
|
||||||
.border(1.dp, Color.Red, RoundedCornerShape(32.dp))
|
|
||||||
.background(Color.Transparent)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "End session",
|
|
||||||
color = Color.Red,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
fontSize = 18.sp,
|
|
||||||
modifier = Modifier.padding(1.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Timer(
|
|
||||||
sessionActions: SessionActions,
|
|
||||||
) {
|
|
||||||
var tikker by remember { mutableStateOf(false) }
|
|
||||||
LaunchedEffect(tikker) {
|
|
||||||
delay(1.seconds)
|
|
||||||
sessionActions.getTimer().tick()
|
|
||||||
callMediaPlayer()
|
|
||||||
tikker = !tikker
|
|
||||||
}
|
|
||||||
|
|
||||||
val hms = sessionActions.getTimer().getHoursMinutesSeconds()
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
text = hms.toString(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(50.dp),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
fontSize = 40.sp,
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = motivationString(),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
fontWeight = FontWeight.Light,
|
|
||||||
fontSize = 30.sp
|
|
||||||
)
|
|
||||||
|
|
||||||
MidSection()
|
|
||||||
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.Center, modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(50.dp)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(16.dp)
|
|
||||||
.background(Color.Blue, RoundedCornerShape(32.dp))
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = sessionActions.getTask(),
|
|
||||||
color = Color.White,
|
|
||||||
fontSize = 18.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
modifier = Modifier.padding(vertical = 4.dp, horizontal = 20.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
abstract fun motivationString(): String
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
open fun MidSection() {
|
|
||||||
// Default has no midsection, unless overwritten.
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun callMediaPlayer()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
|
||||||
fun TimerPreview() {
|
|
||||||
val sessionScreen = object : AbstractSessionScreen() {
|
|
||||||
@Composable
|
|
||||||
override fun motivationString(): String = "Test"
|
|
||||||
override fun callMediaPlayer() {}
|
|
||||||
|
|
||||||
}
|
|
||||||
sessionScreen.Timer(sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}, {}))
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.session.sessionScreens
|
|
||||||
|
|
||||||
import android.media.MediaPlayer
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.material.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import be.ugent.sel.studeez.R
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
|
||||||
import be.ugent.sel.studeez.resources
|
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
|
||||||
|
|
||||||
class BreakSessionScreen(
|
|
||||||
private val funPomoDoroTimer: FunctionalPomodoroTimer,
|
|
||||||
private var mediaplayer: MediaPlayer?
|
|
||||||
): AbstractSessionScreen() {
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun MidSection() {
|
|
||||||
Dots()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Dots() {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
) {
|
|
||||||
repeat(funPomoDoroTimer.repeats - funPomoDoroTimer.breaksRemaining) {
|
|
||||||
Dot(color = Color.DarkGray)
|
|
||||||
}
|
|
||||||
if (!funPomoDoroTimer.isInBreak) Dot(Color.Green) else Dot(Color.DarkGray)
|
|
||||||
repeat(funPomoDoroTimer.breaksRemaining - 1) {
|
|
||||||
Dot(color = Color.Gray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun Dot(color: Color) {
|
|
||||||
Box(modifier = Modifier
|
|
||||||
.padding(5.dp)
|
|
||||||
.size(10.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.background(color))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun motivationString(): String {
|
|
||||||
if (funPomoDoroTimer.isInBreak) {
|
|
||||||
return resources().getString(AppText.state_take_a_break)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (funPomoDoroTimer.hasEnded()) {
|
|
||||||
return resources().getString(AppText.state_done)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resources().getString(AppText.state_focus)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun callMediaPlayer() {
|
|
||||||
if (funPomoDoroTimer.hasEnded()) {
|
|
||||||
mediaplayer?.let { it: MediaPlayer ->
|
|
||||||
it.setOnCompletionListener {
|
|
||||||
it.release()
|
|
||||||
mediaplayer = null
|
|
||||||
}
|
|
||||||
it.start()
|
|
||||||
}
|
|
||||||
} else if (funPomoDoroTimer.hasCurrentCountdownEnded()) {
|
|
||||||
mediaplayer?.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
|
||||||
fun MidsectionPreview() {
|
|
||||||
val funPomoDoroTimer = FunctionalPomodoroTimer(15, 60, 5)
|
|
||||||
val breakSessionScreen = BreakSessionScreen(funPomoDoroTimer, MediaPlayer())
|
|
||||||
breakSessionScreen.MidSection()
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.session.sessionScreens
|
|
||||||
|
|
||||||
import android.media.MediaPlayer
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
|
|
||||||
import be.ugent.sel.studeez.resources
|
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
|
||||||
|
|
||||||
|
|
||||||
class CustomSessionScreen(
|
|
||||||
private val functionalTimer: FunctionalCustomTimer,
|
|
||||||
private var mediaplayer: MediaPlayer?
|
|
||||||
): AbstractSessionScreen() {
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun motivationString(): String {
|
|
||||||
if (functionalTimer.hasEnded()) {
|
|
||||||
return resources().getString(AppText.state_done)
|
|
||||||
}
|
|
||||||
return resources().getString(AppText.state_focus)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun callMediaPlayer() {
|
|
||||||
if (functionalTimer.hasEnded()) {
|
|
||||||
mediaplayer?.let { it: MediaPlayer ->
|
|
||||||
it.setOnCompletionListener {
|
|
||||||
it.release()
|
|
||||||
mediaplayer = null
|
|
||||||
}
|
|
||||||
it.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.session.sessionScreens
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import be.ugent.sel.studeez.resources
|
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
|
||||||
|
|
||||||
|
|
||||||
class EndlessSessionScreen : AbstractSessionScreen() {
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun motivationString(): String {
|
|
||||||
return resources().getString(AppText.state_focus)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun callMediaPlayer() {}
|
|
||||||
}
|
|
Reference in a new issue