package com.zxhyis.toolss.notification.broadcast

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.zxhyis.toolss.logic.LogEx
import com.zxhyis.toolss.notification.NotificationUtils

class CloseNotificationReceiver : BroadcastReceiver() {

    private val TAG = "com.zxhyis.toolss.notification.broadcast.CloseNotificationReceiver"
    override fun onReceive(context: Context?, intent: Intent?) {
        intent?.let {
            val notificationId = it.getIntExtra("notificationId", -1)
            if (notificationId != -1 && it.action != "DELETE_NOTIFICATION") {
                val notificationManager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
                notificationManager?.cancel(NotificationUtils.NOTIFICATION_TAG, notificationId)
            }
            LogEx.logDebug(TAG, "onReceive")
        }
    }
}
