SettingVC.swift
9.21 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
//
// 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)
let infoListSetting = ("信息流设置",[
("是否过滤总结卡片",HHSDKOptions.default.mMessageOptions.isFilterSummary,true),
("是否过滤药卡",HHSDKOptions.default.mMessageOptions.isFilterMedicinal,true),
("小助手默认头像",false,false),
("小助手默认昵称",false,false),
("信息流默认标题",false,false),
("开启定位",false,true),
])
sections.append(infoListSetting)
let userCenterSetting = ("个人中心设置",[
("是否隐藏个人中心入口",HHSDKOptions.default.mUserCenterOptions.hideUserCenter,true),
("是否展示激活码入口",HHSDKOptions.default.mUserCenterOptions.enableActivate,true),
("是否展示档案库入口",HHSDKOptions.default.mUserCenterOptions.enableMedical,true),
("档案库是否可以添加成员",HHSDKOptions.default.mUserCenterOptions.canAddMember,true),
])
sections.append(userCenterSetting)
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
case (2,2):
showEditAlter(title: "小助手默认头像",info: HHSDKOptions.default.mExtension) { info in
HHSDKOptions.default.mMessageOptions.defaultDocHeader = info
}
break
case (2,3):
showEditAlter(title: "小助手默认昵称",info: HHSDKOptions.default.mExtension) { info in
HHSDKOptions.default.mMessageOptions.defaultDocName = info
}
break
case (2,4):
showEditAlter(title: "信息流默认标题",info: HHSDKOptions.default.mExtension) { info in
HHSDKOptions.default.mMessageOptions.messageTitle = 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
case (2,0):
HHSDKOptions.default.mMessageOptions.isFilterSummary = isOpen
case (2,1):
HHSDKOptions.default.mMessageOptions.isFilterMedicinal = isOpen
case (2,5):
// if isOpen {
// HHMSDK.default.aliPayHook = {(url,scheme,callback) in
// let isOk = AlipaySDK.defaultService()?.payInterceptor(withUrl: url, fromScheme: scheme, callback: { (result) in
// callback(result as? [String : Any] ?? ["test":""])
// })
//
//
// return isOk ?? false
// }
// }else{
//
// HHMSDK.default.aliPayHook = nil
// }
if isOpen {
HHLocation.default.startLocation(lng: "116.431941", lat: "39.940199")
}else{
HHLocation.default.closeLocation()
}
case (3,0):
HHSDKOptions.default.mUserCenterOptions.hideUserCenter = isOpen
case (3,1):
HHSDKOptions.default.mUserCenterOptions.enableActivate = isOpen
case (3,2):
HHSDKOptions.default.mUserCenterOptions.enableMedical = isOpen
case (3,3):
HHSDKOptions.default.mUserCenterOptions.canAddMember = 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)
}
}