JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
//
//  Copyright © 2018 dahua. All rights reserved.
//
 
import Foundation
 
class DHWiFiConnectOnlinePresenter: IDHWiFiConnectOnlinePresenter {
 
    public var successHandler: (() -> (Void))?
    var wifiStatus: LCWifiInfo?  //wifi信息
    var deviceId: String?
    weak var container: DHWifiConnectOnlineVC?
    
    func setContainer(container: DHWifiConnectOnlineVC) {
        self.container = container
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    required init(connectWifiInfo: LCWifiInfo, deviceId: String) {
        self.wifiStatus = connectWifiInfo
        self.deviceId = deviceId
    }
    
    
    // MARK: DHWifiPasswordPresenterProtocol
    func updateContainerViewByWifiInfo() {
        
        if let wifiName = wifiStatus?.ssid {
            self.container?.nextButton.dh_enable = true
            self.container?.wifiNameLabel.text = wifiName
            
            //【*】直接从保存的密码取:如果长度大于0,选中check,并填充密码
            if let password = DHUserManager.shareInstance().ssidPwd(by: self.container?.wifiNameLabel.text), password.count > 0 {
                self.container?.checkButton.isSelected = true
                self.container?.passwordInputView.textField.text = password
            } else {
                self.container?.checkButton.isSelected = false
                self.container?.passwordInputView.textField.text = nil
            }
        } else {
            self.container?.nextButton.dh_enable = false
            self.container?.wifiNameLabel.text = ""
            self.container?.passwordInputView.textField.text = ""
        }
    }
    
    func setupSupportView() {
        container?.supportView.isHidden = true
        container?.checkWidthConstraint.constant = 250
    }
    
    func nextStepAction(wifiSSID: String, wifiPassword: String?) {
 
        var password: String?
        if let text = self.container?.passwordInputView.textField.text,
            text.count > 0 {
            password = self.container?.passwordInputView.textField.text
        }
        
 
        //国内需求变更:连接后3s toast提示 WIFI连接中,请稍后刷新查看
        let connectSession = LCWifiConnectSession()
        connectSession.bssid = wifiStatus?.bssid ?? ""
        connectSession.ssid = wifiStatus?.ssid ?? ""
        connectSession.linkEnable = LCLinkHandle(rawValue: LCLinkHandle.RawValue(truncating: NSNumber(booleanLiteral: true)))
        connectSession.password = password ?? ""
        
        LCDeviceHandleInterface.controlDeviceWifi(for: deviceId ?? "", connestSession: connectSession, success: {
            
        }) { (error) in
            
        }
        LCProgressHUD.showMsg("device_manager_wifi_connetting_tip".lc_T, duration: 3.0)
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
            self.container?.navigationController?.popViewController(animated: true)
        }
    }
}