package com.base.pdfreaderallpdfreader.fcm.alarm

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.pdfreaderallpdfreader.BuildConfig
import com.base.pdfreaderallpdfreader.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject
import com.base.pdfreaderallpdfreader.helper.EventUtils
import com.base.pdfreaderallpdfreader.utils.AppPreferences
import com.base.pdfreaderallpdfreader.utils.LogEx

class AlarmJobReceiver : BroadcastReceiver() {

    private val TAG = "AlarmJobReceiver"

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    override fun onReceive(context: Context, intent: Intent?) {
        LogEx.logDebug(TAG, "AlarmJobReceiver onReceive")
        EventUtils.event("alarm_push")
        var firstAlemtime = AppPreferences.getInstance().getLong("firstAlemtime", 0L)
        if (BuildConfig.DEBUG) {
            firstAlemtime = 1
        }
        if (firstAlemtime > 0) {
            val leatTime = System.currentTimeMillis()
            if (leatTime - firstAlemtime >= 1000 * 30 * 60) {
                sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_ALARM)
            }
        }
        AppPreferences.getInstance().put("firstAlemtime", System.currentTimeMillis())
        return
    }
}