Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion android/src/main/java/com/expoalarmmodule/Alarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class Alarm implements Cloneable {
String dismissText;
String snoozeText;

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;

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;
Expand All @@ -72,6 +74,7 @@ public class Alarm implements Cloneable {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.date = date;
}
this.sound = sound
}

List<Date> getDates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ private Alarm parseAlarmObject (ReadableMap alarm) {
String dismissText = alarm.hasKey("dismissText") ? alarm.getString("dismissText") : "Dismiss";
String snoozeText = alarm.hasKey("snoozeText") ? alarm.getString("snoozeText") : "Snooze";

String sound = alarm.hasKey("sound") ? alarm.getString("sound") : null;

ArrayList<Integer> days = new ArrayList<>();

ZonedDateTime date = null;
Expand All @@ -176,7 +178,7 @@ private Alarm parseAlarmObject (ReadableMap alarm) {
}
}
}
return new Alarm(uid, days, date, hour, minutes, showDismiss, showSnooze, snoozeInterval, title, description, repeating, active, dismissText, snoozeText);
return new Alarm(uid, days, date, hour, minutes, showDismiss, showSnooze, snoozeInterval, title, description, repeating, active, dismissText, snoozeText, sound);
}

private WritableMap serializeAlarmObject (Alarm alarm) throws Exception {
Expand Down
13 changes: 12 additions & 1 deletion android/src/main/java/com/expoalarmmodule/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.media.RingtoneManager;
import android.net.Uri;

import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -151,6 +153,15 @@ protected static Notification getNotification(
String channelId = context.getResources().getString(R.string.notification_channel_id);

PendingIntent pendingIntentDismiss = createActionIntent(context, alarmUid, id, "DISMISS_ACTION");

Alarm alarm = Storage.getAlarm(context, alarmUid);
Uri alarmSound;
if (alarm.sound != null && !alarm.sound.isEmpty()) {
alarmSound = Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + alarm.sound);
} else {
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
}


NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(smallIconResId)
Expand All @@ -163,7 +174,7 @@ protected static Notification getNotification(
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setAutoCancel(true)
.setOngoing(false)
.setSound(null)
.setSound(alarmSound)
.setVibrate(null)
.setContentIntent(createOnClickedIntent(context, alarmUid, id))
.setDeleteIntent(pendingIntentDismiss);
Expand Down
9 changes: 6 additions & 3 deletions android/src/main/java/com/expoalarmmodule/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ static void disable(Context context, String alarmUid) {
}

static void start(Context context, String alarmUid) {
Alarm alarm = Storage.getAlarm(context, alarmUid);
if (alarm == null) return;

activeAlarmUid = alarmUid;
sound = new Sound(context);
sound.play("default");

Log.d(TAG, "Starting " + activeAlarmUid);
sound.play(alarm.sound != null ? alarm.sound : "default");
Log.d(TAG, "Starting " + activeAlarmUid);
}

public static void stop(Context context) {
Expand Down
2 changes: 2 additions & 0 deletions src/models/Alarm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Alarm {
repeating?: boolean | undefined;
active?: boolean | undefined;
day?: string | Date | number[] | undefined;
sound?: string | undefined;

constructor(params: any = null) {
this.uid = getParam(params, 'uid');
Expand All @@ -29,6 +30,7 @@ class Alarm {
this.repeating = getParam(params, 'repeating');
this.active = getParam(params, 'active');
this.day = getParam(params, 'day');
this.sound = getParam(params, 'sound');
}

static getEmpty() {
Expand Down