Skip to content

Instantly share code, notes, and snippets.

@garg-lucifer
Last active September 24, 2022 12:01
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 garg-lucifer/5574d710025a824e93545ae44e99a81a to your computer and use it in GitHub Desktop.
Save garg-lucifer/5574d710025a824e93545ae44e99a81a to your computer and use it in GitHub Desktop.
@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