#26 Show selected time
This commit is contained in:
		
							parent
							
								
									024ce85266
								
							
						
					
					
						commit
						3bf0157adc
					
				
					 2 changed files with 48 additions and 36 deletions
				
			
		|  | @ -18,12 +18,12 @@ 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 |     val pickDuration: (Context) -> Unit, | ||||||
|  |     val customTimeStudyTime: Int | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| fun getTimerSelectionActions( | fun getTimerSelectionActions( | ||||||
|  | @ -33,21 +33,20 @@ 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 -> |         pickDuration = { context -> | ||||||
|             val mCalendar = Calendar.getInstance() |             val dialog = TimePickerDialog( | ||||||
|             val mHour = mCalendar[Calendar.HOUR] |  | ||||||
|             val mMinute = mCalendar[Calendar.MINUTE] |  | ||||||
| 
 |  | ||||||
|             val mTimePickerDialog = TimePickerDialog( |  | ||||||
|                 context, |                 context, | ||||||
|                 { _, hour : Int, minute: Int -> timerInfo.studyTime = hour * 60 * 60 + minute * 60 }, |                 { _, hour: Int, minute: Int -> | ||||||
|                 mHour, |                     viewModel.customTimerStudyTime.value = hour * 60 * 60 + minute * 60 | ||||||
|                 mMinute, |                 }, | ||||||
|  |                 0, | ||||||
|  |                 0, | ||||||
|                 true |                 true | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             mTimePickerDialog.show() |             dialog.show() | ||||||
|         } |         }, | ||||||
|  |         customTimeStudyTime = viewModel.customTimerStudyTime.value | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -76,28 +75,7 @@ fun TimerSelectionScreen( | ||||||
|         LazyColumn { |         LazyColumn { | ||||||
|             // Custom timer with duration selection button |             // Custom timer with duration selection button | ||||||
|             item { |             item { | ||||||
|                 val timerInfo = CustomTimerInfo( |                 CustomTimerEntry(timerSelectionActions) | ||||||
|                     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 | ||||||
|  | @ -116,11 +94,39 @@ fun TimerSelectionScreen( | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @Composable | ||||||
|  | fun CustomTimerEntry( | ||||||
|  |     timerSelectionActions: TimerSelectionActions | ||||||
|  | ) { | ||||||
|  |     val timerInfo = CustomTimerInfo( | ||||||
|  |         name = resources().getString(R.string.custom_name), | ||||||
|  |         description = resources().getString(R.string.custom_description), | ||||||
|  |         studyTime = timerSelectionActions.customTimeStudyTime | ||||||
|  |     ) | ||||||
|  |     val context = LocalContext.current | ||||||
|  | 
 | ||||||
|  |     TimerEntry( | ||||||
|  |         timerInfo = timerInfo, | ||||||
|  |         leftButton = { | ||||||
|  |             StealthButton( | ||||||
|  |                 text = R.string.start, | ||||||
|  |                 onClick = { timerSelectionActions.startSession(timerInfo) } | ||||||
|  |             ) | ||||||
|  |         }, | ||||||
|  |         rightButton = { | ||||||
|  |             NotInternationalisedButton( | ||||||
|  |                 text = String.format("%02d:%02d", timerInfo.studyTime / 3600, (timerInfo.studyTime % 3600) / 60), | ||||||
|  |                 onClick = { timerSelectionActions.pickDuration(context) } | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| @Preview | @Preview | ||||||
| @Composable | @Composable | ||||||
| fun TimerSelectionPreview() { | fun TimerSelectionPreview() { | ||||||
|     TimerSelectionScreen( |     TimerSelectionScreen( | ||||||
|         timerSelectionActions = TimerSelectionActions({ flowOf() }, {}, { _, _ -> {}}), |         timerSelectionActions = TimerSelectionActions({ flowOf() }, {}, { {} }, 0), | ||||||
|         popUp = {} |         popUp = {} | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
|  | @ -1,5 +1,9 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_selection | package be.ugent.sel.studeez.screens.timer_selection | ||||||
| 
 | 
 | ||||||
|  | import androidx.compose.runtime.MutableState | ||||||
|  | import androidx.compose.runtime.getValue | ||||||
|  | import androidx.compose.runtime.mutableStateOf | ||||||
|  | import androidx.compose.runtime.remember | ||||||
| import be.ugent.sel.studeez.data.SelectedTimerState | import be.ugent.sel.studeez.data.SelectedTimerState | ||||||
| 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.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
|  | @ -17,6 +21,8 @@ class TimerSelectionViewModel @Inject constructor( | ||||||
|     logService: LogService |     logService: LogService | ||||||
| ) : StudeezViewModel(logService) { | ) : StudeezViewModel(logService) { | ||||||
| 
 | 
 | ||||||
|  |     var customTimerStudyTime: MutableState<Int> = mutableStateOf(0) | ||||||
|  | 
 | ||||||
|     fun getAllTimers() : Flow<List<TimerInfo>> { |     fun getAllTimers() : Flow<List<TimerInfo>> { | ||||||
|         return timerDAO.getAllTimers() |         return timerDAO.getAllTimers() | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Reference in a new issue