-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAlarm.java
More file actions
137 lines (112 loc) · 3.79 KB
/
Alarm.java
File metadata and controls
137 lines (112 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.expoalarmmodule;
import android.os.Build;
import androidx.annotation.RequiresApi;
import com.google.gson.Gson;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import static com.expoalarmmodule.GsonUtil.createSerialize;
public class Alarm implements Cloneable {
String uid;
ZonedDateTime date;
String dateString;
ArrayList<Integer> days;
int hour;
int minutes;
String title;
String description;
boolean repeating;
boolean active;
/**
* Show dismiss button in notification. It is false by default.
*/
boolean showDismiss;
/**
* Show snooze button. It is false by default.
*/
boolean showSnooze;
/**
* Snooze interval in minutes
* Default is 5 minutes
*/
int snoozeInterval;
/**
* Custom texts for buttons of notifications
*/
String dismissText;
String snoozeText;
String sound;
Alarm(String uid, ArrayList<Integer> days, ZonedDateTime date, int hour, int minutes, boolean showDismiss, boolean showSnooze, int snoozeInterval, String title, String description, boolean repeating, boolean active, String dismissText, String snoozeText, String sound) {
this.uid = uid;
this.days = days;
this.hour = hour;
this.minutes = minutes;
this.showDismiss = showDismiss;
this.showSnooze = showSnooze;
this.snoozeInterval = snoozeInterval;
this.title = title;
this.description = description;
this.repeating = repeating;
this.active = active;
this.dismissText = dismissText;
this.snoozeText = snoozeText;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.date = date;
}
this.sound = sound
}
List<Date> getDates() {
List<Date> dates = new ArrayList<>();
if(date != null) {
Calendar triggerDate = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
triggerDate = GregorianCalendar.from(date);
dates.add(triggerDate.getTime());
}
} else if (days != null) {
for (int i = 0; i < days.size(); i++) {
Calendar date = Helper.getDate(days.get(i), hour, minutes);
dates.add(date.getTime());
}
}
return dates;
}
AlarmDates getAlarmDates() {
return new AlarmDates(uid, getDates());
}
@RequiresApi(api = Build.VERSION_CODES.O)
static Alarm fromJson(String json) {
Alarm alarmTemp = createSerialize().fromJson(json, Alarm.class);
alarmTemp.date = ZonedDateTime.parse(alarmTemp.dateString);
return alarmTemp;
}
static String toJson(Alarm alarm) {
alarm.dateString = alarm.date.toString();
return createSerialize().toJson(alarm);
}
public Alarm clone () throws CloneNotSupportedException {
return (Alarm) super.clone();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Alarm)) return false;
Alarm alarm = (Alarm)o;
return (
this.hour == alarm.hour &&
this.minutes == alarm.minutes &&
this.showDismiss == alarm.showDismiss &&
this.showSnooze == alarm.showSnooze &&
this.snoozeInterval == alarm.snoozeInterval &&
this.dismissText == alarm.dismissText &&
this.snoozeText == alarm.snoozeText &&
this.uid.equals(alarm.uid) &&
this.days.equals(alarm.days) &&
this.title.equals(alarm.title) &&
this.description.equals(alarm.description)
);
}
}