/
CameraCell.swift
100 lines (86 loc) · 3.17 KB
/
CameraCell.swift
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
//=============================================================================
// Copyright 2016 YI Technologies, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of YI
// Technologies, Inc. ("Confidential Information"). You shall not
// disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with YI.
//
// YI MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. YI SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
import UIKit
class CameraCell: UICollectionViewCell, CameraListener {
@IBOutlet weak var mCameraImage: UIImageView!
@IBOutlet weak var mNameLabel: UILabel!
@IBOutlet weak var mStateLabel: UILabel!
private var mCamera: Camera?
func setCamera(camera: Camera?) {
if (mCamera !== camera) {
mCamera?.setListener(listener: nil)
mCamera = camera
mCamera?.setListener(listener: self)
}
updateView()
}
func onStateChanged(camera: Camera, newState: Camera.State, oldState: Camera.State) {
updateView()
}
private func updateView() {
updateNameLabel()
updateStateLabel()
updateImage()
}
private func updateNameLabel() {
var name = ""
if (mCamera != nil) {
name = mCamera!.getHost()
if (name == "") {
name = mCamera!.getIP()
}
}
mNameLabel.text = name
}
private func updateStateLabel() {
if (mCamera == nil) {
mStateLabel.text = "Connecting"
} else {
switch mCamera!.getStatus() {
case .Disconnected, .Connecting:
mStateLabel.text = "Disconnected"
break
case .Connected:
mStateLabel.text = "Connected"
break
case .StartRecording:
mStateLabel.text = "Start Recording"
break
case .Recording:
mStateLabel.text = "Recording"
break
}
}
}
private func updateImage() {
if (mCamera == nil) {
mCameraImage.image = UIImage(named: "inactive_camera")
} else {
switch mCamera!.getStatus() {
case .Disconnected, .Connecting:
mCameraImage.image = UIImage(named: "inactive_camera")
break
case .Connected, .StartRecording:
mCameraImage.image = UIImage(named: "white_camera")
break
case .Recording:
mCameraImage.image = UIImage(named: "recording_camera")
break
}
}
}
}