Commit 9ad2292b by Sebastián Katzer

Each LocalNotificationOptions object needs to be created either with an intent…

Each LocalNotificationOptions object needs to be created either with an intent or context to get informed about the package name. The `parse` method must be called to read the options passed through javascript.
parent 39b26a6d
......@@ -18,6 +18,7 @@ import org.json.JSONObject;
import android.content.Intent;
import android.content.Context;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.SharedPreferences;
......@@ -53,7 +54,8 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancel")) {
JSONObject arguments = args.getJSONObject(0);
LocalNotificationOptions options = new LocalNotificationOptions(arguments);
Activity activity = cordova.getActivity();
LocalNotificationOptions options = new LocalNotificationOptions(activity).parse(arguments);
String alarmId = options.getId();
cancel(alarmId);
......@@ -77,7 +79,8 @@ public class LocalNotification extends CordovaPlugin {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
JSONObject arguments = args.optJSONObject(0);
LocalNotificationOptions options = new LocalNotificationOptions(arguments);
Activity activity = cordova.getActivity();
LocalNotificationOptions options = new LocalNotificationOptions(activity).parse(arguments);
persist(options.getId(), args);
add(options);
......
......@@ -14,6 +14,7 @@ import java.util.Date;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlarmManager;
import android.content.Context;
import android.media.RingtoneManager;
......@@ -33,28 +34,18 @@ public class LocalNotificationOptions {
private long interval = 0;
private long date = 0;
/**
* Parse options passed from javascript part of this plugin.
*/
LocalNotificationOptions (JSONObject options) {
packageName = LocalNotification.cordova.getActivity().getPackageName();
parse(options);
LocalNotificationOptions (Activity activity) {
packageName = activity.getPackageName();
}
/**
* Parse options passed from javascript part of this plugin.
*/
LocalNotificationOptions (JSONObject options, Context context) {
LocalNotificationOptions (Context context) {
packageName = context.getPackageName();
parse(options);
}
/**
* Parst die übergebenen Eigenschaften.
*/
private void parse (JSONObject options) {
public LocalNotificationOptions parse (JSONObject options) {
String repeat = options.optString("repeat");
this.options = options;
......@@ -70,6 +61,8 @@ public class LocalNotificationOptions {
} else if (repeat.equalsIgnoreCase("yearly")) {
interval = AlarmManager.INTERVAL_DAY*365;
}
return this;
}
/**
......
......@@ -47,7 +47,7 @@ public class LocalNotificationReceiver extends BroadcastReceiver {
try {
args = new JSONObject(bundle.getString(OPTIONS));
options = new LocalNotificationOptions(args, context);
options = new LocalNotificationOptions(context).parse(args);
} catch (JSONException e) {}
this.context = context;
......
......@@ -48,7 +48,7 @@ public class LocalNotificationRestore extends BroadcastReceiver {
try {
args = new JSONObject(alarms.getString(alarmId, ""));
options = new LocalNotificationOptions(args, context);
options = new LocalNotificationOptions(context).parse(args);
LocalNotification.add(options);
} catch (JSONException e) {}
......
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