package com.zxhyis.toolss.notification.broadcast

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationManagerCompat
import com.zxhyis.toolss.logic.LogEx
import com.zxhyis.toolss.notification.NotificationHelper


/**
 * 响应通知RemoteViews的点击事件
 */
class NotificationBroadcast : BroadcastReceiver() {

    private val TAG = "NotificationBroadcast"
    override fun onReceive(context: Context, intent: Intent?) {
        val cancel = intent?.extras?.getString("cancel")
        LogEx.logDebug(TAG, "onReceive cancel=$cancel")
        if (cancel != null) {
            cancelNotification(context)
        }
    }

    companion object {
        const val action = "com.super.master.notification.broadcast.NotificationBroadcast"
        fun cancelNotification(context: Context) {
            val id = NotificationHelper.notificationId
            val notificationManager = NotificationManagerCompat.from(context)
            notificationManager.cancel(id)
        }

    }
}