1 package host.exp.exponent.notifications
2 
3 import android.content.BroadcastReceiver
4 import android.content.Context
5 import javax.inject.Inject
6 import host.exp.exponent.ExponentManifest
7 import android.content.Intent
8 import host.exp.exponent.kernel.KernelConstants
9 import host.exp.exponent.notifications.managers.SchedulersManagerProxy
10 import host.exp.exponent.analytics.EXL
11 import host.exp.exponent.di.NativeModuleDepsProvider
12 import java.lang.Exception
13 import java.util.HashMap
14 
15 class ScheduledNotificationReceiver : BroadcastReceiver() {
16   @Inject
17   lateinit var exponentManifest: ExponentManifest
18 
onReceivenull19   override fun onReceive(context: Context, intent: Intent) {
20     val bundle = intent.extras
21     val details = bundle!!.getSerializable(KernelConstants.NOTIFICATION_OBJECT_KEY) as HashMap<*, *>?
22     val notificationId = bundle.getInt(KernelConstants.NOTIFICATION_ID_KEY, 0)
23     val schedulerId = details!![SchedulersManagerProxy.SCHEDULER_ID] as String?
24 
25     SchedulersManagerProxy.getInstance(context).rescheduleOrDelete(schedulerId)
26 
27     NotificationHelper.showNotification(
28       context,
29       notificationId,
30       details,
31       exponentManifest,
32       object : NotificationHelper.Listener {
33         override fun onSuccess(id: Int) {
34           // do nothing
35         }
36 
37         override fun onFailure(e: Exception) {
38           EXL.e(ScheduledNotificationReceiver::class.java.name, e)
39         }
40       }
41     )
42   }
43 
44   init {
45     NativeModuleDepsProvider.instance.inject(ScheduledNotificationReceiver::class.java, this)
46   }
47 }
48