Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
9a6d89b5
Commit
9a6d89b5
authored
Oct 30, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added back update method for Android
parent
4fe4e786
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
81 deletions
+100
-81
LocalNotification.java
src/android/LocalNotification.java
+24
-24
TriggerReceiver.java
src/android/TriggerReceiver.java
+6
-2
Manager.java
src/android/notification/Manager.java
+18
-52
Notification.java
src/android/notification/Notification.java
+45
-0
Options.java
src/android/notification/Options.java
+0
-1
local-notification-util.js
www/local-notification-util.js
+7
-2
No files found.
src/android/LocalNotification.java
View file @
9a6d89b5
...
...
@@ -157,10 +157,10 @@ public class LocalNotification extends CordovaPlugin {
schedule
(
args
);
command
.
success
();
}
else
//
if (action.equals("update")) {
//
update(args);
//
command.success();
//
} else
if
(
action
.
equals
(
"update"
))
{
update
(
args
);
command
.
success
();
}
else
if
(
action
.
equals
(
"cancel"
))
{
cancel
(
args
);
command
.
success
();
...
...
@@ -290,26 +290,26 @@ public class LocalNotification extends CordovaPlugin {
}
}
/
/ /
**
//
* Update multiple local notifications.
//
*
//
* @param updates
//
* Notification properties including their IDs
//
*/
//
private void update (JSONArray updates) {
//
for (int i = 0; i < updates.length(); i++) {
//
JSONObject update = updates.optJSONObject(i);
// int id
= update.optInt("id", 0);
//
Notification notification =
//
getNotMgr().update(id, update, TriggerReceiver.class);
//
if (notification == null)
//
continue;
//
fireEvent("update", notification);
//
}
//
}
/**
* Update multiple local notifications.
*
* @param updates
* Notification properties including their IDs
*/
private
void
update
(
JSONArray
updates
)
{
for
(
int
i
=
0
;
i
<
updates
.
length
();
i
++)
{
JSONObject
update
=
updates
.
optJSONObject
(
i
);
int
id
=
update
.
optInt
(
"id"
,
0
);
Notification
notification
=
getNotMgr
().
update
(
id
,
update
,
TriggerReceiver
.
class
);
if
(
notification
==
null
)
continue
;
fireEvent
(
"update"
,
notification
);
}
}
/**
* Cancel multiple local notifications.
...
...
src/android/TriggerReceiver.java
View file @
9a6d89b5
...
...
@@ -45,14 +45,18 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
*/
@Override
public
void
onTrigger
(
Notification
notification
,
Bundle
bundle
)
{
int
badge
=
notification
.
getOptions
().
getBadgeNumber
();
boolean
isUpdate
=
bundle
.
getBoolean
(
Notification
.
EXTRA_UPDATE
,
false
);
int
badge
=
notification
.
getOptions
().
getBadgeNumber
();
if
(
badge
>
0
)
{
Manager
.
getInstance
(
notification
.
getContext
()).
setBadge
(
badge
);
}
notification
.
show
();
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
if
(!
isUpdate
)
{
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
}
}
/**
...
...
src/android/notification/Manager.java
View file @
9a6d89b5
...
...
@@ -120,33 +120,23 @@ public final class Manager {
mgr
.
createNotificationChannel
(
channel
);
}
// /**
// * Clear local notification specified by ID.
// *
// * @param id
// * The notification ID
// * @param updates
// * JSON object with notification options
// * @param receiver
// * Receiver to handle the trigger event
// */
// public Notification update (int id, JSONObject updates, Class<?> receiver) {
// Notification notification = get(id);
// if (notification == null)
// return null;
// notification.cancel();
// JSONObject options = mergeJSONObjects(
// notification.getOptions().getDict(), updates);
// try {
// options.put("updated", true);
// } catch (JSONException ignore) {}
// return schedule(options, receiver);
// }
/**
* Update local notification specified by ID.
*
* @param id The notification ID.
* @param updates JSON object with notification options.
* @param receiver Receiver to handle the trigger event.
*/
public
Notification
update
(
int
id
,
JSONObject
updates
,
Class
<?>
receiver
)
{
Notification
notification
=
get
(
id
);
if
(
notification
==
null
)
return
null
;
notification
.
update
(
updates
,
receiver
);
return
notification
;
}
/**
* Clear local notification specified by ID.
...
...
@@ -386,30 +376,6 @@ public final class Manager {
return
new
Notification
(
context
,
options
);
}
// /**
// * Merge two JSON objects.
// *
// * @param obj1
// * JSON object
// * @param obj2
// * JSON object with new options
// */
// private JSONObject mergeJSONObjects (JSONObject obj1, JSONObject obj2) {
// Iterator it = obj2.keys();
// while (it.hasNext()) {
// try {
// String key = (String)it.next();
// obj1.put(key, obj2.opt(key));
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// return obj1;
// }
/**
* Set the badge number of the app icon.
*
...
...
@@ -444,7 +410,7 @@ public final class Manager {
private
NotificationManagerCompat
getNotCompMgr
()
{
return
NotificationManagerCompat
.
from
(
context
);
}
/**
* Notification manager compat for the application.
*/
...
...
src/android/notification/Notification.java
View file @
9a6d89b5
...
...
@@ -39,6 +39,7 @@ import org.json.JSONObject;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -62,6 +63,9 @@ public final class Notification {
// Extra key for the id
public
static
final
String
EXTRA_ID
=
"NOTIFICATION_ID"
;
// Extra key for the update flag
public
static
final
String
EXTRA_UPDATE
=
"NOTIFICATION_UPDATE"
;
// Key for private preferences
static
final
String
PREF_KEY_ID
=
"NOTIFICATION_ID"
;
...
...
@@ -288,6 +292,27 @@ public final class Notification {
}
/**
* Update the notification properties.
*
* @param updates The properties to update.
* @param receiver Receiver to handle the trigger event.
*/
void
update
(
JSONObject
updates
,
Class
<?>
receiver
)
{
mergeJSONObjects
(
updates
);
persist
(
null
);
if
(
getType
()
!=
Type
.
TRIGGERED
)
return
;
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
PREF_KEY_ID
+
options
.
getId
())
.
putExtra
(
Notification
.
EXTRA_ID
,
options
.
getId
())
.
putExtra
(
Notification
.
EXTRA_UPDATE
,
true
);
trigger
(
intent
,
receiver
);
}
/**
* Encode options to JSON.
*/
public
String
toString
()
{
...
...
@@ -318,6 +343,9 @@ public final class Notification {
editor
.
putString
(
id
,
options
.
toString
());
editor
.
apply
();
if
(
ids
==
null
)
return
;
editor
=
getPrefs
(
PREF_KEY_PID
).
edit
();
editor
.
putStringSet
(
id
,
ids
);
editor
.
apply
();
...
...
@@ -355,6 +383,23 @@ public final class Notification {
}
/**
* Merge two JSON objects.
*/
private
void
mergeJSONObjects
(
JSONObject
updates
)
{
JSONObject
dict
=
options
.
getDict
();
Iterator
it
=
updates
.
keys
();
while
(
it
.
hasNext
())
{
try
{
String
key
=
(
String
)
it
.
next
();
dict
.
put
(
key
,
updates
.
opt
(
key
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* Shared private preferences for the application.
*/
private
SharedPreferences
getPrefs
(
String
key
)
{
...
...
src/android/notification/Options.java
View file @
9a6d89b5
...
...
@@ -31,7 +31,6 @@ import android.support.v4.media.session.MediaSessionCompat;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONArray
;
import
java.io.IOException
;
import
java.util.ArrayList
;
...
...
www/local-notification-util.js
View file @
9a6d89b5
...
...
@@ -164,12 +164,11 @@ exports.convertProperties = function (options) {
* @return [ Map ] Interaction object with category & actions.
*/
exports
.
convertActions
=
function
(
options
)
{
var
actions
=
[];
if
(
!
options
.
actions
)
return
null
;
var
actions
=
[];
for
(
var
action
of
options
.
actions
)
{
if
(
!
action
.
id
)
{
...
...
@@ -200,6 +199,9 @@ exports.convertTrigger = function (options) {
var
trigger
=
options
.
trigger
||
{},
date
=
this
.
getValueFor
(
trigger
,
'at'
,
'firstAt'
,
'date'
);
if
(
!
options
.
trigger
)
return
;
if
(
!
trigger
.
type
)
{
trigger
.
type
=
trigger
.
center
?
'location'
:
'calendar'
;
}
...
...
@@ -262,6 +264,9 @@ exports.convertProgressBar = function (options) {
var
isAndroid
=
device
.
platform
==
'Android'
,
cfg
=
options
.
progressBar
;
if
(
cfg
===
undefined
)
return
;
if
(
typeof
cfg
===
'boolean'
)
{
cfg
=
options
.
progressBar
=
{
enabled
:
cfg
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment