Skip to content

Commit 65c1af8

Browse files
committed
android modifications
modified repeat alarm feature, delete repeating alarm added, can add volume to alarm independent of phone settings
1 parent a846270 commit 65c1af8

File tree

9 files changed

+140
-47
lines changed

9 files changed

+140
-47
lines changed

.github/stale.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Number of days of inactivity before an issue becomes stale
2-
daysUntilStale: 80
2+
daysUntilStale: 60
33
# Number of days of inactivity before a stale issue is closed
4-
daysUntilClose: 7
4+
daysUntilClose: 14
55
# Issues with these labels will never be considered stale
66
exemptLabels:
77
- pinned

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ project.xcworkspace
3333
build/
3434
.idea
3535
.gradle
36+
gradle/
37+
gradle*
3638
local.properties
3739
*.iml
3840

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ In your `AndroidManifest.xml`
116116
| **`loop_sound`** | Play sound continuously until you decide to stop it. `[boolean]` | `false` |
117117
| **`message`** | **Required:** Add Notification message. | `"My Notification Message"` |
118118
| **`play_sound`** | Play alarm notification sound. `[boolean]` | `true` |
119-
| **`repeat_interval`** | Interval set to repeat alarm if schedule_type is "repeat". `[number]` in minutes | `1` |
120119
| **`schedule_type`** | **Required:** Type of alarm schedule. `"once"` (to show alarm once) or `"repeat"` (to display alarm after set repeat_interval) | `"once"` |
120+
| **`repeat_interval`** | Interval set to repeat alarm if schedule_type is "repeat". `[minutely, hourly, daily, weekly]` | `"hourly"` |
121+
| **`interval_value`** | Set interval_value if repeat_interval is minutely and hourly. `[number]` | `1` |
121122
| **`small_icon`** | **Required:** Set the small icon resource, which will be used to represent the notification in the status bar. eg `"ic_launcher"`. PS: make sure to add the file in your mipmap folders `[project_root]/android/app/src/main/res/mipmap*` | `"ic_launcher"` |
122123
| **`snooze_interval`** | Interval set to show alarm after snooze button is tapped. `[number]` in minutes | `1` |
123124
| **`sound_name`** | Set audio file to play when alarm is triggered. example `"sound_name.mp3"` or `"sound_name"`. PS: make sure to add the file in your res/raw folder `[project_root]/android/app/src/main/res/raw` | _None_ |
@@ -128,6 +129,8 @@ In your `AndroidManifest.xml`
128129
| **`vibrate`** | Set vibration when alarm is triggered. `[boolean]` | `true` |
129130
| **`vibration`** | Set number of milliseconds to vibrate. `[number]` | `100` |
130131
| **`use_big_text (Android only)`** | Set notification message style as big text. `[boolean]` | `false` |
132+
| **`volume`** | Set volume. `[number between 0.0 and 1.0]` | `0.5` |
133+
| **`bypass_dnd (Android only)`** | Sets whether or not notifications posted to this channel can interrupt the user | `false` |
131134

132135
## Usage
133136

@@ -162,7 +165,7 @@ class App extends Component {
162165
ReactNativeAN.deleteAlarm(alarm.id);
163166

164167
//Delete Repeating Alarm
165-
ReactNativeAN.deleteRepeatingAlarm();
168+
ReactNativeAN.deleteRepeatingAlarm(alarm.id);
166169

167170
//Stop Alarm
168171
ReactNativeAN.stopAlarmSound();

android/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
//noinspection GradleDynamicVersion
7575
implementation 'com.facebook.react:react-native:+' // From node_modules
7676
implementation 'com.google.code.gson:gson:2.8.6'
77+
implementation 'androidx.appcompat:appcompat:1.1.0'
7778
}
7879

7980
def configureReactNativePom(def pom) {

android/src/main/java/com/emekalites/react/alarm/notification/ANModule.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.app.Application;
44
import android.os.Bundle;
5-
import android.util.Log;
65

76
import com.facebook.react.bridge.Arguments;
87
import com.facebook.react.bridge.Promise;
@@ -68,7 +67,7 @@ public void scheduleAlarm(ReadableMap details, Promise promise) throws ParseExce
6867
Bundle data = bundle.getBundle("data");
6968
alarm.setData(bundle2string(data));
7069

71-
alarm.setInterval((int)bundle.getDouble("repeat_interval", 1.0));
70+
alarm.setInterval(bundle.getString("repeat_interval", "hourly"));
7271
alarm.setLargeIcon(bundle.getString("large_icon", ""));
7372
alarm.setLoopSound(bundle.getBoolean("loop_sound", false));
7473
alarm.setMessage(bundle.getString("message", "My Notification Message"));
@@ -85,6 +84,9 @@ public void scheduleAlarm(ReadableMap details, Promise promise) throws ParseExce
8584
alarm.setHasButton(bundle.getBoolean("has_button", false));
8685
alarm.setVibration((int)bundle.getDouble("vibration", 100.0));
8786
alarm.setUseBigText(bundle.getBoolean("use_big_text", false));
87+
alarm.setVolume(bundle.getDouble("volume", 0.5));
88+
alarm.setIntervalValue((int)bundle.getDouble("interval_value", 1));
89+
alarm.setBypassDnd(bundle.getBoolean("bypass_dnd", false));
8890

8991
String datetime = bundle.getString("fire_date");
9092
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH);
@@ -149,12 +151,10 @@ public void sendNotification(ReadableMap details) throws ParseException {
149151
Bundle data = bundle.getBundle("data");
150152
alarm.setData(bundle2string(data));
151153

152-
alarm.setInterval((int)bundle.getDouble("repeat_interval", 1));
153154
alarm.setLargeIcon(bundle.getString("large_icon"));
154155
alarm.setLoopSound(bundle.getBoolean("loop_sound", false));
155156
alarm.setMessage(bundle.getString("message", "My Notification Message"));
156157
alarm.setPlaySound(bundle.getBoolean("play_sound", true));
157-
alarm.setScheduleType(bundle.getString("schedule_type", "once"));
158158
alarm.setSmallIcon(bundle.getString("small_icon", "ic_launcher"));
159159
alarm.setSnoozeInterval((int)bundle.getDouble("snooze_interval", 1));
160160
alarm.setSoundName(bundle.getString("sound_name"));
@@ -166,8 +166,9 @@ public void sendNotification(ReadableMap details) throws ParseException {
166166
alarm.setHasButton(bundle.getBoolean("has_button", false));
167167
alarm.setVibration((int)bundle.getDouble("vibration", 100));
168168
alarm.setUseBigText(bundle.getBoolean("use_big_text", false));
169+
alarm.setVolume(bundle.getDouble("volume", 0.5));
170+
alarm.setBypassDnd(bundle.getBoolean("bypass_dnd", false));
169171

170-
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH);
171172
Calendar calendar = new GregorianCalendar();
172173

173174
alarmUtil.setAlarmFromCalendar(alarm, calendar);

android/src/main/java/com/emekalites/react/alarm/notification/AlarmModel.java

+37-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ public class AlarmModel implements Serializable {
2828
private String soundNames; // separate sounds with comma eg (sound1.mp3,sound2.mp3)
2929
private String color = "red";
3030
private String scheduleType = "once"; // once or repeat
31-
private int interval = 1; // in minutes
31+
private String interval = "hourly"; // hourly, daily, weekly
32+
private int intervalValue = 1;
3233
private int snoozeInterval = 1; // in minutes
3334
private String tag;
3435
private String data;
3536
private boolean loopSound = false;
3637
private boolean useBigText = false;
3738
private boolean hasButton = false;
39+
private double volume = 0.5;
40+
private boolean bypassDnd = false;
3841

3942
private int active = 1; // 1 = yes, 0 = no
4043

@@ -214,14 +217,22 @@ public void setScheduleType(String scheduleType) {
214217
this.scheduleType = scheduleType;
215218
}
216219

217-
public int getInterval() {
220+
public String getInterval() {
218221
return interval;
219222
}
220223

221-
public void setInterval(int interval) {
224+
public void setInterval(String interval) {
222225
this.interval = interval;
223226
}
224227

228+
public int getIntervalValue() {
229+
return intervalValue;
230+
}
231+
232+
public void setIntervalValue(int intervalValue) {
233+
this.intervalValue = intervalValue;
234+
}
235+
225236
public String getTag() {
226237
return tag;
227238
}
@@ -278,6 +289,26 @@ public void setHasButton(boolean hasButton) {
278289
this.hasButton = hasButton;
279290
}
280291

292+
public double getVolume() {
293+
return volume;
294+
}
295+
296+
public void setVolume(double volume) {
297+
if (volume > 1 || volume < 0) {
298+
this.volume = 0.5;
299+
} else {
300+
this.volume = volume;
301+
}
302+
}
303+
304+
public boolean isBypassDnd() {
305+
return bypassDnd;
306+
}
307+
308+
public void setBypassDnd(boolean bypassDnd) {
309+
this.bypassDnd = bypassDnd;
310+
}
311+
281312
@Override
282313
public String toString() {
283314
return "AlarmModel{" +
@@ -304,12 +335,15 @@ public String toString() {
304335
", color='" + color + '\'' +
305336
", scheduleType='" + scheduleType + '\'' +
306337
", interval=" + interval +
338+
", intervalValue=" + intervalValue +
307339
", snoozeInterval=" + snoozeInterval +
308340
", tag='" + tag + '\'' +
309341
", data='" + data + '\'' +
310342
", loopSound=" + loopSound +
311343
", useBigText=" + useBigText +
312344
", hasButton=" + hasButton +
345+
", volume=" + volume +
346+
", bypassDnd=" + bypassDnd +
313347
", active=" + active +
314348
'}';
315349
}

0 commit comments

Comments
 (0)