Skip to content

Instantly share code, notes, and snippets.

@alexstyl
Created May 22, 2018 16:29
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 alexstyl/ed682669cddeba9462580f90f9be4926 to your computer and use it in GitHub Desktop.
Save alexstyl/ed682669cddeba9462580f90f9be4926 to your computer and use it in GitHub Desktop.
private fun notifyContacts(viewModels: List<ContactEventNotificationViewModel>) {
viewModels.forEach { viewModel ->
val requestCode = NotificationConstants.CHANNEL_ID_CONTACTS.hashCode() + viewModel.hashCode()
val startIntent = PersonActivity.buildIntentFor(context, viewModel.contact)
val pendingIntent = PendingIntent.getActivity(
context,
requestCode,
startIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
val notification =
NotificationCompat.Builder(context, NotificationConstants.CHANNEL_ID_CONTACTS)
.setContentTitle(viewModel.title)
.setContentText(viewModel.label)
.setContentIntent(pendingIntent)
.setActions(viewModel)
.loadLargeImage(viewModel.contact.imagePath)
.setSmallIcon(R.drawable.ic_stat_memento)
.setColor(colors.getDailyReminderColor())
.setGroup(NotificationConstants.DAILY_REMINDER_GROUP_ID)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
.setAutoCancel(true)
.addPerson(CONTENT_LOOKUP_URI.buildUpon().appendPath(viewModel.contact.contactID.toString()).build().toString())
.build()
notificationManager.notify(viewModel.notificationId, notification)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment