Commit 9ad2292b authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

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
Loading
Loading
Loading
Loading
+5 −2
Changes for src/android/LocalNotification.java: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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);
+7 −14
Changes for src/android/LocalNotificationOptions.java: 7 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -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;
    }

    /**
+1 −1
Changes for src/android/LocalNotificationReceiver.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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;
+1 −1
Changes for src/android/LocalNotificationRestore.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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) {}