#26 select time for custom timer
This commit is contained in:
parent
76e69dd03c
commit
024ce85266
6 changed files with 91 additions and 4 deletions
|
@ -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) {}
|
||||
|
|
|
@ -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<List<TimerInfo>>,
|
||||
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 = {}
|
||||
)
|
||||
}
|
Reference in a new issue