hxb
2022-11-24 9d7d3963cc54eb145c1767f5f124f2881e8e06d4
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.mm.android.deviceaddmodule.presenter;
 
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
 
import com.dahua.mobile.utility.network.DHWifiUtil;
import com.lechange.opensdk.searchwifi.LCOpenSDK_SearchWiFi;
import com.mm.android.deviceaddmodule.contract.DevWifiListConstract;
import com.lechange.opensdk.searchwifi.WlanInfo;
import com.mm.android.deviceaddmodule.event.DeviceAddEvent;
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceAddInfo;
import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil;
import com.mm.android.deviceaddmodule.model.DeviceAddModel;
 
import org.greenrobot.eventbus.EventBus;
 
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
 
public class DevWifiListPresenter implements DevWifiListConstract.Presenter {
    WeakReference<DevWifiListConstract.View> mView;
    private List<WlanInfo> mListData;
    DHWifiUtil mDHWifiUtil;
    String mDeviceSn;
    private boolean mIsNotNeedLogin;
    private boolean isSupport5G;
 
    public DevWifiListPresenter(DevWifiListConstract.View view, boolean isNotNeedLogin) {
        mView = new WeakReference<>(view);
        mDHWifiUtil=new DHWifiUtil(mView.get().getContextInfo().getApplicationContext());
        mDeviceSn=DeviceAddModel.newInstance().getDeviceInfoCache().getDeviceSn();
        mListData=new ArrayList<>();
        mIsNotNeedLogin = isNotNeedLogin;
        String wifiMode = DeviceAddModel.newInstance().getDeviceInfoCache().getWifiTransferMode();
        if (!TextUtils.isEmpty(wifiMode)) {
            isSupport5G = wifiMode.toUpperCase().contains("5GHZ");
        }
    }
 
    @Override
    public boolean isDevSupport5G() {
        return isSupport5G;
    }
 
    @Override
    public void getWifiList(){
        mView.get().showProgressDialog();
        EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.SOFTAP_REFRSH_WIFI_LIST_DISABLE_ACTION));
        mListData.clear();
        String gatwayip= mDHWifiUtil.getGatewayIp();
        final DeviceAddInfo deviceAddInfo = DeviceAddModel.newInstance().getDeviceInfoCache();
        String pwd = deviceAddInfo.getDevicePwd();
 
        LCBusinessHandler getWifiListHandler=new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if(mView.get()!=null){
                    mView.get().cancelProgressDialog();
 
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.SOFTAP_REFRSH_WIFI_LIST_ENABLE_ACTION));
                        }
                    }, 500);
 
                    if(msg.what== HandleMessageCode.HMC_SUCCESS){
                        dispatchListResult(msg);
                    } else if(msg.what== HandleMessageCode.HMC_BATCH_MIDDLE_RESULT) { // 登陆失败
                            mView.get().goDevLoginPage();
                    } else {
                        mView.get().showErrorInfoView();
                    }
                }
            }
        };
 
        if(mIsNotNeedLogin) {
            LogUtil.debugLog("LCOpenSDK_SearchWiFi","wifiList::"+mIsNotNeedLogin);
            LCOpenSDK_SearchWiFi.getSoftApWifiList4Sc(gatwayip,getWifiListHandler);
        } else {
            LCOpenSDK_SearchWiFi.getSoftApWifiList(gatwayip,pwd,getWifiListHandler);
        }
    }
 
    private void dispatchListResult(Message msg){
        mView.get().showListView();
        mListData= (List<WlanInfo>) msg.obj;
        mView.get().updateWifiList(mListData);
    }
}