-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
defbe65
commit 7bd900b
Showing
16 changed files
with
596 additions
and
246 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
59 changes: 0 additions & 59 deletions
59
app/src/androidTest/java/fr/antoineverin/worktime/database/TimeSpentDaoTest.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,14 +1,24 @@ | ||
package fr.antoineverin.worktime | ||
|
||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavType | ||
import androidx.navigation.compose.composable | ||
import fr.antoineverin.worktime.ui.screen.AddEntryScreen | ||
import androidx.navigation.navArgument | ||
import fr.antoineverin.worktime.ui.screen.EditEntryScreen | ||
import fr.antoineverin.worktime.ui.screen.ListEntriesScreen | ||
import fr.antoineverin.worktime.ui.screen.MainScreen | ||
|
||
fun NavGraphBuilder.wtAppRoute(appState: WtAppState) { | ||
composable(HOME_ROUTE) { MainScreen({ appState.navigate(it) }) } | ||
composable(ADD_ENTRY) { AddEntryScreen(popUp = { appState.popUp() }) } | ||
composable(LIST_ENTRIES) { ListEntriesScreen({ appState.navigate(it) }) } | ||
composable( | ||
route = "$EDIT_ENTRY/{entryId}", | ||
arguments = listOf(navArgument("entryId") { type = NavType.IntType }) | ||
) { backEntryStack -> | ||
backEntryStack.arguments?.getInt("entryId")?.let { EditEntryScreen(it, { appState.popUp() }) } | ||
} | ||
} | ||
|
||
const val HOME_ROUTE = "home" | ||
const val ADD_ENTRY = "add_entry" | ||
const val LIST_ENTRIES = "entry/list" | ||
const val EDIT_ENTRY = "entry/edit" |
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
93 changes: 93 additions & 0 deletions
93
app/src/main/java/fr/antoineverin/worktime/ui/field/DateField.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,93 @@ | ||
package fr.antoineverin.worktime.ui.field | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusDirection | ||
import androidx.compose.ui.focus.FocusManager | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.unit.dp | ||
import androidx.core.text.isDigitsOnly | ||
import fr.antoineverin.worktime.ui.screen.checkDigitAndRange | ||
import java.time.DateTimeException | ||
import java.time.LocalDate | ||
|
||
|
||
@Composable | ||
fun DateField( | ||
value: DateFieldValue, | ||
onValueChange: (DateFieldValue) -> Unit, | ||
focusManager: FocusManager, | ||
modifier: Modifier = Modifier, | ||
imeAction: ImeAction = ImeAction.Next, | ||
action: () -> Unit = { focusManager.moveFocus(FocusDirection.Next) } | ||
) { | ||
Row( | ||
modifier = modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
NumberField( | ||
label = "Day", | ||
value = value.day, | ||
onValueChange = { onValueChange(value.copy(day = it)) }, | ||
checkValue = { checkDigitAndRange(it, 0..31) }, | ||
focusManager = focusManager, | ||
modifier = Modifier.weight(1f) | ||
) | ||
Spacer(Modifier.width(5.dp)) | ||
NumberField( | ||
label = "Month", | ||
value = value.month, | ||
onValueChange = { onValueChange(value.copy(month = it)) }, | ||
checkValue = { checkDigitAndRange(it, 0..12) }, | ||
focusManager = focusManager, | ||
modifier = Modifier.weight(1f) | ||
) | ||
Spacer(Modifier.width(5.dp)) | ||
NumberField( | ||
label = "Year", | ||
value = value.year, | ||
onValueChange = { onValueChange(value.copy(year = it)) }, | ||
checkValue = { it.isDigitsOnly() }, | ||
focusManager = focusManager, | ||
modifier = Modifier.weight(1f), | ||
imeAction = imeAction, | ||
action = action | ||
) | ||
} | ||
} | ||
|
||
data class DateFieldValue( | ||
val day: String, | ||
val month: String, | ||
val year: String | ||
) { | ||
|
||
fun isValid(): Boolean { | ||
if (!(day.isDigitsOnly() && month.isDigitsOnly() && year.isDigitsOnly())) | ||
return false | ||
if (isEmpty()) | ||
return false | ||
return try { | ||
LocalDate.of(year.toInt(), month.toInt(), day.toInt()) | ||
true | ||
}catch (e: DateTimeException) { | ||
false | ||
} | ||
} | ||
|
||
fun isEmpty(): Boolean { | ||
return day == "" || month == "" || year == "" | ||
} | ||
|
||
fun toLocalDate(): LocalDate { | ||
return LocalDate.of(year.toInt(), month.toInt(), day.toInt()) | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/fr/antoineverin/worktime/ui/field/NumberField.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,49 @@ | ||
package fr.antoineverin.worktime.ui.field | ||
|
||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextField | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusDirection | ||
import androidx.compose.ui.focus.FocusManager | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.text.input.KeyboardType | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun NumberField( | ||
label: String, | ||
value: String, | ||
onValueChange: (String) -> Unit, | ||
checkValue: (String) -> Boolean, | ||
focusManager: FocusManager, | ||
modifier: Modifier = Modifier, | ||
imeAction: ImeAction = ImeAction.Next, | ||
action: () -> Unit = { focusManager.moveFocus(FocusDirection.Next) } | ||
) { | ||
var isError by remember { mutableStateOf(false) } | ||
|
||
TextField( | ||
label = { Text(label) }, | ||
value = value, | ||
onValueChange = { | ||
isError = !checkValue(it) | ||
onValueChange(it) | ||
}, | ||
keyboardOptions = KeyboardOptions( | ||
autoCorrect = false, | ||
keyboardType = KeyboardType.Number, | ||
imeAction = imeAction | ||
), | ||
keyboardActions = KeyboardActions { action() }, | ||
isError = isError, | ||
modifier = modifier | ||
) | ||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/fr/antoineverin/worktime/ui/field/TimeField.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,82 @@ | ||
package fr.antoineverin.worktime.ui.field | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusDirection | ||
import androidx.compose.ui.focus.FocusManager | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.unit.dp | ||
import androidx.core.text.isDigitsOnly | ||
import fr.antoineverin.worktime.ui.screen.checkDigitAndRange | ||
import java.time.DateTimeException | ||
import java.time.LocalTime | ||
|
||
@Composable | ||
fun TimeField( | ||
value: TimeFieldValue, | ||
onValueChange: (TimeFieldValue) -> Unit, | ||
focusManager: FocusManager, | ||
modifier: Modifier = Modifier, | ||
imeAction: ImeAction = ImeAction.Next, | ||
action: () -> Unit = { focusManager.moveFocus(FocusDirection.Next) } | ||
) { | ||
Row( | ||
modifier = modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
NumberField( | ||
label = "Hour", | ||
value = value.hours, | ||
onValueChange = { onValueChange(value.copy(hours = it)) }, | ||
checkValue = { checkDigitAndRange(it, 0..24) }, | ||
focusManager = focusManager, | ||
modifier = Modifier.weight(1f) | ||
) | ||
Spacer(Modifier.width(5.dp)) | ||
NumberField( | ||
label = "Minutes", | ||
value = value.minutes, | ||
onValueChange = { onValueChange(value.copy(minutes = it)) }, | ||
checkValue = { checkDigitAndRange(it, 0..60) }, | ||
focusManager = focusManager, | ||
modifier = Modifier.weight(1f), | ||
imeAction = imeAction, | ||
action = action | ||
) | ||
} | ||
} | ||
|
||
data class TimeFieldValue( | ||
val minutes: String, | ||
val hours: String | ||
) { | ||
|
||
fun isValid(): Boolean { | ||
if (!(minutes.isDigitsOnly() && hours.isDigitsOnly())) | ||
return false | ||
if (isEmpty()) | ||
return false | ||
return try { | ||
LocalTime.of(hours.toInt(), minutes.toInt()) | ||
true | ||
}catch (e: DateTimeException) { | ||
false | ||
} | ||
} | ||
|
||
fun isEmpty(): Boolean { | ||
return minutes == "" || hours == "" | ||
} | ||
|
||
fun toLocalTime(): LocalTime { | ||
return LocalTime.of(hours.toInt(), minutes.toInt()) | ||
} | ||
|
||
} |
Oops, something went wrong.