• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.Objects;
24 
25 import javax.annotation.Nullable;
26 
27 /**
28  * An immutable value representing a calendar event. Should contain only details that are relevant
29  * to the Car Calendar.
30  */
31 public final class Event {
32 
33     /** The status of the current user for this event. */
34     public enum Status {
35         ACCEPTED,
36         DECLINED,
37         NONE,
38     }
39 
40     /** The details required for display of the calendar indicator. */
41     public static class CalendarDetails {
42         private final String mName;
43         private final int mColor;
44 
CalendarDetails(String name, int color)45         CalendarDetails(String name, int color) {
46             mName = name;
47             mColor = color;
48         }
49 
getColor()50         public int getColor() {
51             return mColor;
52         }
53 
getName()54         public String getName() {
55             return mName;
56         }
57 
58         @Override
equals(Object o)59         public boolean equals(Object o) {
60             if (this == o) return true;
61             if (o == null || getClass() != o.getClass()) return false;
62             CalendarDetails that = (CalendarDetails) o;
63             return mColor == that.mColor && mName.equals(that.mName);
64         }
65 
66         @Override
hashCode()67         public int hashCode() {
68             return Objects.hash(mName, mColor);
69         }
70     }
71 
72     private final boolean mAllDay;
73     private final Instant mStartInstant;
74     private final Instant mDayStartInstant;
75     private final Instant mEndInstant;
76     private final Instant mDayEndInstant;
77     private final String mTitle;
78     private final Status mStatus;
79     @Nullable private final String mLocation;
80     @Nullable private final NumberAndAccess mNumberAndAccess;
81     private final CalendarDetails mCalendarDetails;
82 
Event( boolean allDay, Instant startInstant, Instant dayStartInstant, Instant endInstant, Instant dayEndInstant, String title, Status status, @Nullable String location, @Nullable NumberAndAccess numberAndAccess, CalendarDetails calendarDetails)83     Event(
84             boolean allDay,
85             Instant startInstant,
86             Instant dayStartInstant,
87             Instant endInstant,
88             Instant dayEndInstant,
89             String title,
90             Status status,
91             @Nullable String location,
92             @Nullable NumberAndAccess numberAndAccess,
93             CalendarDetails calendarDetails) {
94         mAllDay = allDay;
95         mStartInstant = startInstant;
96         mDayStartInstant = dayStartInstant;
97         mEndInstant = endInstant;
98         mDayEndInstant = dayEndInstant;
99         mTitle = title;
100         mStatus = status;
101         mLocation = location;
102         mNumberAndAccess = numberAndAccess;
103         mCalendarDetails = calendarDetails;
104     }
105 
getStartInstant()106     public Instant getStartInstant() {
107         return mStartInstant;
108     }
109 
getDayStartInstant()110     public Instant getDayStartInstant() {
111         return mDayStartInstant;
112     }
113 
getDayEndInstant()114     public Instant getDayEndInstant() {
115         return mDayEndInstant;
116     }
117 
getEndInstant()118     public Instant getEndInstant() {
119         return mEndInstant;
120     }
121 
getTitle()122     public String getTitle() {
123         return mTitle;
124     }
125 
126     @Nullable
getNumberAndAccess()127     public NumberAndAccess getNumberAndAccess() {
128         return mNumberAndAccess;
129     }
130 
getCalendarDetails()131     public CalendarDetails getCalendarDetails() {
132         return mCalendarDetails;
133     }
134 
135     @Nullable
getLocation()136     public String getLocation() {
137         return mLocation;
138     }
139 
getStatus()140     public Status getStatus() {
141         return mStatus;
142     }
143 
isAllDay()144     public boolean isAllDay() {
145         return mAllDay;
146     }
147 
getDuration()148     public Duration getDuration() {
149         return Duration.between(getStartInstant(), getEndInstant());
150     }
151 
152     @Override
equals(Object o)153     public boolean equals(Object o) {
154         if (this == o) return true;
155         if (o == null || getClass() != o.getClass()) return false;
156         Event event = (Event) o;
157         return mAllDay == event.mAllDay
158                 && mStartInstant.equals(event.mStartInstant)
159                 && mDayStartInstant.equals(event.mDayStartInstant)
160                 && mEndInstant.equals(event.mEndInstant)
161                 && mDayEndInstant.equals(event.mDayEndInstant)
162                 && mTitle.equals(event.mTitle)
163                 && mStatus == event.mStatus
164                 && Objects.equals(mLocation, event.mLocation)
165                 && Objects.equals(mNumberAndAccess, event.mNumberAndAccess)
166                 && mCalendarDetails.equals(event.mCalendarDetails);
167     }
168 
169     @Override
hashCode()170     public int hashCode() {
171         return Objects.hash(
172                 mAllDay,
173                 mStartInstant,
174                 mDayStartInstant,
175                 mEndInstant,
176                 mDayEndInstant,
177                 mTitle,
178                 mStatus,
179                 mLocation,
180                 mNumberAndAccess,
181                 mCalendarDetails);
182     }
183 }
184