package com.wdkl.ncs.s433.transbox.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;


import com.wdkl.ncs.s433.transbox.common.Constants;
import com.wdkl.ncs.s433.transbox.tcp.EventBusModel;
import com.wdkl.ncs.s433.transbox.utils.NetUtil;

import org.greenrobot.eventbus.EventBus;

public class NetworkConnectChangedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        // 如果相等的话就说明网络状态发生了变化
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            int netWorkState = NetUtil.getNetWorkState(context);
            Log.e("NetworkConnect", "onReceive: "+netWorkState );
            // 接口回调传过去状态的类型
            EventBusModel eventBusModel = new EventBusModel(Constants.NET_WORK_STATUS_CHANGE,netWorkState);
            EventBus.getDefault().post(eventBusModel);
        }else if(intent.getAction().equals("com.wdkl.loragateway.net.avaiable")){
            Log.e("NetworkConnect", "onReceive: 收到广播 com.wdkl.loragateway.net.avaiable");
            EventBusModel eventBusModel = new EventBusModel(Constants.NET_WORK_AVAILABLE_CHANGE,Constants.NET_WORK_AVAILABLE);
            EventBus.getDefault().post(eventBusModel);
        }
    }
}