Created
July 16, 2020 22:55
-
-
Save edenman/f1bbcf8e0a5e96970c70c5724f02f1ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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