package com.base.datarecovery.fcm

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.datarecovery.utils.AppPreferences

class CloseNotificationReceiver : BroadcastReceiver() {
    companion object {
        var Action = "CANCEL_NOTIFICATION"
        var NotificationId = "NOTIFICATION_ID"
    }

    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent?.action
        NotificationUtil.stopNotificationHandler()
        if (action != null && action == "CANCEL_NOTIFICATION") {
            var notificationId = intent.getIntExtra(NotificationId, 0)
            val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            val actionS: Int = AppPreferences.getInstance().getInt("actionS", 0)
            if (actionS == 0) {
                notificationId = 0
            }
            notificationManager.cancel(notificationId)
        }
    }
}