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
e00467af
Commit
e00467af
authored
May 02, 2015
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix & simplify repeating on Android
parent
30f8f6aa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
44 deletions
+24
-44
Notification.java
src/android/notification/Notification.java
+9
-27
Options.java
src/android/notification/Options.java
+15
-12
TriggerReceiver.java
src/android/notification/TriggerReceiver.java
+0
-5
No files found.
src/android/notification/Notification.java
View file @
e00467af
...
@@ -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
}
}
...
@@ -162,7 +162,7 @@ public class Notification {
...
@@ -162,7 +162,7 @@ public class Notification {
* Schedule the local notification.
* Schedule the local notification.
*/
*/
public
void
schedule
()
{
public
void
schedule
()
{
long
triggerTime
=
getNex
tTriggerTime
();
long
triggerTime
=
options
.
ge
tTriggerTime
();
persist
();
persist
();
...
@@ -174,15 +174,11 @@ public class Notification {
...
@@ -174,15 +174,11 @@ public class Notification {
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
);
}
}
}
}
...
@@ -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
initT
riggerTime
=
options
.
getTriggerTime
();
long
t
riggerTime
=
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
-
initT
riggerTime
)
/
options
.
getRepeatInterval
());
return
(
int
)
((
now
-
t
riggerTime
)
/
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"
);
...
...
src/android/notification/Options.java
View file @
e00467af
...
@@ -189,31 +189,34 @@ public class Options {
...
@@ -189,31 +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
.
opt
Long
(
"at"
,
0
)
*
1000
;
return
options
.
opt
Int
(
"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 as a number
.
*
Trigger date
.
*/
*/
public
Integer
getId
()
{
public
Date
getTriggerDate
()
{
return
options
.
optInt
(
"id"
,
0
);
return
new
Date
(
getTriggerTime
()
);
}
}
/**
/**
*
ID for the local notification as a string
.
*
Trigger date in milliseconds
.
*/
*/
public
String
getIdStr
()
{
public
long
getTriggerTime
()
{
return
getId
().
toString
();
return
Math
.
max
(
System
.
currentTimeMillis
(),
options
.
optLong
(
"at"
,
0
)
*
1000
);
}
}
/**
/**
...
...
src/android/notification/TriggerReceiver.java
View file @
e00467af
...
@@ -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
();
}
}
...
...
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