111
hxb
2022-11-24 0a3e07f10937484145f33c7560607b4b2353cb81
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
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.ApBindSuccessConstract;
import com.mm.android.deviceaddmodule.helper.DeviceAddHelper;
import com.mm.android.deviceaddmodule.mobilecommon.annotation.DeviceAbility;
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.entity.AddApResult;
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 java.lang.ref.WeakReference;
 
public class ApBindSuccessPresenter implements ApBindSuccessConstract.Presenter {
    WeakReference<ApBindSuccessConstract.View> mView;
    AddApResult mAddApResult;
 
    public ApBindSuccessPresenter(ApBindSuccessConstract.View view) {
        mView = new WeakReference<>(view);
    }
 
    private void initApView() {
        DeviceIntroductionInfo deviceIntroductionInfo = DeviceAddModel.newInstance().getDeviceInfoCache().getDevIntroductionInfo();
        if (deviceIntroductionInfo != null) {
            String img = deviceIntroductionInfo.getImageInfos().get(DeviceAddHelper.OMSKey.ACCESSORY_MODE_FINISH_DEVICE_IMAGE);
            mView.get().setApImg(img);
        }
        if (mAddApResult != null) {
            mView.get().setApName(mAddApResult.getApName());
        }
    }
 
    @Override
    public void modifyApName() {
        if(!DHNetworkUtil.isConnected(mView.get().getContextInfo())){
            mView.get().showToastInfo(R.string.mobile_common_bec_common_network_exception);
            return;
        }
 
        final String apName = mView.get().getApName();
        if (TextUtils.isEmpty(apName)) {
            mView.get().showToastInfo(R.string.device_manager_input_device_name);
            return;
        }
        final DeviceAddInfo deviceAddInfo = DeviceAddModel.newInstance().getDeviceInfoCache();
        mView.get().showProgressDialog();
        final String deviceId = deviceAddInfo.getGatewayInfo().getSn();
        final String apId = deviceAddInfo.getDeviceSn();
        LCBusinessHandler modifyHandler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (mView.get() != null && mView.get().isViewActive()) {
                    mView.get().cancelProgressDialog();
                    if (HandleMessageCode.HMC_SUCCESS == msg.what) {
                        mView.get().completeAction();
                    } else {
                        mView.get().showToastInfo(BusinessErrorTip.getErrorTip(msg));
                    }
                }
            }
        };
        boolean hasToDeviceAbility = deviceAddInfo.hasAbility(DeviceAbility.ModifyName);
        DeviceAddModel.newInstance().modifyAPDevice(deviceId, apId, apName, hasToDeviceAbility, modifyHandler);
    }
 
    @Override
    public void setData(AddApResult addApResult) {
        mAddApResult = addApResult;
        initApView();
    }
}