Skip to content

Commit 09a5301

Browse files
nprycedmcg
authored andcommitted
open-to-sealed.3 : add ItineraryItem.toCalendarEvent()
1 parent c52bee3 commit 09a5301

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package travelator.calendar
2+
3+
import travelator.Id
4+
import travelator.itinerary.*
5+
6+
fun Itinerary.toCalendar() = Calendar(
7+
id = Id.derivedFrom(this.id),
8+
events = mapNotNull { it.toCalendarEvent() }
9+
)
10+
11+
fun ItineraryItem.toCalendarEvent(): CalendarEvent? = when (this) {
12+
is Accommodation -> CalendarEvent(
13+
start = checkInFrom,
14+
end = checkOutBefore,
15+
description = description,
16+
alarms = listOf(
17+
Alarm(checkInFrom, "Check in open"),
18+
Alarm(checkOutBefore.minusHours(1), "Check out")
19+
)
20+
)
21+
is Attraction -> null
22+
is Journey -> CalendarEvent(
23+
start = departureTime,
24+
end = arrivalTime,
25+
description = description,
26+
location = departsFrom,
27+
alarms = listOf(
28+
Alarm(departureTime.minusHours(1)))
29+
)
30+
is RestaurantBooking -> CalendarEvent(
31+
start = time,
32+
description= description,
33+
location = location,
34+
alarms = listOf(
35+
Alarm(time.minusHours(1)))
36+
)
37+
}

src/main/java/travelator/itinerary/ItineraryItem.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ data class Accommodation(
3030

3131
override val description
3232
get() = "$nights nights at ${location.userReadableName}"
33+
3334
override val costs
3435
get() = listOf(totalPrice)
36+
3537
override val mapOverlay
3638
get() = PointOverlay(
3739
id = id,
@@ -49,21 +51,18 @@ data class Attraction(
4951
val notes: String
5052
) : ItineraryItem() {
5153
override val description
52-
get() =
53-
location.userReadableName
54+
get() = location.userReadableName
5455

5556
override val costs
56-
get() =
57-
emptyList<Money>()
57+
get() = emptyList<Money>()
5858

5959
override val mapOverlay
60-
get() =
61-
PointOverlay(
62-
position = location.position,
63-
text = description,
64-
icon = StandardIcons.ATTRACTION,
65-
id = id
66-
)
60+
get() = PointOverlay(
61+
position = location.position,
62+
text = description,
63+
icon = StandardIcons.ATTRACTION,
64+
id = id
65+
)
6766

6867
}
6968

@@ -102,16 +101,17 @@ data class RestaurantBooking(
102101
val location: Location,
103102
val time: ZonedDateTime
104103
) : ItineraryItem() {
105-
override val description get() = location.userReadableName
104+
override val description
105+
get() = location.userReadableName
106106

107-
override val costs get() = emptyList<Money>()
107+
override val costs
108+
get() = emptyList<Money>()
108109

109110
override val mapOverlay
110-
get() =
111-
PointOverlay(
112-
id = id,
113-
position = location.position,
114-
text = location.userReadableName,
115-
icon = StandardIcons.RESTAURANT
116-
)
111+
get() = PointOverlay(
112+
id = id,
113+
position = location.position,
114+
text = location.userReadableName,
115+
icon = StandardIcons.RESTAURANT
116+
)
117117
}

0 commit comments

Comments
 (0)