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
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
//
//  Copyright © 2018 dahua. All rights reserved.
//
 
import UIKit
 
class DHWifiConnectOnlineVC: DHBaseViewController {
 
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var inputPwdLabel: UILabel!
    @IBOutlet weak var wifiLabel: UILabel!
    @IBOutlet weak var wifiNameLabel: UILabel!
    @IBOutlet weak var passwordInputView: LCInputView!
    @IBOutlet weak var bottomLine: UIView!
    @IBOutlet weak var topLine: UIView!
    @IBOutlet weak var checkButton: UIButton!
    @IBOutlet weak var nextButton: UIButton!
    @IBOutlet weak var supportView: UIView!
    @IBOutlet weak var supportTipButton: UIButton!
    @IBOutlet weak var autoKeyboardView: DHAutoKeyboardView!
    @IBOutlet weak var checkWidthConstraint: NSLayoutConstraint!
    var wifiInfo: LCWifiInfo!
 
    private var presenter: IDHWiFiConnectOnlinePresenter?
    
    public static func storyboardInstance() -> DHWifiConnectOnlineVC {
        let storyboard = UIStoryboard(name: "AddDevice", bundle: Bundle.dh_addDeviceBundle())
        let controller = storyboard.instantiateViewController(withIdentifier: "DHWifiConnectOnlineVC")
        return controller as! DHWifiConnectOnlineVC
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.dhcolor_c7()
        title = "mobile_common_network_config".lc_T
        setupCustomContents()
        setupInputView()
        presenter?.setupSupportView()
        presenter?.updateContainerViewByWifiInfo()
        autoKeyboardView.relatedView = nextButton
    }
 
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.view.endEditing(true)
    }
 
 
    public func setPresenter(presenter: IDHWiFiConnectOnlinePresenter) {
        self.presenter = presenter
    }
 
    func setupCustomContents() {
        imageView.image = DHAddDeviceManager.sharedInstance.isSupport5GWifi ? UIImage(named: "adddevice_icon_wifipassword") : UIImage(named: "adddevice_icon_wifipassword_nosupport5g")
        wifiNameLabel.text = nil
        wifiNameLabel.textColor = UIColor.dhcolor_c2()
        inputPwdLabel.text = "add_device_input_wifi_password".lc_T
        inputPwdLabel.textColor = UIColor.dhcolor_c2()
        wifiLabel.text = "add_device_wifi_ssid".lc_T
        wifiLabel.textColor = UIColor.dhcolor_c5()
        checkButton.setTitle("add_device_remember_password".lc_T, for: .normal)
        checkButton.setTitleColor(UIColor.dhcolor_c5(), for: .normal)
        supportTipButton.setTitle("add_device_device_not_support_5g".lc_T, for: .normal)
        supportTipButton.setTitleColor(UIColor.dhcolor_c2(), for: .normal)
        passwordInputView.textField.placeholder = "add_device_input_wifi_password".lc_T
        nextButton.setTitle("device_manager_connect".lc_T, for: .normal)
        nextButton.setTitleColor(UIColor.dhcolor_c43(), for: .normal)
        passwordInputView.textField.textAlignment = .left
        passwordInputView.textField.font = UIFont.dhFont_t3()
        passwordInputView.textField.textColor = UIColor.dhcolor_c2()
        
        bottomLine.backgroundColor = UIColor.dhcolor_c8()
        topLine.backgroundColor = UIColor.dhcolor_c8()
 
        checkButton.setImage(UIImage(named: "adddevice_box_checkbox"), for: .normal)
        checkButton.setImage(UIImage(named: "adddevice_box_checkbox_checked"), for: .selected)
 
        //按钮样式配置
        nextButton.layer.cornerRadius = DHModuleConfig.shareInstance().commonButtonCornerRadius()
        nextButton.backgroundColor = DHModuleConfig.shareInstance().commonButtonColor()
 
        //支持多行显示
        checkButton.titleLabel?.numberOfLines = 2
        supportTipButton.titleLabel?.numberOfLines = 2
        supportView.backgroundColor = UIColor.clear
        
        //DTS000273198 优先显示WifiLabel
        wifiLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
        wifiNameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
    }
 
    func setupInputView() {
        passwordInputView.backgroundColor = UIColor.clear
        passwordInputView.textField.returnKeyType = .done
        passwordInputView.textField.delegate = self
 
        //密码国内默认为明文,可点击隐藏,海外默认为暗文
        passwordInputView.openBtnState = DHModuleConfig.shareInstance().isLeChange
    }
    
    // MARK: Actions
    @IBAction func onCheckAction(_ sender: UIButton) {
        sender.isSelected = !sender.isSelected
 
        //【*】清除当前对应的WIFI密码
        if checkButton.isSelected == false, let ssid = wifiNameLabel.text {
            DHUserManager.shareInstance().removeSSID(ssid)
        }
    }
 
 
    @IBAction func onNextAction(_ sender: Any) {
   
        self.view.endEditing(true)
        
        let wifiSSID = wifiNameLabel.text
        let wifiPassword = passwordInputView.textField.text
        DHAddDeviceManager.sharedInstance.wifiSSID = wifiSSID
        DHAddDeviceManager.sharedInstance.wifiPassword = wifiPassword
        
        //统一下一步记住密码
        if checkButton.isSelected, wifiSSID != nil, wifiPassword != nil {
            DHUserManager.shareInstance().addSSID(wifiSSID, ssidPwd: wifiPassword)
        }
        
        //解释器处理下一步
        self.presenter?.nextStepAction(wifiSSID: wifiSSID ?? "", wifiPassword: wifiPassword)
        
    }
    
 
}
 
extension DHWifiConnectOnlineVC: UITextFieldDelegate {
    
    // MARK: UITextFieldDelegate
    @nonobjc func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}