-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
2,462 additions
and
955 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...java/com/braiso_22/cozycave/date_time_selector/presentation/date_selector/DateSelector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.date_selector | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.braiso_22.cozycave.date_time_selector.presentation.date_selector.comps.DatePickerDialogWrapper | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Composable | ||
fun DateSelector( | ||
state: String, | ||
setState: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val date = try { | ||
LocalDate.parse(state, DateTimeFormatter.ofPattern("dd/MM/yyyy")) | ||
} catch (e: Exception) { | ||
LocalDate.now() | ||
} | ||
|
||
DateSelectorComponent( | ||
date = date, | ||
setDate = { | ||
setState( | ||
it.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) | ||
) | ||
}, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Composable | ||
private fun DateSelectorComponent( | ||
date: LocalDate, | ||
setDate: (LocalDate) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
var isDateOpen by remember { | ||
mutableStateOf(false) | ||
} | ||
DatePickerDialogWrapper( | ||
isVisible = isDateOpen, | ||
setVisible = { isDateOpen = it }, | ||
state = date.toEpochDay().times(86_400_000), | ||
setState = { | ||
setDate( | ||
try { | ||
LocalDate.ofEpochDay(it.div(86_400_000)) | ||
} catch (e: Exception) { | ||
LocalDate.now() | ||
} | ||
) | ||
} | ||
) | ||
Text( | ||
text = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")), | ||
modifier = modifier.clickable { | ||
isDateOpen = true | ||
} | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun DateSelectorPreview() { | ||
DateSelector( | ||
state = "", | ||
setState = {} | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
...2/cozycave/date_time_selector/presentation/date_selector/comps/DatePickerDialogWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.date_selector.comps | ||
|
||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.braiso_22.cozycave.R | ||
import kotlin.math.absoluteValue | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun DatePickerDialogWrapper( | ||
isVisible: Boolean, | ||
setVisible: (Boolean) -> Unit, | ||
state: Long, | ||
setState: (Long) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val datePickerState = rememberDatePickerState( | ||
initialSelectedDateMillis = state | ||
) | ||
|
||
if (isVisible) { | ||
DatePickerDialog( | ||
onDismissRequest = { setVisible(false) }, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { | ||
setVisible(false) | ||
setState(datePickerState.selectedDateMillis?.absoluteValue ?: 0) | ||
} | ||
) { | ||
Text(stringResource(R.string.accept)) | ||
} | ||
|
||
}, | ||
dismissButton = { | ||
TextButton(onClick = { setVisible(false) }) { | ||
Text(stringResource(R.string.cancel)) | ||
} | ||
}, | ||
modifier = modifier | ||
) { | ||
DatePicker(state = datePickerState) | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...java/com/braiso_22/cozycave/date_time_selector/presentation/time_selector/TimeSelector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.time_selector | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.braiso_22.cozycave.date_time_selector.presentation.time_selector.comps.TimePickerDialogWrapper | ||
import java.time.LocalTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Composable | ||
fun TimeSelector( | ||
state: String, | ||
setState: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val time = try { | ||
LocalTime.parse(state) | ||
} catch (e: Exception) { | ||
LocalTime.now() | ||
} | ||
|
||
DateTimeSelectorContent( | ||
time = time, | ||
setTime = { | ||
setState( | ||
it.format(DateTimeFormatter.ofPattern("HH:mm")) | ||
) | ||
}, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Composable | ||
private fun DateTimeSelectorContent( | ||
time: LocalTime, | ||
setTime: (LocalTime) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
var isTimeOpen by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
TimePickerDialogWrapper( | ||
isVisible = isTimeOpen, | ||
setVisible = { isTimeOpen = it }, | ||
state = TimeState(time.hour, time.minute), | ||
setState = { | ||
setTime(LocalTime.of(it.hour, it.minute)) | ||
} | ||
) | ||
|
||
Text( | ||
text = time.format(DateTimeFormatter.ofPattern("HH:mm")), | ||
modifier = modifier.clickable { | ||
isTimeOpen = true | ||
} | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun DateTimeSelectorPreview() { | ||
Surface { | ||
TimeSelector( | ||
state = "", | ||
setState = { | ||
|
||
}, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 8.dp) | ||
) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...in/java/com/braiso_22/cozycave/date_time_selector/presentation/time_selector/TimeState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.time_selector | ||
|
||
data class TimeState( | ||
val hour: Int, | ||
val minute: Int, | ||
) |
91 changes: 91 additions & 0 deletions
91
...raiso_22/cozycave/date_time_selector/presentation/time_selector/comps/TimePickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.time_selector.comps | ||
|
||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Keyboard | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.PreviewScreenSizes | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun TimePickerDialog( | ||
state: TimePickerState, | ||
onDismissRequest: () -> Unit, | ||
confirmButton: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
dismissButton: @Composable (() -> Unit)? = null, | ||
) { | ||
var isTimePicker by remember { | ||
mutableStateOf(true) | ||
} | ||
|
||
Dialog( | ||
onDismissRequest = onDismissRequest, | ||
properties = DialogProperties( | ||
usePlatformDefaultWidth = false, | ||
) | ||
) { | ||
Surface( | ||
shape = MaterialTheme.shapes.extraLarge, | ||
modifier = Modifier | ||
.width(IntrinsicSize.Min) | ||
.height(IntrinsicSize.Min) | ||
.background( | ||
shape = MaterialTheme.shapes.extraLarge, | ||
color = MaterialTheme.colorScheme.surface | ||
) | ||
) { | ||
Column(modifier.padding(8.dp)) { | ||
Text("Select a time", Modifier.padding(8.dp)) | ||
if (isTimePicker) { | ||
TimePicker(state = state) | ||
} else { | ||
TimeInput(state = state) | ||
} | ||
|
||
Row( | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.Bottom, | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
IconButton(onClick = { isTimePicker = !isTimePicker }) { | ||
Icon( | ||
imageVector = Icons.Outlined.Keyboard, | ||
"Change to write mode" | ||
) | ||
} | ||
if (dismissButton != null) { | ||
dismissButton() | ||
} | ||
confirmButton() | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@PreviewScreenSizes | ||
@Composable | ||
private fun TimePickerPreview() { | ||
Box(Modifier.fillMaxSize()) { | ||
TimePickerDialog( | ||
state = rememberTimePickerState(), | ||
onDismissRequest = {}, | ||
confirmButton = { | ||
TextButton(onClick = { /*TODO*/ }) { | ||
Text("Accept") | ||
} | ||
}, | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...2/cozycave/date_time_selector/presentation/time_selector/comps/TimePickerDialogWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.braiso_22.cozycave.date_time_selector.presentation.time_selector.comps | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.material3.rememberTimePickerState | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.braiso_22.cozycave.R | ||
import com.braiso_22.cozycave.date_time_selector.presentation.time_selector.TimeState | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun TimePickerDialogWrapper( | ||
isVisible: Boolean, | ||
setVisible: (Boolean) -> Unit, | ||
state: TimeState, | ||
setState: (TimeState) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val timePickerState = rememberTimePickerState( | ||
is24Hour = true, | ||
initialMinute = state.minute, | ||
initialHour = state.hour, | ||
) | ||
if (isVisible) { | ||
TimePickerDialog( | ||
state = timePickerState, | ||
onDismissRequest = { setVisible(false) }, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { | ||
setVisible(false) | ||
setState( | ||
TimeState(timePickerState.hour, timePickerState.minute) | ||
) | ||
} | ||
) { | ||
Text(stringResource(R.string.accept)) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = { setVisible(false) }) { | ||
Text(stringResource(R.string.cancel)) | ||
} | ||
}, | ||
modifier = modifier | ||
) | ||
} | ||
} |
Oops, something went wrong.