package com.mogo.cloud.wifi;

import android.net.wifi.WifiInfo;

import com.zhidao.manager.system.wifi.WifiState;

import java.util.ArrayList;
import java.util.List;

public class WifiStateManager {

    private WifiStateManager() {

    }

    public static WifiStateManager getInstance() {
        return Holder.wifiStateManager;
    }

    private static final class Holder {
        private static final WifiStateManager wifiStateManager = new WifiStateManager();
    }

    private final List<IWifiStateListener> wifiStateListeners = new ArrayList<>();

    public void registerWifiStateListener(IWifiStateListener listener) {
        if (listener != null && !wifiStateListeners.contains(listener)) {
            wifiStateListeners.add(listener);
        }
    }

    public void unRegisterWifiStateListener(IWifiStateListener listener) {
        if (listener != null) {
            wifiStateListeners.remove(listener);
        }
    }

    public void updateWifiState(WifiInfo wifiInfo) {
        if (wifiStateListeners.size() > 0) {
            for (IWifiStateListener listener : wifiStateListeners) {
                listener.onWifiState(wifiInfo);
            }
        }
    }

}
