wjc
2023-03-30 c5451371d006652b8c7a5da8c3ca7525d7b39fef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ezviz.ezopensdkcommon.configwifi;
 
import android.app.Application;
import android.content.Intent;
import android.text.TextUtils;
 
import java.util.ArrayList;
import java.util.List;
 
public abstract class ConfigWifiExecutingActivityPresenter {
 
    private static List<ConfigWifiExecutingActivityPresenter> mAvailablePresenterList = new ArrayList<>();
 
    protected Callback mCallback;
    protected String mType;
 
    public String getType(){
        return mType;
    }
 
    public void setCallback(Callback mCallback) {
        this.mCallback = mCallback;
    }
 
    public static void addPresenter(ConfigWifiExecutingActivityPresenter presenter){
        // 移除同类presenter,避免互相干扰
        clearPresenter(presenter.mType);
        mAvailablePresenterList.add(presenter);
    }
 
    public static ConfigWifiExecutingActivityPresenter getPresenter(String type){
        for (ConfigWifiExecutingActivityPresenter presenter: mAvailablePresenterList){
            if (!TextUtils.isEmpty(type) && type.equals(presenter.mType)){
                return presenter;
            }
        }
        return null;
    }
 
    private static void clearPresenter(String type){
        List<ConfigWifiExecutingActivityPresenter> mFoundList = new ArrayList<>();
        for (ConfigWifiExecutingActivityPresenter presenter: mAvailablePresenterList){
            if (!TextUtils.isEmpty(type) && type.equals(presenter.mType)){
                mFoundList.add(presenter);
            }
        }
        mAvailablePresenterList.removeAll(mFoundList);
    }
 
    public abstract void startConfigWifi(Application app, Intent configParam);
    public abstract void stopConfigWifi();
 
    public interface Callback{
        void onConnectedToWifi();
 
        /**
         * 设备已经上线,仅供完整SDK使用
         */
        void onConnectedToPlatform();
 
        void onConfigInfo(int info);
        void onConfigError(int code, String msg);
        void onTimeout();
    }
 
}