From 024ce85266790605b89c91f9ed12107170a6799a Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Sat, 29 Apr 2023 17:55:20 +0200 Subject: [PATCH] #26 select time for custom timer --- .../common/composable/ButtonComposable.kt | 23 ++++++++- .../ugent/sel/studeez/common/ext/ShapeExt.kt | 8 +++ .../models/timer_info/CustomTimerInfo.kt | 2 +- .../timer_overview/TimerOverviewScreen.kt | 9 ++++ .../timer_selection/TimerSelectionScreen.kt | 50 ++++++++++++++++++- app/src/main/res/values/strings.xml | 3 ++ 6 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/be/ugent/sel/studeez/common/ext/ShapeExt.kt diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt index 3fa9bd2..9751750 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt @@ -2,7 +2,6 @@ package be.ugent.sel.studeez.common.composable import androidx.annotation.StringRes import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.* import androidx.compose.runtime.Composable 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.common.ext.basicButton import be.ugent.sel.studeez.common.ext.card +import be.ugent.sel.studeez.common.ext.defaultButtonShape @Composable fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) { @@ -30,7 +30,7 @@ fun BasicButton( Button( onClick = onClick, modifier = modifier, - shape = RoundedCornerShape(20.dp), + shape = defaultButtonShape(), colors = colors, border = border, ) { @@ -47,6 +47,25 @@ fun BasicButtonPreview() { 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 fun StealthButton( @StringRes text: Int, diff --git a/app/src/main/java/be/ugent/sel/studeez/common/ext/ShapeExt.kt b/app/src/main/java/be/ugent/sel/studeez/common/ext/ShapeExt.kt new file mode 100644 index 0000000..2114a74 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/common/ext/ShapeExt.kt @@ -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) +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt index 5e06536..d33ecc4 100644 --- a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt @@ -6,7 +6,7 @@ import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer class CustomTimerInfo( name: String, description: String, - private val studyTime: Int, + var studyTime: Int, id: String = "" ): TimerInfo(id, name, description) { diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt index 9489a30..d6d7b07 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -61,6 +61,15 @@ fun TimerOverviewScreen( ) { Column { 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 items(timerOverviewActions.getDefaultTimers()) { TimerEntry(timerInfo = it) {} diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index ac46b5c..2f8fcac 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -1,22 +1,29 @@ 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.items import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview 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.StealthButton 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.resources import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf +import java.util.* data class TimerSelectionActions( val getAllTimers: () -> Flow>, val startSession: (TimerInfo) -> Unit, + val pickDuration: (Context, CustomTimerInfo) -> Unit ) fun getTimerSelectionActions( @@ -26,6 +33,21 @@ fun getTimerSelectionActions( return TimerSelectionActions( getAllTimers = viewModel::getAllTimers, 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 ) { 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 items(timers.value) { timerInfo -> TimerEntry( @@ -72,7 +120,7 @@ fun TimerSelectionScreen( @Composable fun TimerSelectionPreview() { TimerSelectionScreen( - timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), + timerSelectionActions = TimerSelectionActions({ flowOf() }, {}, { _, _ -> {}}), popUp = {} ) } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb643d3..1876cee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,6 +65,7 @@ Timers Edit Add timer + Select time Focus! Focus one more time! @@ -73,6 +74,8 @@ Done! Take a break! + Custom + Select how long you want to study Settings