Skip to content

Commit 76a87bb

Browse files
committed
forward timer added
1 parent 42eb969 commit 76a87bb

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ AndroidManifest
3131
import { TimerNotification, onEvent } from "react-native-custom-timer-notification";
3232

3333
// ...
34+
3435
// onclick and cancel listner
3536
onEvent(event=>{
3637
console.log(event)
3738
});
3839

40+
// Remove timer
41+
RemoveTimer(160211114);
42+
43+
//Trigger notification
3944
TimerNotification({
4045
payload: JSON.stringify('notificationOpen?.data'),
4146
title: 'My notification',
@@ -44,6 +49,7 @@ console.log(event)
4449
remove: false, // optional
4550
foreground: false,
4651
date: new Date(Date.now() + 20000),
52+
isCountDown: true, // false for positive timer
4753
});
4854
```
4955

android/src/main/java/com/reactnativecustomtimernotification/CustomTimerNotificationModule.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,21 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
7575
Log.i("ReactSystemNotification", "NotificationModule: sendEvent (to JS): $eventName")
7676
}
7777

78-
override fun getName(): String {
78+
override fun getName(): String {
7979
return "CustomTimerNotification"
8080
}
81-
fun convert(n:String):String {
81+
82+
fun convert(n:String):String {
8283
if (n.length == 1) return "0" + n;
8384
return n
8485
}
8586

86-
87-
fun notificationPop(objectData:ReadableMap,remainingTime:String,visbleTimer:Boolean):NotificationCompat.Builder{
87+
fun notificationPop(objectData:ReadableMap,remainingTime:String,visbleTimer:Boolean):NotificationCompat.Builder{
8888
val title = objectData.getString("title");
8989
val body = objectData.getString("body");
9090
val payload = objectData.getString("payload");
9191
val id =objectData.getInt("id");
92+
val isCountDown = objectData.getBoolean("isCountDown")
9293

9394
val datetime = objectData.getString("date")
9495
val sdf = SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH)
@@ -120,7 +121,7 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
120121
notificationLayout.setTextViewText(R.id.text,body)
121122

122123
// notificationLayout.setTextViewText(R.id.timer,remainingTime)
123-
notificationLayout.setChronometerCountDown(R.id.simpleChronometer, true);
124+
notificationLayout.setChronometerCountDown(R.id.simpleChronometer, isCountDown);
124125
notificationLayout.setChronometer(R.id.simpleChronometer, remainingTime, ("%tM:%tS"), true);
125126

126127

@@ -151,6 +152,7 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
151152
.setPriority(NotificationCompat.PRIORITY_HIGH)
152153
.setWhen(endTime.getTimeInMillis());
153154
val handler = Handler()
155+
if(isCountDown)
154156
handler.postDelayed({
155157
notificationLayout.setChronometerCountDown(R.id.simpleChronometer, true);
156158
notificationLayout.setChronometer(R.id.simpleChronometer, remainingTime, ("%tM:%tS"), false);
@@ -173,11 +175,21 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
173175
return notificationBuilder
174176
}
175177

176-
fun updatePop(objectData:ReadableMap,remainingTime:String,visbleTimer:Boolean){
178+
fun updatePop(objectData:ReadableMap,remainingTime:String,visbleTimer:Boolean){
177179
val id =objectData.getInt("id");
178180
val notificationBuilder:NotificationCompat.Builder = notificationPop(objectData,remainingTime,visbleTimer)
179181
notificationManager.notify(id,notificationBuilder.build())
180182
}
183+
184+
@ReactMethod
185+
fun RemoveTimer(objectData:ReadableMap) {
186+
val id =objectData.getInt("id");
187+
val foreground = objectData.getBoolean("foreground");
188+
189+
removeNotification (id,foreground);
190+
}
191+
192+
181193
fun removeNotification (id:Int,foreground:Boolean) {
182194
val notificationManager = myContext.getSystemService(NotificationManager::class.java)
183195
if(foreground)

example/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22

33
import {
44
TimerNotification,
5+
RemoveTimer,
56
onEvent,
67
} from 'react-native-custom-timer-notification';
78
onEvent((event: any) => {
@@ -15,9 +16,13 @@ export default function App() {
1516
body: 'Much longer text that cannot fit one line... ',
1617
id: 160211114,
1718
remove: false, // optional
18-
foreground: false,
19-
date: new Date(Date.now() + 20000),
19+
foreground: true,
20+
date: new Date(Date.now()),
21+
isCountDown: false,
2022
});
23+
setTimeout(() => {
24+
RemoveTimer(160211114, true);
25+
}, 5000);
2126
}, []);
2227

2328
return <></>;

src/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export function TimerNotification(a: object): any {
5050
return CustomTimerNotification.TimerNotification(data);
5151
return null;
5252
}
53+
export function RemoveTimer(a: number, b: Boolean = false): any {
54+
const payload = {
55+
id: a,
56+
foreground: b || false,
57+
};
58+
59+
CustomTimerNotification.RemoveTimer(payload);
60+
}
5361

5462
export function onEvent(listener: Function): void {
5563
DeviceEventEmitter.addListener('notificationClick', (event) =>

0 commit comments

Comments
 (0)