JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
//
//  Copyright © 2018年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//    连接云平台超时
 
import UIKit
 
protocol DHConnectCloudTimeoutVCDelegate: NSObjectProtocol {
    
    func cloudTimeOutReconnectAction(controller: DHConnectCloudTimeoutViewController)
}
 
class DHConnectCloudTimeoutViewController: DHAddBaseViewController {
    
    public var failureType: DHNetConnectFailureType = .commonWithWired {
        didSet {
            if failureView != nil {
                failureView.setFailureType(type: failureType)
            }
        }
    }
    
    /// 特殊需求,将详情重置为空
    public var detailText: String? = ""
    
    public weak var delegate: DHConnectCloudTimeoutVCDelegate?
    
    private var failureView: DHNetConnectFailureView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        setupConnectFailureView()
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    public func showOnParent(controller: UIViewController) {
        controller.addChildViewController(self)
        controller.view.addSubview(self.view)
        self.view.frame = controller.view.bounds
        
        controller.view.lc_transitionAnimation(type: .fade, direction: .fromBottom, duration: 0.3)
    }
    
    public func dismiss() {
        self.view.removeFromSuperview()
        self.parent?.view.lc_transitionAnimation(type: .fade, direction: .fromBottom, duration: 0.3)
        self.removeFromParentViewController()
    }
    
    func setupConnectFailureView() {
        failureView = DHNetConnectFailureView.xibInstance()
        failureView.setFailureType(type: failureType)
        failureView.imageView.image = UIImage(named: "adddevice_fail_configurationfailure")
    
        view.addSubview(failureView)
        
        failureView.snp.makeConstraints { make in
            make.edges.equalTo(self.view)
        }
        
        failureView.action = { [unowned self] (failureType, operationType: DHNetConnectFailureOperationType) in
            print("🍎🍎🍎 \(NSStringFromClass(self.classForCoder))::FailureType-\(failureType), OperationType-\(operationType)")
            
            if operationType == .tryAgain {
                //【*】海外门铃类型DB10、DB11、DS11,跳转软AP引导界面
                //【*】国内K5等设备,跳转软AP引导界面
                //【*】通用设备,重新倒计时
                if failureType == .overseasDoorbell || failureType == .door {
                    _ = self.baseBackToViewController(cls: DHApGuideViewController.self)
                } else {
                    self.delegate?.cloudTimeOutReconnectAction(controller: self)
                }
            } else if operationType == .continueToWait {
                //【*】国内K5等设备,重新倒计时
                self.delegate?.cloudTimeOutReconnectAction(controller: self)
            } else if operationType == .quit {
                self.baseBackToAddDeviceRoot()
            } else {
                self.baseExitAddDevice(showAlert: false, backToMain: false)
            }
        }
        
        failureView.help = {  [unowned self] in
            self.basePushToFAQ()
        }
        
        setupContents(type: failureType)
    }
    
    func setupContents(type: DHNetConnectFailureType) {
        //连接云平台超时,通用提示
        var title = "add_device_config_failed".lc_T
        var detail = ""
        
        //适用于软AP类错误【海外不需要语音提示】
        //【*】k5等显示请按设备语音操作
        if type == .overseasDoorbell {
            title = "add_device_connect_timeout".lc_T
            detail = ""
        } else if type == .door {
            title = "add_device_connect_timeout".lc_T
            detail = "add_device_operation_by_voice_tip".lc_T
        }
        
        if detailText == nil {
            detail = ""
        }
        
        failureView.contentLabel.text = title
        failureView.detailLabel.text = detail
        
    }
    
    // MARK: - DHAddBaseVCProtocol
    override func rightActionType() -> [DHAddBaseRightAction] {
        var actions: [DHAddBaseRightAction] = [.restart]
        if DHAddDeviceManager.sharedInstance.supportConfigModes.contains(.wired) {
            actions.append(.switchToWired)
        }
        
        return actions
    }
    
    override func leftActionType() -> DHAddBaseLeftAction {
        return .quit
    }
    
    override func isLeftActionShowAlert() -> Bool {
        return true
    }
}