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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
75 deletions
+94
-75
LocalNotification.java
src/android/LocalNotification.java
+21
-21
TriggerReceiver.java
src/android/TriggerReceiver.java
+4
-0
Manager.java
src/android/notification/Manager.java
+17
-51
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 {
...
@@ -157,10 +157,10 @@ public class LocalNotification extends CordovaPlugin {
schedule
(
args
);
schedule
(
args
);
command
.
success
();
command
.
success
();
}
else
}
else
//
if (action.equals("update")) {
if
(
action
.
equals
(
"update"
))
{
//
update(args);
update
(
args
);
//
command.success();
command
.
success
();
//
} else
}
else
if
(
action
.
equals
(
"cancel"
))
{
if
(
action
.
equals
(
"cancel"
))
{
cancel
(
args
);
cancel
(
args
);
command
.
success
();
command
.
success
();
...
@@ -290,26 +290,26 @@ public class LocalNotification extends CordovaPlugin {
...
@@ -290,26 +290,26 @@ public class LocalNotification extends CordovaPlugin {
}
}
}
}
/
/ /
**
/**
//
* Update multiple local notifications.
* Update multiple local notifications.
//
*
*
//
* @param updates
* @param updates
//
* Notification properties including their IDs
* Notification properties including their IDs
//
*/
*/
//
private void update (JSONArray updates) {
private
void
update
(
JSONArray
updates
)
{
//
for (int i = 0; i < updates.length(); i++) {
for
(
int
i
=
0
;
i
<
updates
.
length
();
i
++)
{
//
JSONObject update = updates.optJSONObject(i);
JSONObject
update
=
updates
.
optJSONObject
(
i
);
// int id
= update.optInt("id", 0);
int
id
=
update
.
optInt
(
"id"
,
0
);
//
Notification notification =
Notification
notification
=
//
getNotMgr().update(id, update, TriggerReceiver.class);
getNotMgr
().
update
(
id
,
update
,
TriggerReceiver
.
class
);
//
if (notification == null)
if
(
notification
==
null
)
//
continue;
continue
;
//
fireEvent("update", notification);
fireEvent
(
"update"
,
notification
);
//
}
}
//
}
}
/**
/**
* Cancel multiple local notifications.
* Cancel multiple local notifications.
...
...
src/android/TriggerReceiver.java
View file @
9a6d89b5
...
@@ -45,6 +45,7 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
...
@@ -45,6 +45,7 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
*/
*/
@Override
@Override
public
void
onTrigger
(
Notification
notification
,
Bundle
bundle
)
{
public
void
onTrigger
(
Notification
notification
,
Bundle
bundle
)
{
boolean
isUpdate
=
bundle
.
getBoolean
(
Notification
.
EXTRA_UPDATE
,
false
);
int
badge
=
notification
.
getOptions
().
getBadgeNumber
();
int
badge
=
notification
.
getOptions
().
getBadgeNumber
();
if
(
badge
>
0
)
{
if
(
badge
>
0
)
{
...
@@ -52,8 +53,11 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
...
@@ -52,8 +53,11 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
}
}
notification
.
show
();
notification
.
show
();
if
(!
isUpdate
)
{
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
}
}
}
/**
/**
* Build notification specified by options.
* Build notification specified by options.
...
...
src/android/notification/Manager.java
View file @
9a6d89b5
...
@@ -120,33 +120,23 @@ public final class Manager {
...
@@ -120,33 +120,23 @@ public final class Manager {
mgr
.
createNotificationChannel
(
channel
);
mgr
.
createNotificationChannel
(
channel
);
}
}
// /**
/**
// * Clear local notification specified by ID.
* Update local notification specified by ID.
// *
*
// * @param id
* @param id The notification ID.
// * The notification ID
* @param updates JSON object with notification options.
// * @param updates
* @param receiver Receiver to handle the trigger event.
// * JSON object with notification options
*/
// * @param receiver
public
Notification
update
(
int
id
,
JSONObject
updates
,
Class
<?>
receiver
)
{
// * Receiver to handle the trigger event
Notification
notification
=
get
(
id
);
// */
// public Notification update (int id, JSONObject updates, Class<?> receiver) {
if
(
notification
==
null
)
// Notification notification = get(id);
return
null
;
// if (notification == null)
notification
.
update
(
updates
,
receiver
);
// return null;
return
notification
;
// notification.cancel();
}
// JSONObject options = mergeJSONObjects(
// notification.getOptions().getDict(), updates);
// try {
// options.put("updated", true);
// } catch (JSONException ignore) {}
// return schedule(options, receiver);
// }
/**
/**
* Clear local notification specified by ID.
* Clear local notification specified by ID.
...
@@ -386,30 +376,6 @@ public final class Manager {
...
@@ -386,30 +376,6 @@ public final class Manager {
return
new
Notification
(
context
,
options
);
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.
* Set the badge number of the app icon.
*
*
...
...
src/android/notification/Notification.java
View file @
9a6d89b5
...
@@ -39,6 +39,7 @@ import org.json.JSONObject;
...
@@ -39,6 +39,7 @@ import org.json.JSONObject;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -62,6 +63,9 @@ public final class Notification {
...
@@ -62,6 +63,9 @@ public final class Notification {
// Extra key for the id
// Extra key for the id
public
static
final
String
EXTRA_ID
=
"NOTIFICATION_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
// Key for private preferences
static
final
String
PREF_KEY_ID
=
"NOTIFICATION_ID"
;
static
final
String
PREF_KEY_ID
=
"NOTIFICATION_ID"
;
...
@@ -288,6 +292,27 @@ public final class Notification {
...
@@ -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.
* Encode options to JSON.
*/
*/
public
String
toString
()
{
public
String
toString
()
{
...
@@ -318,6 +343,9 @@ public final class Notification {
...
@@ -318,6 +343,9 @@ public final class Notification {
editor
.
putString
(
id
,
options
.
toString
());
editor
.
putString
(
id
,
options
.
toString
());
editor
.
apply
();
editor
.
apply
();
if
(
ids
==
null
)
return
;
editor
=
getPrefs
(
PREF_KEY_PID
).
edit
();
editor
=
getPrefs
(
PREF_KEY_PID
).
edit
();
editor
.
putStringSet
(
id
,
ids
);
editor
.
putStringSet
(
id
,
ids
);
editor
.
apply
();
editor
.
apply
();
...
@@ -355,6 +383,23 @@ public final class Notification {
...
@@ -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.
* Shared private preferences for the application.
*/
*/
private
SharedPreferences
getPrefs
(
String
key
)
{
private
SharedPreferences
getPrefs
(
String
key
)
{
...
...
src/android/notification/Options.java
View file @
9a6d89b5
...
@@ -31,7 +31,6 @@ import android.support.v4.media.session.MediaSessionCompat;
...
@@ -31,7 +31,6 @@ import android.support.v4.media.session.MediaSessionCompat;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
org.json.JSONArray
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
...
www/local-notification-util.js
View file @
9a6d89b5
...
@@ -164,12 +164,11 @@ exports.convertProperties = function (options) {
...
@@ -164,12 +164,11 @@ exports.convertProperties = function (options) {
* @return [ Map ] Interaction object with category & actions.
* @return [ Map ] Interaction object with category & actions.
*/
*/
exports
.
convertActions
=
function
(
options
)
{
exports
.
convertActions
=
function
(
options
)
{
var
actions
=
[];
if
(
!
options
.
actions
)
if
(
!
options
.
actions
)
return
null
;
return
null
;
var
actions
=
[];
for
(
var
action
of
options
.
actions
)
{
for
(
var
action
of
options
.
actions
)
{
if
(
!
action
.
id
)
{
if
(
!
action
.
id
)
{
...
@@ -200,6 +199,9 @@ exports.convertTrigger = function (options) {
...
@@ -200,6 +199,9 @@ exports.convertTrigger = function (options) {
var
trigger
=
options
.
trigger
||
{},
var
trigger
=
options
.
trigger
||
{},
date
=
this
.
getValueFor
(
trigger
,
'at'
,
'firstAt'
,
'date'
);
date
=
this
.
getValueFor
(
trigger
,
'at'
,
'firstAt'
,
'date'
);
if
(
!
options
.
trigger
)
return
;
if
(
!
trigger
.
type
)
{
if
(
!
trigger
.
type
)
{
trigger
.
type
=
trigger
.
center
?
'location'
:
'calendar'
;
trigger
.
type
=
trigger
.
center
?
'location'
:
'calendar'
;
}
}
...
@@ -262,6 +264,9 @@ exports.convertProgressBar = function (options) {
...
@@ -262,6 +264,9 @@ exports.convertProgressBar = function (options) {
var
isAndroid
=
device
.
platform
==
'Android'
,
var
isAndroid
=
device
.
platform
==
'Android'
,
cfg
=
options
.
progressBar
;
cfg
=
options
.
progressBar
;
if
(
cfg
===
undefined
)
return
;
if
(
typeof
cfg
===
'boolean'
)
{
if
(
typeof
cfg
===
'boolean'
)
{
cfg
=
options
.
progressBar
=
{
enabled
:
cfg
};
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