#26 select time for custom timer
This commit is contained in:
		
							parent
							
								
									76e69dd03c
								
							
						
					
					
						commit
						024ce85266
					
				
					 6 changed files with 91 additions and 4 deletions
				
			
		|  | @ -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, | ||||
|  |  | |||
|  | @ -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) | ||||
| } | ||||
|  | @ -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) { | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 = {} | ||||
|     ) | ||||
| } | ||||
|  | @ -65,6 +65,7 @@ | |||
|     <string name="timers">Timers</string> | ||||
|     <string name="edit">Edit</string> | ||||
|     <string name="add_timer">Add timer</string> | ||||
|     <string name="pick_time">Select time</string> | ||||
|     <string name="state_focus">Focus!</string> | ||||
|     <plurals name="state_focus_remaining"> | ||||
|         <item quantity="zero">Focus one more time!</item> | ||||
|  | @ -73,6 +74,8 @@ | |||
|     </plurals> | ||||
|     <string name="state_done">Done!</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 --> | ||||
|     <string name="settings">Settings</string> | ||||
|  |  | |||
		Reference in a new issue