SettingVC.swift
5.96 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// SettingVC.swift
// hhVDoctorSDK
//
// Created by 程言方 on 2020/11/13.
// Copyright © 2020 CocoaPods. All rights reserved.
//
import UIKit
import hhVDoctorSDK
class SettingVC : UIViewController {
@IBOutlet weak var mTableView : UITableView!
private var sections = [(String,[(String,Bool,Bool)])]()
override public func viewDidLoad() {
super.viewDidLoad()
setUpUI()
setUpData()
}
override func viewWillAppear(_ animated: Bool) {
}
func setUpUI(){
title = "设置"
mTableView.separatorStyle = .none
mTableView.rowHeight = UITableView.automaticDimension
mTableView.delegate = self
mTableView.dataSource = self
mTableView.separatorStyle = .none
}
func setUpData() {
let baseSetting = ("基础设置",[
("测试环境",HHSDKOptions.default.isDevelopment,true),
("扩展参数",false,false),
])
sections.append(baseSetting)
let videoSetting = ("音视频设置", [
("呼叫是否过滤生日性别",HHSDKOptions.default.mVideoOptions.filterCallerInfo,true),
("是否开启美颜",HHSDKOptions.default.mVideoOptions.allowBeauty,true),
("是否可以选择多人视频",HHSDKOptions.default.mVideoOptions.allowMulti,true),
("是否可以增加成员",HHSDKOptions.default.mVideoOptions.allowAddMember,true),
("视频完成后是否有评价",HHSDKOptions.default.mVideoOptions.allowEvaluate,true),
])
sections.append(videoSetting)
mTableView.reloadData()
}
}
extension SettingVC : UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].1.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SettingCell") as? SettingCell
let cellInfo = sections[indexPath.section].1[indexPath.row]
cell?.configCell(title: cellInfo.0, isOpen: cellInfo.1,isSwitch: cellInfo.2)
let view = UIView()
view.backgroundColor = .white
cell?.selectedBackgroundView = view
cell?.switchCallback = { [weak self] isOn in
self?.onConfigChange(indexPath: indexPath, isOpen: isOn)
}
return cell ?? UITableViewCell()
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
sections[section].0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch (indexPath.section,indexPath.row) {
case (0,1):
showEditAlter(title: "扩展参数",info: HHSDKOptions.default.mExtension) { info in
HHSDKOptions.default.mExtension = info
}
break
default:
break
}
}
}
extension SettingVC {
func onConfigChange(indexPath : IndexPath , isOpen : Bool) {
switch (indexPath.section,indexPath.row) {
case (0,0):
HHMSDK.default.switchEnv(isOpen)
NotificationCenter.default.post(name: Notification.Name(rawValue: "onEnvChange"), object: nil)
break
case (1,0):
HHSDKOptions.default.mVideoOptions.filterCallerInfo = isOpen
case (1,1):
HHSDKOptions.default.mVideoOptions.allowBeauty = isOpen
case (1,2):
HHSDKOptions.default.mVideoOptions.allowMulti = isOpen
case (1,3):
HHSDKOptions.default.mVideoOptions.allowAddMember = isOpen
case (1,4):
HHSDKOptions.default.mVideoOptions.allowEvaluate = isOpen
default:
break
}
}
func showEditAlter(title : String , info : String , callback : @escaping ((String)->Void)) {
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
alert.addTextField { (textField) in
textField.text = info
}
let cancelAction = UIAlertAction(title: "取消", style: .cancel) { _ in
alert.dismiss(animated: true, completion: nil)
}
cancelAction.setValue(UIColor.gray, forKey: "titleTextColor")
alert.addAction(cancelAction)
alert.addAction(UIAlertAction(title: "确定", style: .default, handler: {(_) in
let info = alert.textFields?.first?.text
guard info?.count ?? 0 > 0 else { return }
callback(info ?? "")
}))
present(alert, animated: true, completion: nil)
}
}
class SettingCell: UITableViewCell {
@IBOutlet weak var mTitleLabel: UILabel!
@IBOutlet weak var mSwitch : UISwitch!
@IBOutlet weak var mArrow : UIImageView!
var switchCallback : ((Bool) -> Void)?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func configCell(title: String, isOpen : Bool, isSwitch: Bool) {
mTitleLabel.text = title
mSwitch.isOn = isOpen
if isSwitch {
mSwitch.isHidden = false
mArrow.isHidden = true
}else{
mSwitch.isHidden = true
mArrow.isHidden = false
}
}
@IBAction func onSwitch(_ sender : UISwitch) {
switchCallback?(sender.isOn)
}
}