Commit ab7fa803 by Sebastián Katzer

Update project

parent 9b453cc0
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DaemonCodeAnalyzer">
<disable_hints />
</component>
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0" /> <entry_points version="2.0" />
</component> </component>
...@@ -32,61 +29,9 @@ ...@@ -32,61 +29,9 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Android API 21 Platform" project-jdk-type="Android SDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Android API 22 Platform" project-jdk-type="Android SDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="RunManager">
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<method />
</configuration>
<configuration default="true" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
<method />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<method />
</configuration>
<list size="0" />
<configuration name="&lt;template&gt;" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" default="true" selected="false">
<option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
</configuration>
<configuration name="&lt;template&gt;" type="WebApp" default="true" selected="false">
<Host>localhost</Host>
<Port>5050</Port>
</configuration>
</component>
<component name="masterDetails"> <component name="masterDetails">
<states> <states>
<state key="Copyright.UI"> <state key="Copyright.UI">
...@@ -126,5 +71,4 @@ ...@@ -126,5 +71,4 @@
</state> </state>
</states> </states>
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -22,6 +22,6 @@ ...@@ -22,6 +22,6 @@
<activity android:exported="false" android:launchMode="singleInstance" android:name="de.appplant.cordova.plugin.notification.ClickActivity" android:theme="@android:style/Theme.NoDisplay" /> <activity android:exported="false" android:launchMode="singleInstance" android:name="de.appplant.cordova.plugin.notification.ClickActivity" android:theme="@android:style/Theme.NoDisplay" />
</application> </application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" /> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> </manifest>
...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) { ...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isPresent = function (id, callback, scope) { exports.isPresent = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isPresent', id || 0, callback, scope);
this.exec('isPresent', notId, callback, scope);
}; };
/** /**
...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) { ...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isScheduled = function (id, callback, scope) { exports.isScheduled = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isScheduled', id || 0, callback, scope);
this.exec('isScheduled', notId, callback, scope);
}; };
/** /**
...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isTriggered = function (id, callback, scope) { exports.isTriggered = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isTriggered', id || 0, callback, scope);
this.exec('isTriggered', notId, callback, scope);
}; };
/** /**
...@@ -275,7 +269,7 @@ exports.get = function () { ...@@ -275,7 +269,7 @@ exports.get = function () {
scope = args[2]; scope = args[2];
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingle', ids.toString(), callback, scope); this.exec('getSingle', Number(ids), callback, scope);
return; return;
} }
...@@ -323,7 +317,7 @@ exports.getScheduled = function () { ...@@ -323,7 +317,7 @@ exports.getScheduled = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleScheduled', ids.toString(), callback, scope); this.exec('getSingleScheduled', Number(ids), callback, scope);
return; return;
} }
...@@ -371,7 +365,7 @@ exports.getTriggered = function () { ...@@ -371,7 +365,7 @@ exports.getTriggered = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleTriggered', ids.toString(), callback, scope); this.exec('getSingleTriggered', Number(ids), callback, scope);
return; return;
} }
......
...@@ -35,7 +35,7 @@ exports._defaults = { ...@@ -35,7 +35,7 @@ exports._defaults = {
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
badge: 0, badge: 0,
id: "0", id: 0,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined at: undefined
...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) { ...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) {
options.text = this.getValueFor(options, 'text', 'message'); options.text = this.getValueFor(options, 'text', 'message');
options.data = this.getValueFor(options, 'data', 'json'); options.data = this.getValueFor(options, 'data', 'json');
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel'); if (defaults.hasOwnProperty('autoClear')) {
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
}
if (options.autoClear !== true && options.ongoing) { if (options.autoClear !== true && options.ongoing) {
options.autoClear = false; options.autoClear = false;
...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) { ...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) {
if (options.id) { if (options.id) {
if (isNaN(options.id)) { if (isNaN(options.id)) {
options.id = this.getDefaults().id; options.id = this.getDefaults().id;
console.warn('Id is not a number: ' + options.id);
} else { } else {
options.id = options.id.toString(); options.id = Number(options.id);
} }
} }
...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) { ...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) {
if (options.badge) { if (options.badge) {
if (isNaN(options.badge)) { if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge; options.badge = this.getDefaults().badge;
console.warn('Badge number is not a number: ' + options.id);
} else { } else {
options.badge = Number(options.badge); options.badge = Number(options.badge);
} }
} }
if (typeof options.at == 'object') { if (options.at) {
options.at = Math.round(options.at.getTime()/1000); if (typeof options.at == 'object') {
options.at = options.at.getTime();
}
options.at = Math.round(options.at/1000);
} }
if (typeof options.data == 'object') { if (typeof options.data == 'object') {
...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) { ...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) {
* The new callback function * The new callback function
*/ */
exports.createCallbackFn = function (callbackFn, scope) { exports.createCallbackFn = function (callbackFn, scope) {
if (typeof callbackFn != 'function') if (typeof callbackFn != 'function')
return; return;
...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) {
}; };
/** /**
* Convert the IDs to Strings. * Convert the IDs to numbers.
* *
* @param {String/Number[]} ids * @param {String/Number[]} ids
* *
* @return Array of Strings * @return Array of Numbers
*/ */
exports.convertIds = function (ids) { exports.convertIds = function (ids) {
var convertedIds = []; var convertedIds = [];
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
convertedIds.push(ids[i].toString()); convertedIds.push(Number(ids[i]));
} }
return convertedIds; return convertedIds;
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Notification;
import de.appplant.cordova.plugin.notification.TriggerReceiver; import de.appplant.cordova.plugin.notification.TriggerReceiver;
/** /**
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import java.util.ArrayList; import android.os.Build;
import java.util.List;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
...@@ -35,9 +34,11 @@ import org.json.JSONArray; ...@@ -35,9 +34,11 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.os.Build; import java.util.ArrayList;
import java.util.List;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification;
/** /**
* This plugin utilizes the Android AlarmManager in combination with local * This plugin utilizes the Android AlarmManager in combination with local
...@@ -249,7 +250,9 @@ public class LocalNotification extends CordovaPlugin { ...@@ -249,7 +250,9 @@ public class LocalNotification extends CordovaPlugin {
Notification notification = Notification notification =
getNotificationMgr().cancel(id); getNotificationMgr().cancel(id);
fireEvent("cancel", notification); if (notification != null) {
fireEvent("cancel", notification);
}
} }
} }
...@@ -274,7 +277,9 @@ public class LocalNotification extends CordovaPlugin { ...@@ -274,7 +277,9 @@ public class LocalNotification extends CordovaPlugin {
Notification notification = Notification notification =
getNotificationMgr().clear(id); getNotificationMgr().clear(id);
fireEvent("clear", notification); if (notification != null) {
fireEvent("clear", notification);
}
} }
} }
......
...@@ -42,7 +42,9 @@ public class RestoreReceiver extends AbstractRestoreReceiver { ...@@ -42,7 +42,9 @@ public class RestoreReceiver extends AbstractRestoreReceiver {
*/ */
@Override @Override
public void onRestore (Notification notification) { public void onRestore (Notification notification) {
notification.schedule(); if (notification.isScheduled()) {
notification.schedule();
}
} }
/** /**
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Notification;
/** /**
* The alarm receiver is triggered when a scheduled alarm is fired. This class * The alarm receiver is triggered when a scheduled alarm is fired. This class
......
...@@ -23,16 +23,6 @@ ...@@ -23,16 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Resources; import android.content.res.Resources;
...@@ -43,6 +33,16 @@ import android.net.Uri; ...@@ -43,6 +33,16 @@ import android.net.Uri;
import android.os.StrictMode; import android.os.StrictMode;
import android.util.Log; import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/** /**
* Util class to map unified asset URIs to native URIs. URIs like file:/// * Util class to map unified asset URIs to native URIs. URIs like file:///
* map to absolute paths while file:// point relatively to the www folder * map to absolute paths while file:// point relatively to the www folder
...@@ -60,7 +60,7 @@ class AssetUtil { ...@@ -60,7 +60,7 @@ class AssetUtil {
// Ref to the context passed through the constructor to access the // Ref to the context passed through the constructor to access the
// resources and app directory. // resources and app directory.
private final Context context; private final Context context;
/** /**
* Constructor * Constructor
* *
...@@ -102,7 +102,7 @@ class AssetUtil { ...@@ -102,7 +102,7 @@ class AssetUtil {
/** /**
* The URI for a path. * The URI for a path.
* *
* @param path * @param path
* The given path * The given path
*/ */
...@@ -120,15 +120,13 @@ class AssetUtil { ...@@ -120,15 +120,13 @@ class AssetUtil {
return Uri.EMPTY; return Uri.EMPTY;
} }
/** /**
* URI for a file. * URI for a file.
* *
* @param path * @param path
* Absolute path like file:///... * Absolute path like file:///...
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -146,10 +144,10 @@ class AssetUtil { ...@@ -146,10 +144,10 @@ class AssetUtil {
/** /**
* URI for an asset. * URI for an asset.
* *
* @param path * @param path
* Asset path like file://... * Asset path like file://...
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -191,10 +189,10 @@ class AssetUtil { ...@@ -191,10 +189,10 @@ class AssetUtil {
/** /**
* The URI for a resource. * The URI for a resource.
* *
* @param path * @param path
* The given relative path * The given relative path
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -240,7 +238,7 @@ class AssetUtil { ...@@ -240,7 +238,7 @@ class AssetUtil {
return Uri.EMPTY; return Uri.EMPTY;
} }
/** /**
* Uri from remote located content. * Uri from remote located content.
* *
...@@ -286,11 +284,11 @@ class AssetUtil { ...@@ -286,11 +284,11 @@ class AssetUtil {
outStream.flush(); outStream.flush();
outStream.close(); outStream.close();
return Uri.fromFile(file); return Uri.fromFile(file);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Log.e("Asset", "Incorrect URL"); Log.e("Asset", "Incorrect URL");
e.printStackTrace(); e.printStackTrace();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e("Asset", "Failed to create new File from HTTP Content"); Log.e("Asset", "Failed to create new File from HTTP Content");
...@@ -305,7 +303,7 @@ class AssetUtil { ...@@ -305,7 +303,7 @@ class AssetUtil {
/** /**
* Copy content from input stream into output stream. * Copy content from input stream into output stream.
* *
* @param in * @param in
* The input stream * The input stream
* @param out * @param out
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.util.Random;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -33,6 +31,8 @@ import android.support.v4.app.NotificationCompat; ...@@ -33,6 +31,8 @@ import android.support.v4.app.NotificationCompat;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Random;
/** /**
* Builder class for local notifications. Build fully configured local * Builder class for local notifications. Build fully configured local
* notification specified by JSON object passed from JS side. * notification specified by JSON object passed from JS side.
...@@ -158,7 +158,7 @@ public class Builder { ...@@ -158,7 +158,7 @@ public class Builder {
return; return;
Intent deleteIntent = new Intent(context, clearReceiver) Intent deleteIntent = new Intent(context, clearReceiver)
.setAction(options.getId()) .setAction(options.getIdStr())
.putExtra(Options.EXTRA, options.toString()); .putExtra(Options.EXTRA, options.toString());
PendingIntent dpi = PendingIntent.getBroadcast( PendingIntent dpi = PendingIntent.getBroadcast(
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import static de.appplant.cordova.plugin.notification.Notification.PREF_KEY;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -34,12 +32,13 @@ import org.json.JSONObject; ...@@ -34,12 +32,13 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static de.appplant.cordova.plugin.notification.Notification.PREF_KEY;
/** /**
* Central way to access all or single local notifications set by specific * Central way to access all or single local notifications set by specific
* state like triggered or scheduled. Offers shortcut ways to schedule, * state like triggered or scheduled. Offers shortcut ways to schedule,
......
...@@ -45,7 +45,7 @@ import java.util.Date; ...@@ -45,7 +45,7 @@ import java.util.Date;
public class Notification { public class Notification {
// Used to differ notifications by their life cycle state // Used to differ notifications by their life cycle state
public static enum Type { public enum Type {
ALL, SCHEDULED, TRIGGERED ALL, SCHEDULED, TRIGGERED
} }
...@@ -105,7 +105,7 @@ public class Notification { ...@@ -105,7 +105,7 @@ public class Notification {
* Get notification ID. * Get notification ID.
*/ */
public int getId () { public int getId () {
return options.getIdAsInt(); return options.getId();
} }
/** /**
...@@ -162,27 +162,23 @@ public class Notification { ...@@ -162,27 +162,23 @@ public class Notification {
* Schedule the local notification. * Schedule the local notification.
*/ */
public void schedule() { public void schedule() {
long triggerTime = getNextTriggerTime(); long triggerTime = options.getTriggerTime();
persist(); persist();
// Intent gets called when the Notification gets fired // Intent gets called when the Notification gets fired
Intent intent = new Intent(context, receiver) Intent intent = new Intent(context, receiver)
.setAction(options.getId()) .setAction(options.getIdStr())
.putExtra(Options.EXTRA, options.toString()); .putExtra(Options.EXTRA, options.toString());
PendingIntent pi = PendingIntent.getBroadcast( PendingIntent pi = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
}
/**
* Re-schedule the local notification if repeating.
*/
void reschedule () {
if (isRepeating()) { if (isRepeating()) {
schedule(); getAlarmMgr().setRepeating(AlarmManager.RTC_WAKEUP,
triggerTime, options.getRepeatInterval(), pi);
} else {
getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
} }
} }
...@@ -208,13 +204,13 @@ public class Notification { ...@@ -208,13 +204,13 @@ public class Notification {
*/ */
public void cancel() { public void cancel() {
Intent intent = new Intent(context, receiver) Intent intent = new Intent(context, receiver)
.setAction(options.getId()); .setAction(options.getIdStr());
PendingIntent pi = PendingIntent. PendingIntent pi = PendingIntent.
getBroadcast(context, 0, intent, 0); getBroadcast(context, 0, intent, 0);
getAlarmMgr().cancel(pi); getAlarmMgr().cancel(pi);
getNotMgr().cancel(options.getIdAsInt()); getNotMgr().cancel(options.getId());
unpersist(); unpersist();
} }
...@@ -232,7 +228,7 @@ public class Notification { ...@@ -232,7 +228,7 @@ public class Notification {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void showNotification () { private void showNotification () {
int id = getOptions().getIdAsInt(); int id = getOptions().getId();
if (Build.VERSION.SDK_INT <= 15) { if (Build.VERSION.SDK_INT <= 15) {
// Notification for HoneyComb to ICS // Notification for HoneyComb to ICS
...@@ -251,26 +247,11 @@ public class Notification { ...@@ -251,26 +247,11 @@ public class Notification {
} }
/** /**
* Next trigger time.
*/
public long getNextTriggerTime() {
long triggerTime = options.getTriggerTime();
if (!isRepeating() || !isTriggered())
return triggerTime;
long interval = options.getRepeatInterval();
int triggerCount = getTriggerCountSinceSchedule();
return triggerTime + (triggerCount + 1) * interval;
}
/**
* Count of triggers since schedule. * Count of triggers since schedule.
*/ */
public int getTriggerCountSinceSchedule() { public int getTriggerCountSinceSchedule() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long initTriggerTime = options.getTriggerTime(); long triggerTime = options.getTriggerTime();
if (!wasInThePast()) if (!wasInThePast())
return 0; return 0;
...@@ -278,7 +259,7 @@ public class Notification { ...@@ -278,7 +259,7 @@ public class Notification {
if (!isRepeating()) if (!isRepeating())
return 1; return 1;
return (int) ((now - initTriggerTime) / options.getRepeatInterval()); return (int) ((now - triggerTime) / options.getRepeatInterval());
} }
/** /**
...@@ -294,6 +275,7 @@ public class Notification { ...@@ -294,6 +275,7 @@ public class Notification {
e.printStackTrace(); e.printStackTrace();
} }
json.remove("firstAt");
json.remove("updatedAt"); json.remove("updatedAt");
json.remove("soundUri"); json.remove("soundUri");
json.remove("iconUri"); json.remove("iconUri");
...@@ -309,7 +291,7 @@ public class Notification { ...@@ -309,7 +291,7 @@ public class Notification {
private void persist () { private void persist () {
SharedPreferences.Editor editor = getPrefs().edit(); SharedPreferences.Editor editor = getPrefs().edit();
editor.putString(options.getId(), options.toString()); editor.putString(options.getIdStr(), options.toString());
if (Build.VERSION.SDK_INT < 9) { if (Build.VERSION.SDK_INT < 9) {
editor.commit(); editor.commit();
...@@ -324,7 +306,7 @@ public class Notification { ...@@ -324,7 +306,7 @@ public class Notification {
private void unpersist () { private void unpersist () {
SharedPreferences.Editor editor = getPrefs().edit(); SharedPreferences.Editor editor = getPrefs().edit();
editor.remove(options.getId()); editor.remove(options.getIdStr());
if (Build.VERSION.SDK_INT < 9) { if (Build.VERSION.SDK_INT < 9) {
editor.commit(); editor.commit();
......
...@@ -23,16 +23,16 @@ ...@@ -23,16 +23,16 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
/** /**
* Wrapper around the JSON object passed through JS which contains all * Wrapper around the JSON object passed through JS which contains all
* possible option values. Class provides simple readers and more advanced * possible option values. Class provides simple readers and more advanced
...@@ -189,35 +189,34 @@ public class Options { ...@@ -189,35 +189,34 @@ public class Options {
} }
/** /**
* Trigger date in milliseconds. * ID for the local notification as a number.
*/ */
public long getTriggerTime() { public Integer getId() {
return options.optLong("at", 0) * 1000; return options.optInt("id", 0);
} }
/** /**
* Trigger date. * ID for the local notification as a string.
*/ */
public Date getTriggerDate() { public String getIdStr() {
return new Date(getTriggerTime()); return getId().toString();
} }
/** /**
* ID for the local notification. * Trigger date.
*/ */
public String getId() { public Date getTriggerDate() {
return options.optString("id", "0"); return new Date(getTriggerTime());
} }
/** /**
* ID for the local notification. * Trigger date in milliseconds.
*/ */
public int getIdAsInt() { public long getTriggerTime() {
try { return Math.max(
return Integer.parseInt(getId()); System.currentTimeMillis(),
} catch (Exception ignore) { options.optLong("at", 0) * 1000
return 0; );
}
} }
/** /**
......
...@@ -42,11 +42,6 @@ public class TriggerReceiver extends AbstractTriggerReceiver { ...@@ -42,11 +42,6 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
*/ */
@Override @Override
public void onTrigger (Notification notification, boolean updated) { public void onTrigger (Notification notification, boolean updated) {
if (notification.isRepeating()) {
notification.reschedule();
}
notification.show(); notification.show();
} }
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D2AAC07D0554694100DB518D"
BuildableName = "libCordova.a"
BlueprintName = "CordovaLib"
ReferencedContainer = "container:CordovaLib.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D2AAC07D0554694100DB518D"
BuildableName = "libCordova.a"
BlueprintName = "CordovaLib"
ReferencedContainer = "container:CordovaLib.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D2AAC07D0554694100DB518D"
BuildableName = "libCordova.a"
BlueprintName = "CordovaLib"
ReferencedContainer = "container:CordovaLib.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CordovaLib.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>D2AAC07D0554694100DB518D</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:NotificationExample.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>A63F5FF5-C059-403D-81B9-E740110FFC25</string>
<key>IDESourceControlProjectName</key>
<string>NotificationExample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E6A4395732CC1C6C7441E85472223F9AAF3A67CD</key>
<string>github.com:katzer/cordova-plugin-local-notifications.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>platforms/ios/NotificationExample.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E6A4395732CC1C6C7441E85472223F9AAF3A67CD</key>
<string>../../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:katzer/cordova-plugin-local-notifications.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E6A4395732CC1C6C7441E85472223F9AAF3A67CD</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E6A4395732CC1C6C7441E85472223F9AAF3A67CD</string>
<key>IDESourceControlWCCName</key>
<string>cordova-example-local-notifications</string>
</dict>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
BuildableName = "NotificationExample.app"
BlueprintName = "NotificationExample"
ReferencedContainer = "container:NotificationExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
BuildableName = "NotificationExample.app"
BlueprintName = "NotificationExample"
ReferencedContainer = "container:NotificationExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
BuildableName = "NotificationExample.app"
BlueprintName = "NotificationExample"
ReferencedContainer = "container:NotificationExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
BuildableName = "NotificationExample.app"
BlueprintName = "NotificationExample"
ReferencedContainer = "container:NotificationExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>NotificationExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>1D6058900D05DD3D006BFB54</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
...@@ -61,6 +61,13 @@ ...@@ -61,6 +61,13 @@
// List all ids from all triggered notifications // List all ids from all triggered notifications
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command; - (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;
// Propertys for given local notification
- (void) getSingle:(CDVInvokedUrlCommand*)command;
// Propertya for given scheduled notification
- (void) getSingleScheduled:(CDVInvokedUrlCommand*)command;
// Propertys for given triggered notification
- (void) getSingleTriggered:(CDVInvokedUrlCommand*)command;
// Property list for given local notifications // Property list for given local notifications
- (void) getAll:(CDVInvokedUrlCommand*)command; - (void) getAll:(CDVInvokedUrlCommand*)command;
// Property list for given scheduled notifications // Property list for given scheduled notifications
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSDictionary* options in notifications) { for (NSDictionary* options in notifications) {
NSString* id = [options objectForKey:@"id"]; NSNumber* id = [options objectForKey:@"id"];
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSString* id in command.arguments) { for (NSNumber* id in command.arguments) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
- (void) clear:(CDVInvokedUrlCommand*)command - (void) clear:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSString* id in command.arguments) { for (NSNumber* id in command.arguments) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
type:(APPLocalNotificationType)type; type:(APPLocalNotificationType)type;
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSString* id = [command argumentAtIndex:0]; NSNumber* id = [command argumentAtIndex:0];
BOOL exist; BOOL exist;
CDVPluginResult* result; CDVPluginResult* result;
...@@ -314,6 +314,28 @@ ...@@ -314,6 +314,28 @@
} }
/** /**
* Propertys for given local notification.
*/
- (void) getSingle:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeAll];
}
/**
* Propertya for given scheduled notification.
*/
- (void) getSingleScheduled:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeScheduled];
}
// Propertys for given triggered notification
- (void) getSingleTriggered:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeTriggered];
}
/**
* Property list for given local notifications. * Property list for given local notifications.
* *
* @param ids * @param ids
...@@ -347,6 +369,38 @@ ...@@ -347,6 +369,38 @@
} }
/** /**
* Propertys for given triggered notification.
*
* @param type
* Notification life cycle type
* @param ids
* The ID of the notification
*/
- (void) getOption:(CDVInvokedUrlCommand*)command
byType:(APPLocalNotificationType)type;
{
[self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments;
NSArray* notifications;
CDVPluginResult* result;
if (type == NotifcationTypeAll) {
notifications = [self.app localNotificationOptionsById:ids];
}
else {
notifications = [self.app localNotificationOptionsByType:type
andId:ids];
}
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:notifications[0]];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* Property list for given triggered notifications. * Property list for given triggered notifications.
* *
* @param type * @param type
...@@ -474,7 +528,7 @@ ...@@ -474,7 +528,7 @@
*/ */
- (void) cancelForerunnerLocalNotification:(UILocalNotification*)notification - (void) cancelForerunnerLocalNotification:(UILocalNotification*)notification
{ {
NSString* id = notification.options.id; NSNumber* id = notification.options.id;
UILocalNotification* forerunner; UILocalNotification* forerunner;
forerunner = [self.app localNotificationWithId:id]; forerunner = [self.app localNotificationWithId:id];
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
- (id) initWithDict:(NSDictionary*)dict; - (id) initWithDict:(NSDictionary*)dict;
@property (readonly, getter=id) NSString* id; @property (readonly, getter=id) NSNumber* id;
@property (readonly, getter=badgeNumber) NSInteger badgeNumber; @property (readonly, getter=badgeNumber) NSInteger badgeNumber;
@property (readonly, getter=alertBody) NSString* alertBody; @property (readonly, getter=alertBody) NSString* alertBody;
@property (readonly, getter=soundName) NSString* soundName; @property (readonly, getter=soundName) NSString* soundName;
......
...@@ -59,9 +59,11 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -59,9 +59,11 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
/** /**
* The notification's ID. * The notification's ID.
*/ */
- (NSString*) id - (NSNumber*) id
{ {
return [dict objectForKey:@"id"]; NSInteger id = [[dict objectForKey:@"id"] integerValue];
return [NSNumber numberWithInteger:id];
} }
/** /**
...@@ -186,6 +188,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -186,6 +188,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
*/ */
- (NSDictionary*) userInfo - (NSDictionary*) userInfo
{ {
if ([dict objectForKey:@"updatedAt"]) {
NSMutableDictionary* data = [dict mutableCopy];
[data removeObjectForKey:@"updatedAt"];
return data;
}
return dict; return dict;
} }
......
...@@ -37,14 +37,14 @@ ...@@ -37,14 +37,14 @@
- (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type; - (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type;
// If local notification with ID exists // If local notification with ID exists
- (BOOL) localNotificationExist:(NSString*)id; - (BOOL) localNotificationExist:(NSNumber*)id;
// If local notification with ID and type exists // If local notification with ID and type exists
- (BOOL) localNotificationExist:(NSString*)id type:(APPLocalNotificationType)type; - (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type;
// Local notification by ID // Local notification by ID
- (UILocalNotification*) localNotificationWithId:(NSString*)id; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id;
// Local notification by ID and type // Local notification by ID and type
- (UILocalNotification*) localNotificationWithId:(NSString*)id andType:(APPLocalNotificationType)type; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type;
// Property list from all local notifications // Property list from all local notifications
- (NSArray*) localNotificationOptions; - (NSArray*) localNotificationOptions;
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
* @param id * @param id
* Notification ID * Notification ID
*/ */
- (BOOL) localNotificationExist:(NSString*)id - (BOOL) localNotificationExist:(NSNumber*)id
{ {
return [self localNotificationWithId:id] != NULL; return [self localNotificationWithId:id] != NULL;
} }
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (BOOL) localNotificationExist:(NSString*)id type:(APPLocalNotificationType)type - (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type
{ {
return [self localNotificationWithId:id andType:type] != NULL; return [self localNotificationWithId:id andType:type] != NULL;
} }
...@@ -182,13 +182,13 @@ ...@@ -182,13 +182,13 @@
* @param id * @param id
* Notification ID * Notification ID
*/ */
- (UILocalNotification*) localNotificationWithId:(NSString*)id - (UILocalNotification*) localNotificationWithId:(NSNumber*)id
{ {
NSArray* notifications = self.localNotifications; NSArray* notifications = self.localNotifications;
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
if ([notification.options.id isEqualToString:id]) { if ([notification.options.id isEqualToNumber:id]) {
return notification; return notification;
} }
} }
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (UILocalNotification*) localNotificationWithId:(NSString*)id andType:(APPLocalNotificationType)type - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type
{ {
UILocalNotification* notification = [self localNotificationWithId:id]; UILocalNotification* notification = [self localNotificationWithId:id];
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
return options; return options;
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
if (notification.type == type) { if (notification.type == type) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
...@@ -262,12 +262,12 @@ ...@@ -262,12 +262,12 @@
UILocalNotification* notification; UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids) for (NSNumber* id in ids)
{ {
notification = [self localNotificationWithId:id]; notification = [self localNotificationWithId:id];
if (notification) { if (notification) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
...@@ -287,12 +287,12 @@ ...@@ -287,12 +287,12 @@
UILocalNotification* notification; UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids) for (NSNumber* id in ids)
{ {
notification = [self localNotificationWithId:id]; notification = [self localNotificationWithId:id];
if (notification && notification.type == type) { if (notification && notification.type == type) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
......
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
</author> </author>
<content src="index.html" /> <content src="index.html" />
<access origin="*" /> <access origin="*" />
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
<feature name="Device"> <feature name="Device">
<param name="ios-package" value="CDVDevice" /> <param name="ios-package" value="CDVDevice" />
</feature> </feature>
...@@ -33,4 +30,7 @@ ...@@ -33,4 +30,7 @@
<param name="ios-package" onload="true" value="APPLocalNotification" /> <param name="ios-package" onload="true" value="APPLocalNotification" />
<param name="onload" value="true" /> <param name="onload" value="true" />
</feature> </feature>
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
</widget> </widget>
cordova.define('cordova/plugin_list', function(require, exports, module) { cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [ module.exports = [
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js", "file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification", "id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [ "clobbers": [
...@@ -36,6 +25,17 @@ module.exports = [ ...@@ -36,6 +25,17 @@ module.exports = [
] ]
}, },
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/org.apache.cordova.device/www/device.js", "file": "plugins/org.apache.cordova.device/www/device.js",
"id": "org.apache.cordova.device.device", "id": "org.apache.cordova.device.device",
"clobbers": [ "clobbers": [
...@@ -46,8 +46,8 @@ module.exports = [ ...@@ -46,8 +46,8 @@ module.exports = [
module.exports.metadata = module.exports.metadata =
// TOP OF METADATA // TOP OF METADATA
{ {
"nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev", "de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3",
"org.apache.cordova.device": "0.3.0" "org.apache.cordova.device": "0.3.0"
} }
// BOTTOM OF METADATA // BOTTOM OF METADATA
......
...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) { ...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isPresent = function (id, callback, scope) { exports.isPresent = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isPresent', id || 0, callback, scope);
this.exec('isPresent', notId, callback, scope);
}; };
/** /**
...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) { ...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isScheduled = function (id, callback, scope) { exports.isScheduled = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isScheduled', id || 0, callback, scope);
this.exec('isScheduled', notId, callback, scope);
}; };
/** /**
...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isTriggered = function (id, callback, scope) { exports.isTriggered = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isTriggered', id || 0, callback, scope);
this.exec('isTriggered', notId, callback, scope);
}; };
/** /**
...@@ -275,7 +269,7 @@ exports.get = function () { ...@@ -275,7 +269,7 @@ exports.get = function () {
scope = args[2]; scope = args[2];
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingle', ids.toString(), callback, scope); this.exec('getSingle', Number(ids), callback, scope);
return; return;
} }
...@@ -323,7 +317,7 @@ exports.getScheduled = function () { ...@@ -323,7 +317,7 @@ exports.getScheduled = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleScheduled', ids.toString(), callback, scope); this.exec('getSingleScheduled', Number(ids), callback, scope);
return; return;
} }
...@@ -371,7 +365,7 @@ exports.getTriggered = function () { ...@@ -371,7 +365,7 @@ exports.getTriggered = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleTriggered', ids.toString(), callback, scope); this.exec('getSingleTriggered', Number(ids), callback, scope);
return; return;
} }
......
...@@ -35,7 +35,7 @@ exports._defaults = { ...@@ -35,7 +35,7 @@ exports._defaults = {
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
badge: 0, badge: 0,
id: "0", id: 0,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined at: undefined
...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) { ...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) {
options.text = this.getValueFor(options, 'text', 'message'); options.text = this.getValueFor(options, 'text', 'message');
options.data = this.getValueFor(options, 'data', 'json'); options.data = this.getValueFor(options, 'data', 'json');
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel'); if (defaults.hasOwnProperty('autoClear')) {
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
}
if (options.autoClear !== true && options.ongoing) { if (options.autoClear !== true && options.ongoing) {
options.autoClear = false; options.autoClear = false;
...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) { ...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) {
if (options.id) { if (options.id) {
if (isNaN(options.id)) { if (isNaN(options.id)) {
options.id = this.getDefaults().id; options.id = this.getDefaults().id;
console.warn('Id is not a number: ' + options.id);
} else { } else {
options.id = options.id.toString(); options.id = Number(options.id);
} }
} }
...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) { ...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) {
if (options.badge) { if (options.badge) {
if (isNaN(options.badge)) { if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge; options.badge = this.getDefaults().badge;
console.warn('Badge number is not a number: ' + options.id);
} else { } else {
options.badge = Number(options.badge); options.badge = Number(options.badge);
} }
} }
if (typeof options.at == 'object') { if (options.at) {
options.at = Math.round(options.at.getTime()/1000); if (typeof options.at == 'object') {
options.at = options.at.getTime();
}
options.at = Math.round(options.at/1000);
} }
if (typeof options.data == 'object') { if (typeof options.data == 'object') {
...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) { ...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) {
* The new callback function * The new callback function
*/ */
exports.createCallbackFn = function (callbackFn, scope) { exports.createCallbackFn = function (callbackFn, scope) {
if (typeof callbackFn != 'function') if (typeof callbackFn != 'function')
return; return;
...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) {
}; };
/** /**
* Convert the IDs to Strings. * Convert the IDs to numbers.
* *
* @param {String/Number[]} ids * @param {String/Number[]} ids
* *
* @return Array of Strings * @return Array of Numbers
*/ */
exports.convertIds = function (ids) { exports.convertIds = function (ids) {
var convertedIds = []; var convertedIds = [];
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
convertedIds.push(ids[i].toString()); convertedIds.push(Number(ids[i]));
} }
return convertedIds; return convertedIds;
......
cordova.define('cordova/plugin_list', function(require, exports, module) { cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [ module.exports = [
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js", "file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification", "id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [ "clobbers": [
...@@ -46,17 +57,6 @@ module.exports = [ ...@@ -46,17 +57,6 @@ module.exports = [
] ]
}, },
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/org.apache.cordova.device/www/device.js", "file": "plugins/org.apache.cordova.device/www/device.js",
"id": "org.apache.cordova.device.device", "id": "org.apache.cordova.device.device",
"clobbers": [ "clobbers": [
...@@ -74,8 +74,8 @@ module.exports = [ ...@@ -74,8 +74,8 @@ module.exports = [
module.exports.metadata = module.exports.metadata =
// TOP OF METADATA // TOP OF METADATA
{ {
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3", "nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"org.apache.cordova.device": "0.3.0" "org.apache.cordova.device": "0.3.0"
} }
// BOTTOM OF METADATA // BOTTOM OF METADATA
......
...@@ -209,6 +209,54 @@ exports.getTriggeredIds = function (success, error) { ...@@ -209,6 +209,54 @@ exports.getTriggeredIds = function (success, error) {
}; };
/** /**
* Propertys for given notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingle = function (success, error, ids) {
var notification = exports.core.getAll(ids)[0];
success(notification);
};
/**
* Propertys for given scheduled notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingleScheduled = function (success, error, ids) {
var notification = exports.core.getScheduled(ids)[0];
success(notification);
};
/**
* Propertys for given triggered notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingleTriggered = function (success, error, ids) {
var notification = exports.core.getTriggered(ids)[0];
success(notification);
};
/**
* Property list for given notifications. * Property list for given notifications.
* If called without IDs, all notification will be returned. * If called without IDs, all notification will be returned.
* *
......
...@@ -20,8 +20,8 @@ cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification. ...@@ -20,8 +20,8 @@ cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification.
*/ */
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy').core; exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy').core;
var channel = require('cordova/channel'); var channel = require('cordova/channel');
......
...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) { ...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isPresent = function (id, callback, scope) { exports.isPresent = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isPresent', id || 0, callback, scope);
this.exec('isPresent', notId, callback, scope);
}; };
/** /**
...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) { ...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isScheduled = function (id, callback, scope) { exports.isScheduled = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isScheduled', id || 0, callback, scope);
this.exec('isScheduled', notId, callback, scope);
}; };
/** /**
...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isTriggered = function (id, callback, scope) { exports.isTriggered = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isTriggered', id || 0, callback, scope);
this.exec('isTriggered', notId, callback, scope);
}; };
/** /**
...@@ -275,7 +269,7 @@ exports.get = function () { ...@@ -275,7 +269,7 @@ exports.get = function () {
scope = args[2]; scope = args[2];
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingle', ids.toString(), callback, scope); this.exec('getSingle', Number(ids), callback, scope);
return; return;
} }
...@@ -323,7 +317,7 @@ exports.getScheduled = function () { ...@@ -323,7 +317,7 @@ exports.getScheduled = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleScheduled', ids.toString(), callback, scope); this.exec('getSingleScheduled', Number(ids), callback, scope);
return; return;
} }
...@@ -371,7 +365,7 @@ exports.getTriggered = function () { ...@@ -371,7 +365,7 @@ exports.getTriggered = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleTriggered', ids.toString(), callback, scope); this.exec('getSingleTriggered', Number(ids), callback, scope);
return; return;
} }
......
...@@ -35,7 +35,7 @@ exports._defaults = { ...@@ -35,7 +35,7 @@ exports._defaults = {
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
badge: 0, badge: 0,
id: "0", id: 0,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined at: undefined
...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) { ...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) {
options.text = this.getValueFor(options, 'text', 'message'); options.text = this.getValueFor(options, 'text', 'message');
options.data = this.getValueFor(options, 'data', 'json'); options.data = this.getValueFor(options, 'data', 'json');
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel'); if (defaults.hasOwnProperty('autoClear')) {
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
}
if (options.autoClear !== true && options.ongoing) { if (options.autoClear !== true && options.ongoing) {
options.autoClear = false; options.autoClear = false;
...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) { ...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) {
if (options.id) { if (options.id) {
if (isNaN(options.id)) { if (isNaN(options.id)) {
options.id = this.getDefaults().id; options.id = this.getDefaults().id;
console.warn('Id is not a number: ' + options.id);
} else { } else {
options.id = options.id.toString(); options.id = Number(options.id);
} }
} }
...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) { ...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) {
if (options.badge) { if (options.badge) {
if (isNaN(options.badge)) { if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge; options.badge = this.getDefaults().badge;
console.warn('Badge number is not a number: ' + options.id);
} else { } else {
options.badge = Number(options.badge); options.badge = Number(options.badge);
} }
} }
if (typeof options.at == 'object') { if (options.at) {
options.at = Math.round(options.at.getTime()/1000); if (typeof options.at == 'object') {
options.at = options.at.getTime();
}
options.at = Math.round(options.at/1000);
} }
if (typeof options.data == 'object') { if (typeof options.data == 'object') {
...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) { ...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) {
* The new callback function * The new callback function
*/ */
exports.createCallbackFn = function (callbackFn, scope) { exports.createCallbackFn = function (callbackFn, scope) {
if (typeof callbackFn != 'function') if (typeof callbackFn != 'function')
return; return;
...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) {
}; };
/** /**
* Convert the IDs to Strings. * Convert the IDs to numbers.
* *
* @param {String/Number[]} ids * @param {String/Number[]} ids
* *
* @return Array of Strings * @return Array of Numbers
*/ */
exports.convertIds = function (ids) { exports.convertIds = function (ids) {
var convertedIds = []; var convertedIds = [];
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
convertedIds.push(ids[i].toString()); convertedIds.push(Number(ids[i]));
} }
return convertedIds; return convertedIds;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<!-- cordova --> <!-- cordova -->
<engines> <engines>
<engine name="cordova" version=">=3.0.0" /> <engine name="cordova" version=">=3.0.0" />
<engine name="cordova" version="<4.0.0" />
</engines> </engines>
<!-- dependencies --> <!-- dependencies -->
......
...@@ -39,10 +39,16 @@ module.exports = function (context) { ...@@ -39,10 +39,16 @@ module.exports = function (context) {
var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'), var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'),
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'), ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
platforms = context.requireCordovaModule('cordova-lib/src/cordova/platforms'),
projectRoot = cordova_util.isCordova(), projectRoot = cordova_util.isCordova(),
xml = cordova_util.projectConfig(projectRoot), xml = cordova_util.projectConfig(projectRoot),
cfg = new ConfigParser(xml); cfg = new ConfigParser(xml);
// Cordova moved the platforms stuff; try both locations so we'll work for new and old file layouts.
var platforms;
try {
platforms = context.requireCordovaModule('cordova-lib/src/cordova/platforms');
} catch(e) {
platforms = context.requireCordovaModule('cordova-lib/src/platforms/platforms');
}
/** /**
* The absolute path for the file. * The absolute path for the file.
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Notification;
import de.appplant.cordova.plugin.notification.TriggerReceiver; import de.appplant.cordova.plugin.notification.TriggerReceiver;
/** /**
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import java.util.ArrayList; import android.os.Build;
import java.util.List;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
...@@ -35,9 +34,11 @@ import org.json.JSONArray; ...@@ -35,9 +34,11 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.os.Build; import java.util.ArrayList;
import java.util.List;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification;
/** /**
* This plugin utilizes the Android AlarmManager in combination with local * This plugin utilizes the Android AlarmManager in combination with local
...@@ -249,7 +250,9 @@ public class LocalNotification extends CordovaPlugin { ...@@ -249,7 +250,9 @@ public class LocalNotification extends CordovaPlugin {
Notification notification = Notification notification =
getNotificationMgr().cancel(id); getNotificationMgr().cancel(id);
fireEvent("cancel", notification); if (notification != null) {
fireEvent("cancel", notification);
}
} }
} }
...@@ -274,7 +277,9 @@ public class LocalNotification extends CordovaPlugin { ...@@ -274,7 +277,9 @@ public class LocalNotification extends CordovaPlugin {
Notification notification = Notification notification =
getNotificationMgr().clear(id); getNotificationMgr().clear(id);
fireEvent("clear", notification); if (notification != null) {
fireEvent("clear", notification);
}
} }
} }
......
...@@ -42,7 +42,9 @@ public class RestoreReceiver extends AbstractRestoreReceiver { ...@@ -42,7 +42,9 @@ public class RestoreReceiver extends AbstractRestoreReceiver {
*/ */
@Override @Override
public void onRestore (Notification notification) { public void onRestore (Notification notification) {
notification.schedule(); if (notification.isScheduled()) {
notification.schedule();
}
} }
/** /**
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Notification;
/** /**
* The alarm receiver is triggered when a scheduled alarm is fired. This class * The alarm receiver is triggered when a scheduled alarm is fired. This class
......
...@@ -23,16 +23,6 @@ ...@@ -23,16 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Resources; import android.content.res.Resources;
...@@ -43,6 +33,16 @@ import android.net.Uri; ...@@ -43,6 +33,16 @@ import android.net.Uri;
import android.os.StrictMode; import android.os.StrictMode;
import android.util.Log; import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/** /**
* Util class to map unified asset URIs to native URIs. URIs like file:/// * Util class to map unified asset URIs to native URIs. URIs like file:///
* map to absolute paths while file:// point relatively to the www folder * map to absolute paths while file:// point relatively to the www folder
...@@ -60,7 +60,7 @@ class AssetUtil { ...@@ -60,7 +60,7 @@ class AssetUtil {
// Ref to the context passed through the constructor to access the // Ref to the context passed through the constructor to access the
// resources and app directory. // resources and app directory.
private final Context context; private final Context context;
/** /**
* Constructor * Constructor
* *
...@@ -102,7 +102,7 @@ class AssetUtil { ...@@ -102,7 +102,7 @@ class AssetUtil {
/** /**
* The URI for a path. * The URI for a path.
* *
* @param path * @param path
* The given path * The given path
*/ */
...@@ -120,15 +120,13 @@ class AssetUtil { ...@@ -120,15 +120,13 @@ class AssetUtil {
return Uri.EMPTY; return Uri.EMPTY;
} }
/** /**
* URI for a file. * URI for a file.
* *
* @param path * @param path
* Absolute path like file:///... * Absolute path like file:///...
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -146,10 +144,10 @@ class AssetUtil { ...@@ -146,10 +144,10 @@ class AssetUtil {
/** /**
* URI for an asset. * URI for an asset.
* *
* @param path * @param path
* Asset path like file://... * Asset path like file://...
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -191,10 +189,10 @@ class AssetUtil { ...@@ -191,10 +189,10 @@ class AssetUtil {
/** /**
* The URI for a resource. * The URI for a resource.
* *
* @param path * @param path
* The given relative path * The given relative path
* *
* @return * @return
* URI pointing to the given path * URI pointing to the given path
*/ */
...@@ -240,7 +238,7 @@ class AssetUtil { ...@@ -240,7 +238,7 @@ class AssetUtil {
return Uri.EMPTY; return Uri.EMPTY;
} }
/** /**
* Uri from remote located content. * Uri from remote located content.
* *
...@@ -286,11 +284,11 @@ class AssetUtil { ...@@ -286,11 +284,11 @@ class AssetUtil {
outStream.flush(); outStream.flush();
outStream.close(); outStream.close();
return Uri.fromFile(file); return Uri.fromFile(file);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Log.e("Asset", "Incorrect URL"); Log.e("Asset", "Incorrect URL");
e.printStackTrace(); e.printStackTrace();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e("Asset", "Failed to create new File from HTTP Content"); Log.e("Asset", "Failed to create new File from HTTP Content");
...@@ -305,7 +303,7 @@ class AssetUtil { ...@@ -305,7 +303,7 @@ class AssetUtil {
/** /**
* Copy content from input stream into output stream. * Copy content from input stream into output stream.
* *
* @param in * @param in
* The input stream * The input stream
* @param out * @param out
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.util.Random;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -33,6 +31,8 @@ import android.support.v4.app.NotificationCompat; ...@@ -33,6 +31,8 @@ import android.support.v4.app.NotificationCompat;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Random;
/** /**
* Builder class for local notifications. Build fully configured local * Builder class for local notifications. Build fully configured local
* notification specified by JSON object passed from JS side. * notification specified by JSON object passed from JS side.
...@@ -158,7 +158,7 @@ public class Builder { ...@@ -158,7 +158,7 @@ public class Builder {
return; return;
Intent deleteIntent = new Intent(context, clearReceiver) Intent deleteIntent = new Intent(context, clearReceiver)
.setAction(options.getId()) .setAction(options.getIdStr())
.putExtra(Options.EXTRA, options.toString()); .putExtra(Options.EXTRA, options.toString());
PendingIntent dpi = PendingIntent.getBroadcast( PendingIntent dpi = PendingIntent.getBroadcast(
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import static de.appplant.cordova.plugin.notification.Notification.PREF_KEY;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -34,12 +32,13 @@ import org.json.JSONObject; ...@@ -34,12 +32,13 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static de.appplant.cordova.plugin.notification.Notification.PREF_KEY;
/** /**
* Central way to access all or single local notifications set by specific * Central way to access all or single local notifications set by specific
* state like triggered or scheduled. Offers shortcut ways to schedule, * state like triggered or scheduled. Offers shortcut ways to schedule,
......
...@@ -45,7 +45,7 @@ import java.util.Date; ...@@ -45,7 +45,7 @@ import java.util.Date;
public class Notification { public class Notification {
// Used to differ notifications by their life cycle state // Used to differ notifications by their life cycle state
public static enum Type { public enum Type {
ALL, SCHEDULED, TRIGGERED ALL, SCHEDULED, TRIGGERED
} }
...@@ -105,7 +105,7 @@ public class Notification { ...@@ -105,7 +105,7 @@ public class Notification {
* Get notification ID. * Get notification ID.
*/ */
public int getId () { public int getId () {
return options.getIdAsInt(); return options.getId();
} }
/** /**
...@@ -162,27 +162,23 @@ public class Notification { ...@@ -162,27 +162,23 @@ public class Notification {
* Schedule the local notification. * Schedule the local notification.
*/ */
public void schedule() { public void schedule() {
long triggerTime = getNextTriggerTime(); long triggerTime = options.getTriggerTime();
persist(); persist();
// Intent gets called when the Notification gets fired // Intent gets called when the Notification gets fired
Intent intent = new Intent(context, receiver) Intent intent = new Intent(context, receiver)
.setAction(options.getId()) .setAction(options.getIdStr())
.putExtra(Options.EXTRA, options.toString()); .putExtra(Options.EXTRA, options.toString());
PendingIntent pi = PendingIntent.getBroadcast( PendingIntent pi = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
}
/**
* Re-schedule the local notification if repeating.
*/
void reschedule () {
if (isRepeating()) { if (isRepeating()) {
schedule(); getAlarmMgr().setRepeating(AlarmManager.RTC_WAKEUP,
triggerTime, options.getRepeatInterval(), pi);
} else {
getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
} }
} }
...@@ -208,13 +204,13 @@ public class Notification { ...@@ -208,13 +204,13 @@ public class Notification {
*/ */
public void cancel() { public void cancel() {
Intent intent = new Intent(context, receiver) Intent intent = new Intent(context, receiver)
.setAction(options.getId()); .setAction(options.getIdStr());
PendingIntent pi = PendingIntent. PendingIntent pi = PendingIntent.
getBroadcast(context, 0, intent, 0); getBroadcast(context, 0, intent, 0);
getAlarmMgr().cancel(pi); getAlarmMgr().cancel(pi);
getNotMgr().cancel(options.getIdAsInt()); getNotMgr().cancel(options.getId());
unpersist(); unpersist();
} }
...@@ -232,7 +228,7 @@ public class Notification { ...@@ -232,7 +228,7 @@ public class Notification {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void showNotification () { private void showNotification () {
int id = getOptions().getIdAsInt(); int id = getOptions().getId();
if (Build.VERSION.SDK_INT <= 15) { if (Build.VERSION.SDK_INT <= 15) {
// Notification for HoneyComb to ICS // Notification for HoneyComb to ICS
...@@ -251,26 +247,11 @@ public class Notification { ...@@ -251,26 +247,11 @@ public class Notification {
} }
/** /**
* Next trigger time.
*/
public long getNextTriggerTime() {
long triggerTime = options.getTriggerTime();
if (!isRepeating() || !isTriggered())
return triggerTime;
long interval = options.getRepeatInterval();
int triggerCount = getTriggerCountSinceSchedule();
return triggerTime + (triggerCount + 1) * interval;
}
/**
* Count of triggers since schedule. * Count of triggers since schedule.
*/ */
public int getTriggerCountSinceSchedule() { public int getTriggerCountSinceSchedule() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long initTriggerTime = options.getTriggerTime(); long triggerTime = options.getTriggerTime();
if (!wasInThePast()) if (!wasInThePast())
return 0; return 0;
...@@ -278,7 +259,7 @@ public class Notification { ...@@ -278,7 +259,7 @@ public class Notification {
if (!isRepeating()) if (!isRepeating())
return 1; return 1;
return (int) ((now - initTriggerTime) / options.getRepeatInterval()); return (int) ((now - triggerTime) / options.getRepeatInterval());
} }
/** /**
...@@ -294,6 +275,7 @@ public class Notification { ...@@ -294,6 +275,7 @@ public class Notification {
e.printStackTrace(); e.printStackTrace();
} }
json.remove("firstAt");
json.remove("updatedAt"); json.remove("updatedAt");
json.remove("soundUri"); json.remove("soundUri");
json.remove("iconUri"); json.remove("iconUri");
...@@ -309,7 +291,7 @@ public class Notification { ...@@ -309,7 +291,7 @@ public class Notification {
private void persist () { private void persist () {
SharedPreferences.Editor editor = getPrefs().edit(); SharedPreferences.Editor editor = getPrefs().edit();
editor.putString(options.getId(), options.toString()); editor.putString(options.getIdStr(), options.toString());
if (Build.VERSION.SDK_INT < 9) { if (Build.VERSION.SDK_INT < 9) {
editor.commit(); editor.commit();
...@@ -324,7 +306,7 @@ public class Notification { ...@@ -324,7 +306,7 @@ public class Notification {
private void unpersist () { private void unpersist () {
SharedPreferences.Editor editor = getPrefs().edit(); SharedPreferences.Editor editor = getPrefs().edit();
editor.remove(options.getId()); editor.remove(options.getIdStr());
if (Build.VERSION.SDK_INT < 9) { if (Build.VERSION.SDK_INT < 9) {
editor.commit(); editor.commit();
......
...@@ -23,16 +23,16 @@ ...@@ -23,16 +23,16 @@
package de.appplant.cordova.plugin.notification; package de.appplant.cordova.plugin.notification;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
/** /**
* Wrapper around the JSON object passed through JS which contains all * Wrapper around the JSON object passed through JS which contains all
* possible option values. Class provides simple readers and more advanced * possible option values. Class provides simple readers and more advanced
...@@ -189,35 +189,34 @@ public class Options { ...@@ -189,35 +189,34 @@ public class Options {
} }
/** /**
* Trigger date in milliseconds. * ID for the local notification as a number.
*/ */
public long getTriggerTime() { public Integer getId() {
return options.optLong("at", 0) * 1000; return options.optInt("id", 0);
} }
/** /**
* Trigger date. * ID for the local notification as a string.
*/ */
public Date getTriggerDate() { public String getIdStr() {
return new Date(getTriggerTime()); return getId().toString();
} }
/** /**
* ID for the local notification. * Trigger date.
*/ */
public String getId() { public Date getTriggerDate() {
return options.optString("id", "0"); return new Date(getTriggerTime());
} }
/** /**
* ID for the local notification. * Trigger date in milliseconds.
*/ */
public int getIdAsInt() { public long getTriggerTime() {
try { return Math.max(
return Integer.parseInt(getId()); System.currentTimeMillis(),
} catch (Exception ignore) { options.optLong("at", 0) * 1000
return 0; );
}
} }
/** /**
......
...@@ -42,11 +42,6 @@ public class TriggerReceiver extends AbstractTriggerReceiver { ...@@ -42,11 +42,6 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
*/ */
@Override @Override
public void onTrigger (Notification notification, boolean updated) { public void onTrigger (Notification notification, boolean updated) {
if (notification.isRepeating()) {
notification.reschedule();
}
notification.show(); notification.show();
} }
......
...@@ -61,6 +61,13 @@ ...@@ -61,6 +61,13 @@
// List all ids from all triggered notifications // List all ids from all triggered notifications
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command; - (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;
// Propertys for given local notification
- (void) getSingle:(CDVInvokedUrlCommand*)command;
// Propertya for given scheduled notification
- (void) getSingleScheduled:(CDVInvokedUrlCommand*)command;
// Propertys for given triggered notification
- (void) getSingleTriggered:(CDVInvokedUrlCommand*)command;
// Property list for given local notifications // Property list for given local notifications
- (void) getAll:(CDVInvokedUrlCommand*)command; - (void) getAll:(CDVInvokedUrlCommand*)command;
// Property list for given scheduled notifications // Property list for given scheduled notifications
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSDictionary* options in notifications) { for (NSDictionary* options in notifications) {
NSString* id = [options objectForKey:@"id"]; NSNumber* id = [options objectForKey:@"id"];
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSString* id in command.arguments) { for (NSNumber* id in command.arguments) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
- (void) clear:(CDVInvokedUrlCommand*)command - (void) clear:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSString* id in command.arguments) { for (NSNumber* id in command.arguments) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [self.app localNotificationWithId:id]; notification = [self.app localNotificationWithId:id];
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
type:(APPLocalNotificationType)type; type:(APPLocalNotificationType)type;
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSString* id = [command argumentAtIndex:0]; NSNumber* id = [command argumentAtIndex:0];
BOOL exist; BOOL exist;
CDVPluginResult* result; CDVPluginResult* result;
...@@ -314,6 +314,28 @@ ...@@ -314,6 +314,28 @@
} }
/** /**
* Propertys for given local notification.
*/
- (void) getSingle:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeAll];
}
/**
* Propertya for given scheduled notification.
*/
- (void) getSingleScheduled:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeScheduled];
}
// Propertys for given triggered notification
- (void) getSingleTriggered:(CDVInvokedUrlCommand*)command
{
[self getOption:command byType:NotifcationTypeTriggered];
}
/**
* Property list for given local notifications. * Property list for given local notifications.
* *
* @param ids * @param ids
...@@ -347,6 +369,38 @@ ...@@ -347,6 +369,38 @@
} }
/** /**
* Propertys for given triggered notification.
*
* @param type
* Notification life cycle type
* @param ids
* The ID of the notification
*/
- (void) getOption:(CDVInvokedUrlCommand*)command
byType:(APPLocalNotificationType)type;
{
[self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments;
NSArray* notifications;
CDVPluginResult* result;
if (type == NotifcationTypeAll) {
notifications = [self.app localNotificationOptionsById:ids];
}
else {
notifications = [self.app localNotificationOptionsByType:type
andId:ids];
}
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:notifications[0]];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* Property list for given triggered notifications. * Property list for given triggered notifications.
* *
* @param type * @param type
...@@ -474,7 +528,7 @@ ...@@ -474,7 +528,7 @@
*/ */
- (void) cancelForerunnerLocalNotification:(UILocalNotification*)notification - (void) cancelForerunnerLocalNotification:(UILocalNotification*)notification
{ {
NSString* id = notification.options.id; NSNumber* id = notification.options.id;
UILocalNotification* forerunner; UILocalNotification* forerunner;
forerunner = [self.app localNotificationWithId:id]; forerunner = [self.app localNotificationWithId:id];
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
- (id) initWithDict:(NSDictionary*)dict; - (id) initWithDict:(NSDictionary*)dict;
@property (readonly, getter=id) NSString* id; @property (readonly, getter=id) NSNumber* id;
@property (readonly, getter=badgeNumber) NSInteger badgeNumber; @property (readonly, getter=badgeNumber) NSInteger badgeNumber;
@property (readonly, getter=alertBody) NSString* alertBody; @property (readonly, getter=alertBody) NSString* alertBody;
@property (readonly, getter=soundName) NSString* soundName; @property (readonly, getter=soundName) NSString* soundName;
......
...@@ -59,9 +59,11 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -59,9 +59,11 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
/** /**
* The notification's ID. * The notification's ID.
*/ */
- (NSString*) id - (NSNumber*) id
{ {
return [dict objectForKey:@"id"]; NSInteger id = [[dict objectForKey:@"id"] integerValue];
return [NSNumber numberWithInteger:id];
} }
/** /**
...@@ -186,6 +188,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -186,6 +188,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
*/ */
- (NSDictionary*) userInfo - (NSDictionary*) userInfo
{ {
if ([dict objectForKey:@"updatedAt"]) {
NSMutableDictionary* data = [dict mutableCopy];
[data removeObjectForKey:@"updatedAt"];
return data;
}
return dict; return dict;
} }
......
...@@ -37,14 +37,14 @@ ...@@ -37,14 +37,14 @@
- (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type; - (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type;
// If local notification with ID exists // If local notification with ID exists
- (BOOL) localNotificationExist:(NSString*)id; - (BOOL) localNotificationExist:(NSNumber*)id;
// If local notification with ID and type exists // If local notification with ID and type exists
- (BOOL) localNotificationExist:(NSString*)id type:(APPLocalNotificationType)type; - (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type;
// Local notification by ID // Local notification by ID
- (UILocalNotification*) localNotificationWithId:(NSString*)id; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id;
// Local notification by ID and type // Local notification by ID and type
- (UILocalNotification*) localNotificationWithId:(NSString*)id andType:(APPLocalNotificationType)type; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type;
// Property list from all local notifications // Property list from all local notifications
- (NSArray*) localNotificationOptions; - (NSArray*) localNotificationOptions;
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
* @param id * @param id
* Notification ID * Notification ID
*/ */
- (BOOL) localNotificationExist:(NSString*)id - (BOOL) localNotificationExist:(NSNumber*)id
{ {
return [self localNotificationWithId:id] != NULL; return [self localNotificationWithId:id] != NULL;
} }
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (BOOL) localNotificationExist:(NSString*)id type:(APPLocalNotificationType)type - (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type
{ {
return [self localNotificationWithId:id andType:type] != NULL; return [self localNotificationWithId:id andType:type] != NULL;
} }
...@@ -182,13 +182,13 @@ ...@@ -182,13 +182,13 @@
* @param id * @param id
* Notification ID * Notification ID
*/ */
- (UILocalNotification*) localNotificationWithId:(NSString*)id - (UILocalNotification*) localNotificationWithId:(NSNumber*)id
{ {
NSArray* notifications = self.localNotifications; NSArray* notifications = self.localNotifications;
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
if ([notification.options.id isEqualToString:id]) { if ([notification.options.id isEqualToNumber:id]) {
return notification; return notification;
} }
} }
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (UILocalNotification*) localNotificationWithId:(NSString*)id andType:(APPLocalNotificationType)type - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type
{ {
UILocalNotification* notification = [self localNotificationWithId:id]; UILocalNotification* notification = [self localNotificationWithId:id];
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
return options; return options;
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
if (notification.type == type) { if (notification.type == type) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
...@@ -262,12 +262,12 @@ ...@@ -262,12 +262,12 @@
UILocalNotification* notification; UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids) for (NSNumber* id in ids)
{ {
notification = [self localNotificationWithId:id]; notification = [self localNotificationWithId:id];
if (notification) { if (notification) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
...@@ -287,12 +287,12 @@ ...@@ -287,12 +287,12 @@
UILocalNotification* notification; UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids) for (NSNumber* id in ids)
{ {
notification = [self localNotificationWithId:id]; notification = [self localNotificationWithId:id];
if (notification && notification.type == type) { if (notification && notification.type == type) {
[options addObject:notification.userInfo]; [options addObject:notification.options.userInfo];
} }
} }
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
*/ */
var Notifications = Windows.UI.Notifications, var proxy = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy');
applicationData = Windows.Storage.ApplicationData.current,
localSettings = applicationData.localSettings;
var Notifications = Windows.UI.Notifications;
exports.core = {
proxy.core = {
/** /**
* Executes all queued events. * Executes all queued events.
......
...@@ -209,6 +209,54 @@ exports.getTriggeredIds = function (success, error) { ...@@ -209,6 +209,54 @@ exports.getTriggeredIds = function (success, error) {
}; };
/** /**
* Propertys for given notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingle = function (success, error, ids) {
var notification = exports.core.getAll(ids)[0];
success(notification);
};
/**
* Propertys for given scheduled notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingleScheduled = function (success, error, ids) {
var notification = exports.core.getScheduled(ids)[0];
success(notification);
};
/**
* Propertys for given triggered notification.
*
* @param {Function} success
* Success callback
* @param {Function} error
* Error callback
* @param {int[]} ids
* List of local notification IDs
*/
exports.getSingleTriggered = function (success, error, ids) {
var notification = exports.core.getTriggered(ids)[0];
success(notification);
};
/**
* Property list for given notifications. * Property list for given notifications.
* If called without IDs, all notification will be returned. * If called without IDs, all notification will be returned.
* *
...@@ -259,11 +307,5 @@ exports.getTriggered = function (success, error, ids) { ...@@ -259,11 +307,5 @@ exports.getTriggered = function (success, error, ids) {
success(notifications); success(notifications);
}; };
/**
* Required for core module to access the proxy.
*/
exports.exports = function () {
return exports;
};
cordova.commandProxy.add('LocalNotification', exports); cordova.commandProxy.add('LocalNotification', exports);
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
*/ */
var channel = require('cordova/channel'); exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy').core;
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core; var channel = require('cordova/channel');
/*********** /***********
......
...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) { ...@@ -172,9 +172,7 @@ exports.cancelAll = function (callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isPresent = function (id, callback, scope) { exports.isPresent = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isPresent', id || 0, callback, scope);
this.exec('isPresent', notId, callback, scope);
}; };
/** /**
...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) { ...@@ -188,9 +186,7 @@ exports.isPresent = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isScheduled = function (id, callback, scope) { exports.isScheduled = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isScheduled', id || 0, callback, scope);
this.exec('isScheduled', notId, callback, scope);
}; };
/** /**
...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -204,9 +200,7 @@ exports.isScheduled = function (id, callback, scope) {
* The scope for the callback function * The scope for the callback function
*/ */
exports.isTriggered = function (id, callback, scope) { exports.isTriggered = function (id, callback, scope) {
var notId = (id || '0').toString(); this.exec('isTriggered', id || 0, callback, scope);
this.exec('isTriggered', notId, callback, scope);
}; };
/** /**
...@@ -275,7 +269,7 @@ exports.get = function () { ...@@ -275,7 +269,7 @@ exports.get = function () {
scope = args[2]; scope = args[2];
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingle', ids.toString(), callback, scope); this.exec('getSingle', Number(ids), callback, scope);
return; return;
} }
...@@ -323,7 +317,7 @@ exports.getScheduled = function () { ...@@ -323,7 +317,7 @@ exports.getScheduled = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleScheduled', ids.toString(), callback, scope); this.exec('getSingleScheduled', Number(ids), callback, scope);
return; return;
} }
...@@ -371,7 +365,7 @@ exports.getTriggered = function () { ...@@ -371,7 +365,7 @@ exports.getTriggered = function () {
} }
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
this.exec('getSingleTriggered', ids.toString(), callback, scope); this.exec('getSingleTriggered', Number(ids), callback, scope);
return; return;
} }
......
...@@ -35,7 +35,7 @@ exports._defaults = { ...@@ -35,7 +35,7 @@ exports._defaults = {
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
badge: 0, badge: 0,
id: "0", id: 0,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined at: undefined
...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) { ...@@ -87,7 +87,9 @@ exports.mergeWithDefaults = function (options) {
options.text = this.getValueFor(options, 'text', 'message'); options.text = this.getValueFor(options, 'text', 'message');
options.data = this.getValueFor(options, 'data', 'json'); options.data = this.getValueFor(options, 'data', 'json');
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel'); if (defaults.hasOwnProperty('autoClear')) {
options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
}
if (options.autoClear !== true && options.ongoing) { if (options.autoClear !== true && options.ongoing) {
options.autoClear = false; options.autoClear = false;
...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) { ...@@ -131,8 +133,9 @@ exports.convertProperties = function (options) {
if (options.id) { if (options.id) {
if (isNaN(options.id)) { if (isNaN(options.id)) {
options.id = this.getDefaults().id; options.id = this.getDefaults().id;
console.warn('Id is not a number: ' + options.id);
} else { } else {
options.id = options.id.toString(); options.id = Number(options.id);
} }
} }
...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) { ...@@ -147,13 +150,18 @@ exports.convertProperties = function (options) {
if (options.badge) { if (options.badge) {
if (isNaN(options.badge)) { if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge; options.badge = this.getDefaults().badge;
console.warn('Badge number is not a number: ' + options.id);
} else { } else {
options.badge = Number(options.badge); options.badge = Number(options.badge);
} }
} }
if (typeof options.at == 'object') { if (options.at) {
options.at = Math.round(options.at.getTime()/1000); if (typeof options.at == 'object') {
options.at = options.at.getTime();
}
options.at = Math.round(options.at/1000);
} }
if (typeof options.data == 'object') { if (typeof options.data == 'object') {
...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) { ...@@ -175,6 +183,7 @@ exports.convertProperties = function (options) {
* The new callback function * The new callback function
*/ */
exports.createCallbackFn = function (callbackFn, scope) { exports.createCallbackFn = function (callbackFn, scope) {
if (typeof callbackFn != 'function') if (typeof callbackFn != 'function')
return; return;
...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -184,17 +193,17 @@ exports.createCallbackFn = function (callbackFn, scope) {
}; };
/** /**
* Convert the IDs to Strings. * Convert the IDs to numbers.
* *
* @param {String/Number[]} ids * @param {String/Number[]} ids
* *
* @return Array of Strings * @return Array of Numbers
*/ */
exports.convertIds = function (ids) { exports.convertIds = function (ids) {
var convertedIds = []; var convertedIds = [];
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
convertedIds.push(ids[i].toString()); convertedIds.push(Number(ids[i]));
} }
return convertedIds; return convertedIds;
......
...@@ -9,15 +9,15 @@ ...@@ -9,15 +9,15 @@
"parents": { "parents": {
"/*": [ "/*": [
{ {
"xml": "<feature name=\"Toast\"><param name=\"ios-package\" value=\"Toast\" /></feature>", "xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>",
"count": 1 "count": 1
}, },
{ {
"xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>", "xml": "<feature name=\"LocalNotification\"><param name=\"ios-package\" onload=\"true\" value=\"APPLocalNotification\" /><param name=\"onload\" value=\"true\" /></feature>",
"count": 1 "count": 1
}, },
{ {
"xml": "<feature name=\"LocalNotification\"><param name=\"ios-package\" onload=\"true\" value=\"APPLocalNotification\" /><param name=\"onload\" value=\"true\" /></feature>", "xml": "<feature name=\"Toast\"><param name=\"ios-package\" value=\"Toast\" /></feature>",
"count": 1 "count": 1
} }
] ]
...@@ -30,17 +30,16 @@ ...@@ -30,17 +30,16 @@
"xml": false, "xml": false,
"count": 1 "count": 1
} }
], ]
"MessageUI.framework": []
} }
} }
} }
}, },
"installed_plugins": { "installed_plugins": {
"nl.x-services.plugins.toast": { "de.appplant.cordova.plugin.local-notification": {
"PACKAGE_NAME": "de.appplant.localnotification.example" "PACKAGE_NAME": "de.appplant.localnotification.example"
}, },
"de.appplant.cordova.plugin.local-notification": { "nl.x-services.plugins.toast": {
"PACKAGE_NAME": "de.appplant.localnotification.example" "PACKAGE_NAME": "de.appplant.localnotification.example"
} }
}, },
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
"files": {} "files": {}
}, },
"installed_plugins": { "installed_plugins": {
"de.appplant.cordova.plugin.local-notification": { "nl.x-services.plugins.toast": {
"PACKAGE_NAME": "NotificationExample" "PACKAGE_NAME": "NotificationExample"
}, },
"nl.x-services.plugins.toast": { "de.appplant.cordova.plugin.local-notification": {
"PACKAGE_NAME": "NotificationExample" "PACKAGE_NAME": "NotificationExample"
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment