Skip to content

layout fix #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ TimerNotification({


```javascript
CustomTimerNotification.TimerNotification({
id: 2,
title: "Special Offer!",
body: "Limited time offer ends in:",
date: "25-12-2024 23:59:59",
gifUrl: "https://example.com/animation.gif",
payload: "offer-456"
TimerNotification({
id: 2,
title: <p style="color: #ff5722; font-size: 18px;"><b>🔥 Limited-Time Deal! Hurry Up! ⏳</b></p>,
body: <p style="font-size: 14px;">⏳ Time is running out! <b>Claim your exclusive discount</b> before it's too late.</p>,
subtitle: "💸",
date: new Date(Date.now() + 20000),
giffyUrl: "https://media1.tenor.com/m/EBdqcf-JxpYAAAAC/6m-rain.gif",
payload: "offer-456"
});
```
#### Options

| Parameter | Type | Required | Description |
|-----------|----------|----------|---------------------------------|
| id | number | Yes | Unique notification identifier |
| title | string | Yes | Notification title |
| body | string | Yes | Notification message |
| date | string | Yes | End date (dd-MM-yyyy HH:mm:ss) |
| gifUrl | string | No | URL to GIF animation |
| title | string | Yes | Notification title with HTML support |
| body | string | Yes | Notification message with HTML support |
| date | Date | No | End date with time (dd-MM-yyyy HH:mm:ss) |
| giffyUrl | string | No | URL to GIF animation |
| payload | string | No | Custom data payload |

## Full Custom Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ data class NotificationConfig(
val subtitle: String?,
val smallIcon: Int = android.R.drawable.ic_dialog_info,
val countdownDuration: Long = 5000,
val payload: String?
val payload: String?,
val body: String?
)


Expand All @@ -60,12 +61,11 @@ class AnimatedNotificationManager(
try {
val extras = intent.extras
val params: WritableMap = Arguments.createMap()
params.putString("id", extras!!.getString("id"))
params.putString("action", extras!!.getString("action"))
params.putString("payload", extras!!.getString("payload"))
Log.d(TAG, extras?.getString("payload")?:"")
if(extras!!.getString("action") == "cancel"){
disableCurrentNotification = true
}
disableCurrentNotification = true
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit(
"notificationClick",
Expand Down Expand Up @@ -115,7 +115,8 @@ class AnimatedNotificationManager(
val remoteViews = RemoteViews(context.packageName, R.layout.gen_notification_open)

if(config.gifUrl !== null){
val frames = processGif(config.gifUrl, memoryLimitMB = GIF_MEMORY_LIMIT_MB)
val gifProcessor = GifProcessor()
val frames = gifProcessor.processGif(config.gifUrl, memoryLimitMB = GIF_MEMORY_LIMIT_MB)

frames.forEach { frame ->
val frameView = RemoteViews(context.packageName, R.layout.giffy_image)
Expand Down Expand Up @@ -143,25 +144,30 @@ class AnimatedNotificationManager(
}
} else null

val subtitleHtml = if(config.title != null) {
val bodyHtml = if(config.title != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(config.subtitle, Html.FROM_HTML_MODE_COMPACT)
Html.fromHtml(config.body, Html.FROM_HTML_MODE_COMPACT)
} else {
Html.fromHtml(config.subtitle)
Html.fromHtml(config.body)
}
} else null

if(titleHtml != null)
remoteViews.setTextViewText(R.id.title, titleHtml)

if(subtitleHtml != null)
remoteViews.setTextViewText(R.id.subtitle, subtitleHtml)
if(bodyHtml != null)
remoteViews.setTextViewText(R.id.body, bodyHtml)
}

private fun configureChronometer(remoteViews: RemoteViews, countdownDuration: Long) {
if(countdownDuration !== null){
val chronometerBaseTime = countdownDuration
remoteViews.setChronometerCountDown(R.id.simpleChronometer, true)
remoteViews.setChronometer(R.id.simpleChronometer, chronometerBaseTime, null, true)
} else {
remoteViews.setViewVisibility(R.id.simpleChronometer, View.GONE)
}

}

private fun buildNotification(remoteViews: RemoteViews, config: NotificationConfig): NotificationCompat.Builder {
Expand Down Expand Up @@ -204,6 +210,9 @@ class AnimatedNotificationManager(
.setOnlyAlertOnce(true)
.setAutoCancel(true)
.setDeleteIntent(onDismissPendingIntent)
.apply {
config.subtitle?.let { setSubText(it) }
}
.setContentIntent(pendingIntent)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,47 @@ var removedNotification = false;
return "CustomTimerNotification"
}


@ReactMethod
fun TimerNotification(objectData:ReadableMap) {
val payload = objectData.getString(Constants.NOTIFICATION.PAYLOAD);
val title = objectData.getString(Constants.NOTIFICATION.TITLE);
val body = objectData.getString(Constants.NOTIFICATION.BODY);
val id = objectData.getInt(Constants.NOTIFICATION.ID);
val gifUrl = objectData.getString(Constants.NOTIFICATION.GIFFY_URl)
val notificationHelper = AnimatedNotificationManager(myContext)

val datetime = objectData.getString("date")
val sdf = SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH)

val startTime = SystemClock.elapsedRealtime()
val endTime: Calendar = Calendar.getInstance()
endTime.time = sdf.parse(datetime)

val now = Date()
val elapsed: Long = now.getTime() - endTime.timeInMillis
val remainingTime = startTime - elapsed

notificationHelper.showAnimatedNotification(NotificationConfig(gifUrl = gifUrl, title=title, subtitle=body, payload=payload, notificationId=id, countdownDuration = remainingTime))
fun TimerNotification(objectData: ReadableMap) {
val payload = if (objectData.hasKey(Constants.NOTIFICATION.PAYLOAD)) objectData.getString(Constants.NOTIFICATION.PAYLOAD) else ""
val title = if (objectData.hasKey(Constants.NOTIFICATION.TITLE)) objectData.getString(Constants.NOTIFICATION.TITLE) else "Default Title"
val body = if (objectData.hasKey(Constants.NOTIFICATION.BODY)) objectData.getString(Constants.NOTIFICATION.BODY) else "Default Body"
val subtitle = if (objectData.hasKey("subtitle")) objectData.getString("subtitle") else null
val id = if (objectData.hasKey(Constants.NOTIFICATION.ID)) objectData.getInt(Constants.NOTIFICATION.ID) else 0
val gifUrl = if (objectData.hasKey(Constants.NOTIFICATION.GIFFY_URl)) objectData.getString(Constants.NOTIFICATION.GIFFY_URl) else null

val datetime = if (objectData.hasKey("date")) objectData.getString("date") else null
val sdf = SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH)

val endTime: Calendar = Calendar.getInstance()
try {
if (!datetime.isNullOrEmpty()) {
endTime.time = sdf.parse(datetime) ?: Date()
}
} catch (e: Exception) {
Log.e("TimerNotification", "Date parsing failed: ${e.message}")
endTime.time = Date()
}

val startTime = SystemClock.elapsedRealtime()
val now = System.currentTimeMillis()
val elapsed: Long = now - endTime.timeInMillis
val remainingTime = maxOf(startTime - elapsed, 0L)

val notificationHelper = AnimatedNotificationManager(myContext)
notificationHelper.showAnimatedNotification(
NotificationConfig(
gifUrl = gifUrl,
title = title,
subtitle = subtitle,
body = body,
payload = payload,
notificationId = id,
countdownDuration = remainingTime
)
)
}



@ReactMethod
Expand Down
Loading