Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@AndroidEntryPoint
class OnCompletedBroadcastReceiver : BroadcastReceiver() {
@Inject lateinit var repository: TaskCategoryRepositoryImpl
override fun onReceive(p0: Context?, p1: Intent?) {
val taskInfo = p1?.getSerializableExtra("task_info") as? TaskInfo
if (taskInfo != null) {
taskInfo.status = true
}
CoroutineScope(IO).launch {
taskInfo?.let {
repository.updateTaskStatus(it)
}
}
if (p0 != null && taskInfo != null) {
// used to remove the notification when a user taps completed button (Optional)
NotificationManagerCompat.from(p0).cancel(null, taskInfo.id)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment