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.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.fcm.PopupConstObject
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.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
    }
}