package com.abbidot.tracker.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.location.LocationManager
import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.tracker.constant.ConstantInt


/**
 *Created  by .yzq on 2022/5/23/023.
 * @link
 * @description:GPS开关操作广播
 */
class GPSMonitorReceiver(locationManager:LocationManager) : BroadcastReceiver() {

    private val mLocationManager=locationManager

    override fun onReceive(context: Context, intent: Intent?) {
        intent?.action?.apply {
            if (matches(Regex(LocationManager.PROVIDERS_CHANGED_ACTION))) {
                val gpsEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
                if (gpsEnabled) {
                    LogUtil.e("gps开启")
                    XEventBus.post(EventName.GPSSwitchState, ConstantInt.Open)
                } else {
                    LogUtil.e("gps关闭")
                    XEventBus.post(EventName.GPSSwitchState, ConstantInt.Close)
                }
            }
        }
    }


}