wxr
2022-11-24 2af932533ef851bf983385244e9912976dbd4daa
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.mm.android.deviceaddmodule.presenter;
 
import android.os.Message;
import android.text.TextUtils;
 
import com.dahua.mobile.utility.network.DHNetworkUtil;
import com.mm.android.deviceaddmodule.R;
import com.mm.android.deviceaddmodule.contract.BindSuccessConstract;
import com.mm.android.deviceaddmodule.helper.DeviceAddHelper;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.ProviderManager;
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
import com.mm.android.deviceaddmodule.mobilecommon.common.LCConfiguration;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceAddInfo;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceIntroductionInfo;
import com.mm.android.deviceaddmodule.model.DeviceAddModel;
import com.mm.android.deviceaddmodule.openapi.DeviceAddOpenApiManager;
import com.mm.android.deviceaddmodule.openapi.data.DeviceDetailListData;
 
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
public class BindSuccessPresenter implements BindSuccessConstract.Presenter {
    private static final String CHANNEL_INDEX = "0";
    WeakReference<BindSuccessConstract.View> mView;
    String mDevDefaultName;
    DeviceAddInfo mDeviceAddInfo;
    boolean mIsOverSea;
 
    public BindSuccessPresenter(BindSuccessConstract.View view) {
        mView = new WeakReference<>(view);
        initViewData();
    }
 
    private void initViewData() {
        mDeviceAddInfo = DeviceAddModel.newInstance().getDeviceInfoCache();
        mDevDefaultName = mDeviceAddInfo.getDeviceDefaultName();
        mView.get().setDevName(mDevDefaultName);
        updateDevImg();
        mIsOverSea = ProviderManager.getAppProvider().getAppType() == LCConfiguration.APP_LECHANGE_OVERSEA;
    }
 
    private void updateDevImg() {
        DeviceIntroductionInfo deviceIntroductionInfo = mDeviceAddInfo.getDevIntroductionInfo();
        if (deviceIntroductionInfo != null && deviceIntroductionInfo.getImageInfos() != null) {
            HashMap<String, String> imageInfos = deviceIntroductionInfo.getImageInfos();
            String img = "";
            if (imageInfos.containsKey(DeviceAddHelper.OMSKey.WIFI_MODE_FINISH_DEVICE_IMAGE)) {
                img = imageInfos.get(DeviceAddHelper.OMSKey.WIFI_MODE_FINISH_DEVICE_IMAGE);
            } else if (imageInfos.containsKey(DeviceAddHelper.OMSKey.SOFT_AP_MODE_RESULT_PROMPT_IMAGE)) {
                img = imageInfos.get(DeviceAddHelper.OMSKey.SOFT_AP_MODE_RESULT_PROMPT_IMAGE);
            } else if (imageInfos.containsKey(DeviceAddHelper.OMSKey.LOCATION_MODE_FINISH_DEVICE_IMAGE)) {
                img = imageInfos.get(DeviceAddHelper.OMSKey.LOCATION_MODE_FINISH_DEVICE_IMAGE);
            } else if (imageInfos.containsKey(DeviceAddHelper.OMSKey.THIRD_PARTY_PLATFORM_MODE_RESULT_PROMPT_IMAGE)) {
                img = imageInfos.get(DeviceAddHelper.OMSKey.THIRD_PARTY_PLATFORM_MODE_RESULT_PROMPT_IMAGE);
            }
            mView.get().updateDevImg(img);
        }
    }
 
    @Override
    public void refreshDevice(final boolean isExit) {
        mView.get().completeAction();
    }
 
    @Override
    public void modifyDevName() {
        if (!DHNetworkUtil.isConnected(mView.get().getContextInfo())) {
            mView.get().showToastInfo(R.string.mobile_common_bec_common_network_exception);
            return;
        }
 
        final String sn = DeviceAddModel.newInstance().getDeviceInfoCache().getDeviceSn();
        String channelId = "0";
        // 国内单通道设备修改通道名称
        if (ProviderManager.getAppProvider().getAppType() != LCConfiguration.APP_LECHANGE_OVERSEA
                && DeviceAddModel.newInstance().getDeviceInfoCache().getChannelNum() == 1) {
            channelId = CHANNEL_INDEX;
        }
        final String devName = mView.get().getDevName();
        if (TextUtils.isEmpty(devName)) {
            mView.get().showToastInfo(R.string.device_manager_input_device_name);
            return;
        }
 
        mView.get().showProgressDialog();
        LCBusinessHandler modifyNameHandler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (mView.get() != null && mView.get().isViewActive()) {
                    mView.get().cancelProgressDialog();
                    if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                        refreshDevice(true);
                    } else {
                        mView.get().showToastInfo(BusinessErrorTip.getErrorTip(msg));
                    }
                }
            }
        };
        DeviceAddModel.newInstance().modifyDeviceName(sn, channelId, devName, modifyNameHandler);
    }
 
    @Override
    public void getDevName() {
        mView.get().showProgressDialog();
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                mView.get().cancelProgressDialog();
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    DeviceDetailListData.Response response = (DeviceDetailListData.Response) msg.obj;
                    mView.get().deviceName(response.data.deviceList.get(0).name);
                } else {
                    //失败
                    mView.get().showToastInfo(BusinessErrorTip.getErrorTip(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    //获取设备详情列表request参数封装
                    DeviceDetailListData deviceDetailListData = new DeviceDetailListData();
                    List<DeviceDetailListData.RequestData.DeviceListBean> deviceListBeans = new ArrayList<>();
                    DeviceDetailListData.RequestData.DeviceListBean deviceListBean = new DeviceDetailListData.RequestData.DeviceListBean();
                    deviceListBean.deviceId = DeviceAddModel.newInstance().getDeviceInfoCache().getDeviceSn();
                    deviceListBeans.add(deviceListBean);
                    deviceDetailListData.data.deviceList = deviceListBeans;
                    //获取设备详情列表
                    DeviceDetailListData.Response result = DeviceAddOpenApiManager.subAccountDeviceInfo(deviceDetailListData);
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
}