1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.calendar.common;
18 
19 import com.android.car.calendar.common.Dialer.NumberAndAccess;
20 
21 import java.time.Duration;
22 import java.time.Instant;
23 
24 /**
25  * An immutable value representing a calendar event. Should contain only details that are relevant
26  * to the Car Calendar.
27  */
28 public final class Event {
29 
30     /** The status of the current user for this event. */
31     public enum Status {
32         ACCEPTED,
33         DECLINED,
34         NONE,
35     }
36 
37     /**
38      * The details required for display of the calendar indicator.
39      */
40     public static class CalendarDetails {
41         private final String mName;
42         private final int mColor;
43 
CalendarDetails(String name, int color)44         CalendarDetails(String name, int color) {
45             mName = name;
46             mColor = color;
47         }
48 
getColor()49         public int getColor() {
50             return mColor;
51         }
52 
getName()53         public String getName() {
54             return mName;
55         }
56     }
57 
58     private final boolean mAllDay;
59     private final Instant mStartInstant;
60     private final Instant mDayStartInstant;
61     private final Instant mEndInstant;
62     private final Instant mDayEndInstant;
63     private final String mTitle;
64     private final Status mStatus;
65     private final String mLocation;
66     private final NumberAndAccess mNumberAndAccess;
67     private final CalendarDetails mCalendarDetails;
68 
Event( boolean allDay, Instant startInstant, Instant dayStartInstant, Instant endInstant, Instant dayEndInstant, String title, Status status, String location, NumberAndAccess numberAndAccess, CalendarDetails calendarDetails)69     Event(
70             boolean allDay,
71             Instant startInstant,
72             Instant dayStartInstant,
73             Instant endInstant,
74             Instant dayEndInstant,
75             String title,
76             Status status,
77             String location,
78             NumberAndAccess numberAndAccess,
79             CalendarDetails calendarDetails) {
80         mAllDay = allDay;
81         mStartInstant = startInstant;
82         mDayStartInstant = dayStartInstant;
83         mEndInstant = endInstant;
84         mDayEndInstant = dayEndInstant;
85         mTitle = title;
86         mStatus = status;
87         mLocation = location;
88         mNumberAndAccess = numberAndAccess;
89         mCalendarDetails = calendarDetails;
90     }
91 
getStartInstant()92     public Instant getStartInstant() {
93         return mStartInstant;
94     }
95 
getDayStartInstant()96     public Instant getDayStartInstant() {
97         return mDayStartInstant;
98     }
99 
getDayEndInstant()100     public Instant getDayEndInstant() {
101         return mDayEndInstant;
102     }
103 
getEndInstant()104     public Instant getEndInstant() {
105         return mEndInstant;
106     }
107 
getTitle()108     public String getTitle() {
109         return mTitle;
110     }
111 
getNumberAndAccess()112     public NumberAndAccess getNumberAndAccess() {
113         return mNumberAndAccess;
114     }
115 
getCalendarDetails()116     public CalendarDetails getCalendarDetails() {
117         return mCalendarDetails;
118     }
119 
getLocation()120     public String getLocation() {
121         return mLocation;
122     }
123 
getStatus()124     public Status getStatus() {
125         return mStatus;
126     }
127 
isAllDay()128     public boolean isAllDay() {
129         return mAllDay;
130     }
131 
getDuration()132     public Duration getDuration() {
133         return Duration.between(getStartInstant(), getEndInstant());
134     }
135 }
136