Skip to content

Commit

Permalink
android modifications
Browse files Browse the repository at this point in the history
modified repeat alarm feature, delete repeating alarm added, can add volume to alarm independent of phone settings
  • Loading branch information
emekalites committed Aug 17, 2020
1 parent a846270 commit 65c1af8
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 80
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
daysUntilClose: 14
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ project.xcworkspace
build/
.idea
.gradle
gradle/
gradle*
local.properties
*.iml

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ In your `AndroidManifest.xml`
| **`loop_sound`** | Play sound continuously until you decide to stop it. `[boolean]` | `false` |
| **`message`** | **Required:** Add Notification message. | `"My Notification Message"` |
| **`play_sound`** | Play alarm notification sound. `[boolean]` | `true` |
| **`repeat_interval`** | Interval set to repeat alarm if schedule_type is "repeat". `[number]` in minutes | `1` |
| **`schedule_type`** | **Required:** Type of alarm schedule. `"once"` (to show alarm once) or `"repeat"` (to display alarm after set repeat_interval) | `"once"` |
| **`repeat_interval`** | Interval set to repeat alarm if schedule_type is "repeat". `[minutely, hourly, daily, weekly]` | `"hourly"` |
| **`interval_value`** | Set interval_value if repeat_interval is minutely and hourly. `[number]` | `1` |
| **`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"` |
| **`snooze_interval`** | Interval set to show alarm after snooze button is tapped. `[number]` in minutes | `1` |
| **`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_ |
Expand All @@ -128,6 +129,8 @@ In your `AndroidManifest.xml`
| **`vibrate`** | Set vibration when alarm is triggered. `[boolean]` | `true` |
| **`vibration`** | Set number of milliseconds to vibrate. `[number]` | `100` |
| **`use_big_text (Android only)`** | Set notification message style as big text. `[boolean]` | `false` |
| **`volume`** | Set volume. `[number between 0.0 and 1.0]` | `0.5` |
| **`bypass_dnd (Android only)`** | Sets whether or not notifications posted to this channel can interrupt the user | `false` |

## Usage

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

//Delete Repeating Alarm
ReactNativeAN.deleteRepeatingAlarm();
ReactNativeAN.deleteRepeatingAlarm(alarm.id);

//Stop Alarm
ReactNativeAN.stopAlarmSound();
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.appcompat:appcompat:1.1.0'
}

def configureReactNativePom(def pom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.Application;
import android.os.Bundle;
import android.util.Log;

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

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

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

alarm.setInterval((int)bundle.getDouble("repeat_interval", 1));
alarm.setLargeIcon(bundle.getString("large_icon"));
alarm.setLoopSound(bundle.getBoolean("loop_sound", false));
alarm.setMessage(bundle.getString("message", "My Notification Message"));
alarm.setPlaySound(bundle.getBoolean("play_sound", true));
alarm.setScheduleType(bundle.getString("schedule_type", "once"));
alarm.setSmallIcon(bundle.getString("small_icon", "ic_launcher"));
alarm.setSnoozeInterval((int)bundle.getDouble("snooze_interval", 1));
alarm.setSoundName(bundle.getString("sound_name"));
Expand All @@ -166,8 +166,9 @@ public void sendNotification(ReadableMap details) throws ParseException {
alarm.setHasButton(bundle.getBoolean("has_button", false));
alarm.setVibration((int)bundle.getDouble("vibration", 100));
alarm.setUseBigText(bundle.getBoolean("use_big_text", false));
alarm.setVolume(bundle.getDouble("volume", 0.5));
alarm.setBypassDnd(bundle.getBoolean("bypass_dnd", false));

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

alarmUtil.setAlarmFromCalendar(alarm, calendar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public class AlarmModel implements Serializable {
private String soundNames; // separate sounds with comma eg (sound1.mp3,sound2.mp3)
private String color = "red";
private String scheduleType = "once"; // once or repeat
private int interval = 1; // in minutes
private String interval = "hourly"; // hourly, daily, weekly
private int intervalValue = 1;
private int snoozeInterval = 1; // in minutes
private String tag;
private String data;
private boolean loopSound = false;
private boolean useBigText = false;
private boolean hasButton = false;
private double volume = 0.5;
private boolean bypassDnd = false;

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

Expand Down Expand Up @@ -214,14 +217,22 @@ public void setScheduleType(String scheduleType) {
this.scheduleType = scheduleType;
}

public int getInterval() {
public String getInterval() {
return interval;
}

public void setInterval(int interval) {
public void setInterval(String interval) {
this.interval = interval;
}

public int getIntervalValue() {
return intervalValue;
}

public void setIntervalValue(int intervalValue) {
this.intervalValue = intervalValue;
}

public String getTag() {
return tag;
}
Expand Down Expand Up @@ -278,6 +289,26 @@ public void setHasButton(boolean hasButton) {
this.hasButton = hasButton;
}

public double getVolume() {
return volume;
}

public void setVolume(double volume) {
if (volume > 1 || volume < 0) {
this.volume = 0.5;
} else {
this.volume = volume;
}
}

public boolean isBypassDnd() {
return bypassDnd;
}

public void setBypassDnd(boolean bypassDnd) {
this.bypassDnd = bypassDnd;
}

@Override
public String toString() {
return "AlarmModel{" +
Expand All @@ -304,12 +335,15 @@ public String toString() {
", color='" + color + '\'' +
", scheduleType='" + scheduleType + '\'' +
", interval=" + interval +
", intervalValue=" + intervalValue +
", snoozeInterval=" + snoozeInterval +
", tag='" + tag + '\'' +
", data='" + data + '\'' +
", loopSound=" + loopSound +
", useBigText=" + useBigText +
", hasButton=" + hasButton +
", volume=" + volume +
", bypassDnd=" + bypassDnd +
", active=" + active +
'}';
}
Expand Down
Loading

0 comments on commit 65c1af8

Please sign in to comment.