-
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
1b1ef36
commit a556296
Showing
10 changed files
with
103 additions
and
79 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
48 changes: 48 additions & 0 deletions
48
.../kotlin/xyz/ksharma/krail/trip/planner/ui/state/datetimeselector/DateTimeSelectionItem.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,48 @@ | ||
package xyz.ksharma.krail.trip.planner.ui.state.datetimeselector | ||
|
||
import kotlinx.datetime.LocalDate | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.Json | ||
import xyz.ksharma.krail.core.datetime.toReadableDate | ||
import xyz.ksharma.krail.core.datetime.to12HourTimeString | ||
|
||
@Serializable | ||
data class DateTimeSelectionItem( | ||
val option: JourneyTimeOptions, | ||
val hour: Int, | ||
val minute: Int, | ||
val date: LocalDate, | ||
) { | ||
fun toDateTimeText(): String = when (option) { | ||
JourneyTimeOptions.LEAVE -> { | ||
"Leave: ${toReadableDate(date)} ${to12HourTimeString(hour, minute)}" | ||
} | ||
|
||
JourneyTimeOptions.ARRIVE -> { | ||
"Arrive: ${toReadableDate(date)} ${to12HourTimeString(hour, minute)}" | ||
} | ||
} | ||
|
||
fun toJsonString() = Json.encodeToString(serializer(), this) | ||
|
||
fun toHHMM(): String { | ||
val hh = hour.toString().padStart(2, '0') | ||
val mm = minute.toString().padStart(2, '0') | ||
return "$hh$mm" | ||
} | ||
|
||
fun toYYYYMMDD(): String { | ||
val yyyy = date.year.toString() | ||
val mm = date.monthNumber.toString().padStart(2, '0') | ||
val dd = date.dayOfMonth.toString().padStart(2, '0') | ||
return "$yyyy$mm$dd" | ||
} | ||
|
||
@Suppress("ConstPropertyName") | ||
companion object { | ||
private const val serialVersionUID: Long = 1L | ||
|
||
fun fromJsonString(json: String) = | ||
kotlin.runCatching { Json.decodeFromString(serializer(), json) }.getOrNull() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ain/kotlin/xyz/ksharma/krail/trip/planner/ui/state/datetimeselector/JourneyTimeOptions.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 xyz.ksharma.krail.trip.planner.ui.state.datetimeselector | ||
|
||
enum class JourneyTimeOptions(val text: String) { | ||
LEAVE("Leave"), | ||
ARRIVE("Arrive") | ||
} |
5 changes: 5 additions & 0 deletions
5
...c/commonMain/kotlin/xyz/ksharma/krail/trip/planner/ui/state/timetable/TimeTableUiEvent.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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package xyz.ksharma.krail.trip.planner.ui.state.timetable | ||
|
||
import xyz.ksharma.krail.trip.planner.ui.state.datetimeselector.DateTimeSelectionItem | ||
|
||
sealed interface TimeTableUiEvent { | ||
data object SaveTripButtonClicked : TimeTableUiEvent | ||
data class LoadTimeTable(val trip: Trip) : TimeTableUiEvent | ||
data class JourneyCardClicked(val journeyId: String) : TimeTableUiEvent | ||
data class DateTimeSelectionChanged(val dateTimeSelectionItem: DateTimeSelectionItem?) : | ||
TimeTableUiEvent | ||
|
||
data object ReverseTripButtonClicked : TimeTableUiEvent | ||
data object RetryButtonClicked : TimeTableUiEvent | ||
} |
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
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
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