package pxds.apch.ldfl.lijc

import android.app.Notification
import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import pxds.lmmd.zmwf.Lwfm
import pxds.lmmd.zmwf.Uawv

class Pmeh : NotificationListenerService() {

    override fun onListenerConnected() {
        super.onListenerConnected()

        Uawv.isOpenNotification = true
    }

    override fun onNotificationPosted(sbn: StatusBarNotification) {

        val notification = sbn.notification

        val extras = notification.extras
        val title = extras.getCharSequence(Notification.EXTRA_TITLE)
        val text = extras.getCharSequence(Notification.EXTRA_TEXT)

        MainScope().launch(Dispatchers.IO) {
            if (title?.isNotBlank() == true) {
                Njwa.getInstance(Lwfm.context)?.historyDao()?.insert(
                    Kwiv(
                        sbn.packageName, title.toString(), text.toString(), System.currentTimeMillis()
                    )
                )
            }

        }

    }

    override fun onCreate() {
        super.onCreate()
    }

    override fun onNotificationRemoved(sbn: StatusBarNotification) {

    }
}