MainHomeTableViewController.swift
22 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
//
// MainHomeTableViewController.swift
// YouerLiveVideo
//
// Created by 葛建军 on 17/5/19.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
import AVKit
class MainHomeTableViewController: UITableViewController {
@IBOutlet var tableHeaderView: UIView!
let current=AppDelegate.instance().accountManager
override func viewDidLoad() {
super.viewDidLoad()
tableHeaderView.frame.size.height=getScreenWidth()/12*5
settingIconAndTitle()
settingCarouselView()
}
//设置左上角头像及背景色等
func settingIconAndTitle(){
let photo=UIImageView(frame: CGRect(x: 0, y: 0, width: 35, height: 35))
photo.sd_setImage(with: URL(string: current.photo()), placeholderImage: UIImage(named: "defphoto"))
photo.layer.cornerRadius=35/2
photo.layer.masksToBounds=true
let leftBarButtonItem=UIBarButtonItem(customView: photo)
self.navigationItem.leftBarButtonItem=leftBarButtonItem
self.configTheme()
self.navigationController?.navigationBar.barStyle=UIBarStyle.black
}
//设置轮播图
func settingCarouselView(){
AppDelegate.instance().httpServer.getLunboList(parameters: ["type": 0 as AnyObject]) { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
var lineModelAry:[InLineModel]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineModelAry.append(InLineModel(j: item))
lineAry.append(item["f_Img"].stringValue)
}
if lineModelAry.count>0{
let jyScrollViews=JYScrollView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: getScreenWidth()/12*5))
jyScrollViews.banner(with: lineAry, imageType: JYImageType.urlType, placeHolder: "default") { (index) in
NSLog("点击了轮播图 图片ID:\(lineModelAry[index].f_Id)")
}
jyScrollViews.timeInterval=2
self.tableHeaderView.addSubview(jyScrollViews)
}
}, failHandler: { (error) in
self.view.makeToast("获取轮播图失败:\(error.localizedDescription)")
})
}else{
self.view.makeToast("获取轮播图失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)")
}
}else{
self.view.makeToast("获取轮播图失败:\(error!.description)")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row==0{
return (getScreenWidth()-45)/2/33*25+80
}else if indexPath.row==1{
return (getScreenWidth()-45)/2/33*16+132
}else if indexPath.row==2{
return (getScreenWidth()-40)/3+170.5
}else{
return (getScreenWidth()-40)/3+110
}
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return tableHeaderView
}
/*
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row==0{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell0", for: indexPath) as! HomeFirstTableViewCell
return cell
}else if indexPath.row==1{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath)
return cell
}else if indexPath.row==2{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath)
return cell
}else{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell3", for: indexPath)
return cell
}
}
*/
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row==0{
//排行
let vc = UIStoryboard(name: "HomePage", bundle: nil).instantiateViewController(withIdentifier: "RankingTableViewController") as! RankingTableViewController
vc.openIndexAry=[0,4]
self.navigationController?.pushViewController(vc, animated: true)
}else if indexPath.row==1{
//热门微课
self.tabBarController?.selectedIndex=2
}else if indexPath.row==2{
//资源
self.tabBarController?.selectedIndex=1
}else{
//校园电视台
self.tabBarController?.selectedIndex=3
}
}
}
class InLineModel: NSObject {
var f_Id:String="" //标识字段,Guid标识 ,
var f_DeleteMark:Bool=false //删除标识,1-已删除
var f_CreatorTime:String="" //创建时间
var f_CreatorUserId:String="" //创建人员ID
var f_LastModifyTime:String="" //最近一次编辑时间
var f_LastModifyUserId:String=""//最近一次编辑人员
var f_DeleteTime:String="" //删除时间
var f_DeleteUserId:String="" //删除人员
var f_Img:String="" //轮播图片
var f_Type:Int=0 //轮播图位置 0-视频云前端轮播图 1-校园电视台轮播图
init(j:JSON) {
f_Id=j["f_Id"].stringValue
f_DeleteMark=j["f_DeleteMark"].boolValue
f_CreatorTime=j["f_CreatorTime"].stringValue
f_CreatorUserId=j["f_CreatorUserId"].stringValue
f_LastModifyTime=j["f_LastModifyTime"].stringValue
f_LastModifyUserId=j["f_LastModifyUserId"].stringValue
f_DeleteTime=j["f_DeleteTime"].stringValue
f_DeleteUserId=j["f_DeleteUserId"].stringValue
f_Img=j["f_Img"].stringValue
f_Type=j["f_Type"].intValue
}
}
class HomeFirstTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if appRootViewController().childViewControllers.count>0 {
if indexPath.row==0{
//点击进入学校
let vc = UIStoryboard(name: "HomePage", bundle: nil).instantiateViewController(withIdentifier: "RankingTableViewController") as! RankingTableViewController
vc.openIndexAry=[0]
((appRootViewController().childViewControllers[0] as! MViewController).selectedViewController as! UINavigationController).pushViewController(vc, animated: true)
}else{
//点击进入教师
let vc = UIStoryboard(name: "HomePage", bundle: nil).instantiateViewController(withIdentifier: "RankingTableViewController") as! RankingTableViewController
vc.openIndexAry=[4]
((appRootViewController().childViewControllers[0] as! MViewController).selectedViewController as! UINavigationController).pushViewController(vc, animated: true)
}
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-45)/2, height: (getScreenWidth()-45)/2/33*25)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "HomeFirstCollectionViewCell", for: indexPath) as! HomeFirstCollectionViewCell
if indexPath.row==0{
cell.nameLabel.text="学校"
cell.iconImageView.image=UIImage(named: "ranking_school")
}else{
cell.nameLabel.text="教师"
cell.iconImageView.image=UIImage(named: "ranking_teacher")
}
return cell
}
}
class HomeFirstCollectionViewCell: UICollectionViewCell {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var iconImageView: UIImageView!
}
class HomeSecondTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
var dataSet:[MicroCourseModel]=[]
override func awakeFromNib() {
super.awakeFromNib()
getHotCourseList()
}
//获取热门微课前两门
func getHotCourseList(){
let parameters:Dictionary<String,AnyObject>=["type":0 as AnyObject,"pageIndex":0 as AnyObject,"pageSize":2 as AnyObject]
AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
self.dataSet.removeAll()
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
self.dataSet.append(MicroCourseModel(j: item))
}
(self.viewWithTag(1) as! UICollectionView).reloadData()
}, failHandler: { (error) in
appRootViewController().view.makeToast("获取热门微课失败:\(error.localizedDescription)")
})
}else{
appRootViewController().view.makeToast("获取热门微课失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)")
}
}else{
appRootViewController().view.makeToast("获取热门微课失败:\(error!.description)")
}
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let url = URL(string:dataSet[indexPath.row].f_ResourceUrl)
let player = AVPlayerViewController()
player.player = AVPlayer(url: url!)
player.videoGravity = AVLayerVideoGravityResizeAspect
appRootViewController().present(player, animated: true, completion: nil)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-45)/2, height: ((getScreenWidth()-45)/2/33*16+67))
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataSet.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "HomeSecondCollectionViewCell", for: indexPath) as! HomeSecondCollectionViewCell
cell.setUpWithItem(item: dataSet[indexPath.row])
return cell
}
}
//MARK: - 排行model
class MicroCourseModel:NSObject {
var f_Id:String="" //标识字段,Guid标识 ,
var f_DeleteMark:Bool=false //删除标识,1-已删除
var f_CreatorTime:String="" //创建时间
var f_CreatorUserId:String="" //创建人员ID
var f_LastModifyTime:String="" //最近一次编辑时间
var f_LastModifyUserId:String=""//最近一次编辑人员
var f_DeleteTime:String="" //删除时间
var f_DeleteUserId:String="" //删除人员
var f_Img:String="" //轮播图片
var f_Title:String="" //课件名称
var f_CreatorName:String="" //上传人员昵称
var f_Pv:Int=0 //浏览量
var f_DownloadSum:Int=0 //下载量
var f_LoveSum:Int=0 //点赞量
var f_Price:Int=0 //价格
var f_WaveId:String="" //所属教材ID
var f_ChapterId:String="" //所属章节
var f_TopicId:String="" //所属知识点
var f_TestId:String="" //所属考点
var f_SchoolId:String="" //上传老师的学校ID
var f_IsExamine:Int=0 //审核状态:0-未审核,1-审核通过,2-审核不通过
var f_ExamineUserId:String="" //审核人ID
var f_ExamineName:String="" //审核人姓名
var f_ExamineDatetime:String="" //审核日期
var f_ResourceType:Int=0 //资源类型 0-微课 1-资源 2-电视台
var f_ResourceUrl:String="" //资源地址
var f_IsOpen:Bool=false //是否公开
var f_Detail:String="" //资源简介
var f_TelevisionId:String="" //电视台目录
init(j:JSON) {
f_Id=j["f_Id"].stringValue
f_DeleteMark=j["f_DeleteMark"].boolValue
f_CreatorTime=j["f_CreatorTime"].stringValue
f_CreatorUserId=j["f_CreatorUserId"].stringValue
f_LastModifyTime=j["f_LastModifyTime"].stringValue
f_LastModifyUserId=j["f_LastModifyUserId"].stringValue
f_DeleteTime=j["f_DeleteTime"].stringValue
f_DeleteUserId=j["f_DeleteUserId"].stringValue
f_Img=j["f_Img"].stringValue
f_Title=j["f_Title"].stringValue
f_CreatorName=j["f_CreatorName"].stringValue
f_Pv=j["f_Pv"].intValue
f_DownloadSum=j["f_DownloadSum"].intValue
f_LoveSum=j["f_LoveSum"].intValue
f_Price=j["f_Price"].intValue
f_WaveId=j["f_WaveId"].stringValue
f_ChapterId=j["f_ChapterId"].stringValue
f_TopicId=j["f_TopicId"].stringValue
f_TestId=j["f_TestId"].stringValue
f_SchoolId=j["f_SchoolId"].stringValue
f_IsExamine=j["f_IsExamine"].intValue
f_ExamineUserId=j["f_ExamineUserId"].stringValue
f_ExamineName=j["f_ExamineName"].stringValue
f_ExamineDatetime=j["f_ExamineDatetime"].stringValue
f_ResourceType=j["f_ResourceType"].intValue
f_ResourceUrl=j["f_ResourceUrl"].stringValue
f_IsOpen=j["f_IsOpen"].boolValue
f_Detail=j["f_Detail"].stringValue
f_TelevisionId=j["f_TelevisionId"].stringValue
}
}
class HomeSecondCollectionViewCell: UICollectionViewCell {
@IBOutlet var iconImageView: UIImageView!
@IBOutlet var nameLabel: UILabel!
@IBOutlet var teacherNameLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
@IBOutlet var readCountLabel: UILabel!
func setUpWithItem(item:MicroCourseModel){
iconImageView.sd_setImage(with: URL(string: item.f_Img), placeholderImage: UIImage(named: "icon_course_placeholder"))
nameLabel.text=item.f_Title
teacherNameLabel.text="主讲师:\(item.f_CreatorName) 老师"
dateLabel.text=item.f_CreatorTime
readCountLabel.text="\(item.f_Pv)"
}
}
class HomeThirdTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
var dataSet:[MicroCourseModel]=[]
override func awakeFromNib() {
super.awakeFromNib()
getHotCourseList()
}
//获取资源前三门
func getHotCourseList(){
let parameters:Dictionary<String,AnyObject>=["type":1 as AnyObject,"pageIndex":0 as AnyObject,"pageSize":3 as AnyObject]
AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
self.dataSet.removeAll()
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
self.dataSet.append(MicroCourseModel(j: item))
}
(self.viewWithTag(1) as! UICollectionView).reloadData()
}, failHandler: { (error) in
appRootViewController().view.makeToast("获取资源失败:\(error.localizedDescription)")
})
}else{
appRootViewController().view.makeToast("获取资源失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)")
}
}else{
appRootViewController().view.makeToast("获取资源失败:\(error!.description)")
}
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//点击下载并打开资源文档
let download = DownLoad.share
download.superVC = ((appRootViewController().childViewControllers[0] as! MViewController).selectedViewController as! UINavigationController).viewControllers[0]
download.downLoadWithUrl(url: dataSet[indexPath.row].f_ResourceUrl)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-40)/3, height: (getScreenWidth()-40)/3+105.5)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataSet.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "HomeThirdCollectionViewCell", for: indexPath) as! HomeThirdCollectionViewCell
cell.setUpWithItem(item: dataSet[indexPath.row])
return cell
}
}
class HomeThirdCollectionViewCell: UICollectionViewCell {
@IBOutlet var iconImageView: UIImageView!
@IBOutlet var nameLabel: UILabel!
@IBOutlet var teacherNameLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
@IBOutlet var readCountLabel: UILabel!
func setUpWithItem(item:MicroCourseModel){
iconImageView.sd_setImage(with: URL(string: item.f_Img), placeholderImage: UIImage(named: "icon_course_placeholder"))
nameLabel.text=item.f_Title
teacherNameLabel.text="上传者:\(item.f_CreatorName) 老师"
dateLabel.text=item.f_CreatorTime
readCountLabel.text="\(item.f_DownloadSum)"
}
}
class HomeFourTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
var dataSet:[MicroCourseModel]=[]
override func awakeFromNib() {
super.awakeFromNib()
getHotCourseList()
}
//获取校园电视台前三门
func getHotCourseList(){
let parameters:Dictionary<String,AnyObject>=["type":2 as AnyObject,"pageIndex":0 as AnyObject,"pageSize":3 as AnyObject]
AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
self.dataSet.removeAll()
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
self.dataSet.append(MicroCourseModel(j: item))
}
(self.viewWithTag(1) as! UICollectionView).reloadData()
}, failHandler: { (error) in
appRootViewController().view.makeToast("获取校园电视台失败:\(error.localizedDescription)")
})
}else{
appRootViewController().view.makeToast("获取校园电视台失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)")
}
}else{
appRootViewController().view.makeToast("获取校园电视台失败:\(error!.description)")
}
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//点击进入学校 appRootViewController()
let vc = Story.instantiateViewControllerWithIdentifier("TVStationInforViewControllerVC", storyName: "TVStation") as! TVStationInforViewController
if collectionView.tag == 1{
vc.TVStationProgram = TVStationInfor(item: dataSet[indexPath.row])
vc.title = dataSet[indexPath.row].f_Title
}else if collectionView.tag == 3{
vc.title = dataSet[indexPath.row].f_Title
vc.excellentTVStationProgram = TVStationSubject(item: dataSet[indexPath.row])
}
((appRootViewController().childViewControllers[0] as! MViewController).selectedViewController as! UINavigationController).pushViewController(vc, animated: true)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-40)/3, height: (getScreenWidth()-40)/3+30)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataSet.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "HomeFourCollectionViewCell", for: indexPath) as! HomeFourCollectionViewCell
cell.setUpWithItem(item: dataSet[indexPath.row])
return cell
}
}
class HomeFourCollectionViewCell: UICollectionViewCell {
@IBOutlet var iconImageView: UIImageView!
@IBOutlet var nameLabel: UILabel!
func setUpWithItem(item:MicroCourseModel){
iconImageView.sd_setImage(with: URL(string: item.f_Img), placeholderImage: UIImage(named: "icon_course_placeholder"))
nameLabel.text=item.f_Title
}
}