#26 select time for custom timer

This commit is contained in:
Tibo De Peuter 2023-04-29 17:55:20 +02:00
parent 76e69dd03c
commit 024ce85266
6 changed files with 91 additions and 4 deletions

View file

@ -2,7 +2,6 @@ package be.ugent.sel.studeez.common.composable
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -13,6 +12,7 @@ import androidx.compose.ui.unit.sp
import be.ugent.sel.studeez.R import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.common.ext.card import be.ugent.sel.studeez.common.ext.card
import be.ugent.sel.studeez.common.ext.defaultButtonShape
@Composable @Composable
fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) { fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) {
@ -30,7 +30,7 @@ fun BasicButton(
Button( Button(
onClick = onClick, onClick = onClick,
modifier = modifier, modifier = modifier,
shape = RoundedCornerShape(20.dp), shape = defaultButtonShape(),
colors = colors, colors = colors,
border = border, border = border,
) { ) {
@ -47,6 +47,25 @@ fun BasicButtonPreview() {
BasicButton(text = R.string.add_timer, modifier = Modifier.basicButton()) {} BasicButton(text = R.string.add_timer, modifier = Modifier.basicButton()) {}
} }
@Composable
fun NotInternationalisedButton(
text: String,
modifier: Modifier = Modifier,
colors: ButtonColors = ButtonDefaults.buttonColors(),
border: BorderStroke? = null,
onClick: () -> Unit
) {
Button(
onClick = onClick,
modifier = modifier,
shape = defaultButtonShape(),
colors = colors,
border = border
) {
Text(text = text)
}
}
@Composable @Composable
fun StealthButton( fun StealthButton(
@StringRes text: Int, @StringRes text: Int,

View file

@ -0,0 +1,8 @@
package be.ugent.sel.studeez.common.ext
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.unit.dp
fun defaultButtonShape(): RoundedCornerShape {
return RoundedCornerShape(20.dp)
}

View file

@ -6,7 +6,7 @@ import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
class CustomTimerInfo( class CustomTimerInfo(
name: String, name: String,
description: String, description: String,
private val studyTime: Int, var studyTime: Int,
id: String = "" id: String = ""
): TimerInfo(id, name, description) { ): TimerInfo(id, name, description) {

View file

@ -61,6 +61,15 @@ fun TimerOverviewScreen(
) { ) {
Column { Column {
LazyColumn { LazyColumn {
// Custom timer, select new duration each time
item {
TimerEntry(timerInfo = CustomTimerInfo(
name = resources().getString(R.string.custom_name),
description = resources().getString(R.string.custom_name),
studyTime = 0
))
}
// Default Timers, cannot be edited // Default Timers, cannot be edited
items(timerOverviewActions.getDefaultTimers()) { items(timerOverviewActions.getDefaultTimers()) {
TimerEntry(timerInfo = it) {} TimerEntry(timerInfo = it) {}

View file

@ -1,22 +1,29 @@
package be.ugent.sel.studeez.screens.timer_selection package be.ugent.sel.studeez.screens.timer_selection
import android.app.TimePickerDialog
import android.content.Context
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import be.ugent.sel.studeez.R import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.composable.NotInternationalisedButton
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
import be.ugent.sel.studeez.common.composable.StealthButton import be.ugent.sel.studeez.common.composable.StealthButton
import be.ugent.sel.studeez.common.composable.TimerEntry import be.ugent.sel.studeez.common.composable.TimerEntry
import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.resources
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import java.util.*
data class TimerSelectionActions( data class TimerSelectionActions(
val getAllTimers: () -> Flow<List<TimerInfo>>, val getAllTimers: () -> Flow<List<TimerInfo>>,
val startSession: (TimerInfo) -> Unit, val startSession: (TimerInfo) -> Unit,
val pickDuration: (Context, CustomTimerInfo) -> Unit
) )
fun getTimerSelectionActions( fun getTimerSelectionActions(
@ -26,6 +33,21 @@ fun getTimerSelectionActions(
return TimerSelectionActions( return TimerSelectionActions(
getAllTimers = viewModel::getAllTimers, getAllTimers = viewModel::getAllTimers,
startSession = { viewModel.startSession(open, it) }, startSession = { viewModel.startSession(open, it) },
pickDuration = { context, timerInfo ->
val mCalendar = Calendar.getInstance()
val mHour = mCalendar[Calendar.HOUR]
val mMinute = mCalendar[Calendar.MINUTE]
val mTimePickerDialog = TimePickerDialog(
context,
{ _, hour : Int, minute: Int -> timerInfo.studyTime = hour * 60 * 60 + minute * 60 },
mHour,
mMinute,
true
)
mTimePickerDialog.show()
}
) )
} }
@ -52,6 +74,32 @@ fun TimerSelectionScreen(
popUp = popUp popUp = popUp
) { ) {
LazyColumn { LazyColumn {
// Custom timer with duration selection button
item {
val timerInfo = CustomTimerInfo(
name = resources().getString(R.string.custom_name),
description = resources().getString(R.string.custom_name),
studyTime = 0
)
val context = LocalContext.current
TimerEntry(
timerInfo = timerInfo,
leftButton = {
StealthButton(
text = R.string.start,
onClick = { timerSelectionActions.startSession(timerInfo) }
)
},
rightButton = {
NotInternationalisedButton(
text = resources().getString(R.string.pick_time),
onClick = { timerSelectionActions.pickDuration(context, timerInfo) }
)
}
)
}
// All timers // All timers
items(timers.value) { timerInfo -> items(timers.value) { timerInfo ->
TimerEntry( TimerEntry(
@ -72,7 +120,7 @@ fun TimerSelectionScreen(
@Composable @Composable
fun TimerSelectionPreview() { fun TimerSelectionPreview() {
TimerSelectionScreen( TimerSelectionScreen(
timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), timerSelectionActions = TimerSelectionActions({ flowOf() }, {}, { _, _ -> {}}),
popUp = {} popUp = {}
) )
} }

View file

@ -65,6 +65,7 @@
<string name="timers">Timers</string> <string name="timers">Timers</string>
<string name="edit">Edit</string> <string name="edit">Edit</string>
<string name="add_timer">Add timer</string> <string name="add_timer">Add timer</string>
<string name="pick_time">Select time</string>
<string name="state_focus">Focus!</string> <string name="state_focus">Focus!</string>
<plurals name="state_focus_remaining"> <plurals name="state_focus_remaining">
<item quantity="zero">Focus one more time!</item> <item quantity="zero">Focus one more time!</item>
@ -73,6 +74,8 @@
</plurals> </plurals>
<string name="state_done">Done!</string> <string name="state_done">Done!</string>
<string name="state_take_a_break">Take a break!</string> <string name="state_take_a_break">Take a break!</string>
<string name="custom_name">Custom</string>
<string name="custom_description">Select how long you want to study</string>
<!-- Settings --> <!-- Settings -->
<string name="settings">Settings</string> <string name="settings">Settings</string>