package com.hh.lib_common.connect;

import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;

import com.hh.lib_base.log.AppLogUtils;

/**
 * Description: $
 * @author xwh
 * time 2024/8/20
 **/
public class NetworkCallbackImpl extends ConnectivityManager.NetworkCallback {

    private NetworkCallback callback;

    public NetworkCallbackImpl(NetworkCallback callback) {
        this.callback = callback;
    }

    @Override
    public void onAvailable(Network network) {
        super.onAvailable(network);
        //
        AppLogUtils.e("网络--连接--onAvailable");
        if(callback!=null){
            callback.onAvailable(network);
        }


    }

    @Override
    public void onLosing(Network network, int maxMsToLive) {
        super.onLosing(network, maxMsToLive);
        AppLogUtils.e("网络--onLosing");
    }

    @Override
    public void onLost(Network network) {
        super.onLost(network);
        AppLogUtils.e("网络--断开--onLost");
        if(callback!=null){
            callback.onLost(network);
        }
    }

    @Override
    public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
        super.onCapabilitiesChanged(network, networkCapabilities);
        AppLogUtils.i("网络-onCapabilitiesChanged");
    }

    @Override
    public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
        super.onLinkPropertiesChanged(network, linkProperties);
        AppLogUtils.i("网络-onLinkPropertiesChanged");
    }

    public void setCallback(NetworkCallback callback) {
        this.callback = callback;
    }
}