Skip to content

Instantly share code, notes, and snippets.

@edenman
Created July 16, 2020 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edenman/f1bbcf8e0a5e96970c70c5724f02f1ad to your computer and use it in GitHub Desktop.
Save edenman/f1bbcf8e0a5e96970c70c5724f02f1ad to your computer and use it in GitHub Desktop.
private fun Notification.toBuilder(): NotificationCompat.Builder {
val builder = NotificationCompat.Builder(app, CHANNEL_ID)
.setSmallIcon(smallIcon.resId)
.setAutoCancel(flags and Notification.FLAG_AUTO_CANCEL == Notification.FLAG_AUTO_CANCEL)
.setCategory(category)
.setStyle(messagingStyle())
.setContentIntent(contentIntent)
actions.forEach { action ->
val actionBuilder = NotificationCompat.Action.Builder(
action.icon,
action.title,
action.actionIntent
)
action.remoteInputs.forEach { input ->
actionBuilder.addRemoteInput(
RemoteInput.Builder(input.resultKey).setLabel(input.label).build()
)
}
builder.addAction(actionBuilder.build())
}
return builder
}
private fun Notification.messagingStyle(): MessagingStyle {
return MessagingStyle.extractMessagingStyleFromNotification(this)
.require("No messagingStyle on notification?")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment