Commit 349ae761d39ebe18d7c23d415027e44dd1c0a373

Authored by 葛建军
1 parent aa722845
Exists in newLive

no message

YouerLiveVideo/YouerLiveVideo/controllers/MicroCourse/MicroCourseViewController.swift
... ... @@ -7,6 +7,7 @@
7 7 //
8 8  
9 9 import UIKit
  10 +import AVKit
10 11  
11 12 class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UISearchControllerDelegate,UISearchResultsUpdating {
12 13 @IBOutlet var tableView: UITableView!
... ... @@ -18,14 +19,14 @@ class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableVie
18 19 var searchController:UISearchController!
19 20 var dataSetAry:[String]=["葛建军","张道峰","徐晓杰","左承","段合江"]
20 21 var searchAry:[String]=[]
21   - var currentPage:Int=0 //当前页数,每次取十个数据
  22 + var currentPage:Int=1 //当前页数,每次取十个数据
22 23 var resourceData:[MicroCourseModel]=[]
23 24 override func viewDidLoad() {
24 25 super.viewDidLoad()
25 26 self.configTheme()
26 27 addSearchController()
27 28 addRefresh()
28   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  29 + self.refreshLivesAction(parameters: ["type":0 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
29 30 if success{
30 31 self.tableView.reloadData()
31 32 }
... ... @@ -53,9 +54,9 @@ class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableVie
53 54 func addRefresh(){
54 55 let header=MJRefreshNormalHeader(refreshingBlock: {
55 56 //下拉刷新
56   - self.currentPage=0
  57 + self.currentPage=1
57 58 self.resourceData.removeAll()
58   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  59 + self.refreshLivesAction(parameters: ["type":0 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
59 60 if success{
60 61 self.tableView.reloadData()
61 62 }
... ... @@ -66,7 +67,7 @@ class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableVie
66 67 tableView.mj_header=header
67 68 tableView.mj_footer=MJRefreshBackNormalFooter(refreshingBlock: {
68 69 //上拉加载更多
69   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  70 + self.refreshLivesAction(parameters: ["type":0 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
70 71 if success{
71 72 self.tableView.reloadData()
72 73 }
... ... @@ -75,9 +76,8 @@ class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableVie
75 76 })
76 77 }
77 78 // MARK: - 刷新数据接口
78   - func refreshLivesAction(tag:Int,completionHandler:@escaping (Bool) -> ()){
79   - let parameters:Dictionary<String,AnyObject>=["type":0 as AnyObject,"pageIndex":tag as AnyObject,"pageSize":1 as AnyObject]
80   - AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in
  79 + func refreshLivesAction(parameters:Dictionary<String,AnyObject>,completionHandler:@escaping (Bool) -> ()){
  80 + AppDelegate.instance().httpServer.postResourceList(parameters: parameters) { (str, error) in
81 81 var success:Bool=true
82 82 if error==nil {
83 83 if JSON.fromString(jsonString: str)!["status"].intValue == 1{
... ... @@ -129,8 +129,13 @@ class MicroCourseViewController: UIViewController,UITableViewDelegate,UITableVie
129 129 self.navigationController?.pushViewController(vc, animated: true)
130 130 }else{
131 131 // let vc = UIStoryboard(name: "Resource", bundle: nil).instantiateViewController(withIdentifier: "LiveInforViewControllerVC") as! LiveInforViewController
132   -// vc.item=resourceData[indexPath.row]
  132 +
133 133 // self.navigationController?.pushViewController(vc, animated: true)
  134 + let url = URL(string:resourceData[indexPath.row].f_ResourceUrl)
  135 + let player = AVPlayerViewController()
  136 + player.player = AVPlayer(url: url!)
  137 + player.videoGravity = AVLayerVideoGravityResizeAspect
  138 + self.present(player, animated: true, completion: nil)
134 139 }
135 140 }
136 141 //取消键盘输入状态
... ...
YouerLiveVideo/YouerLiveVideo/controllers/Resource/FilterViewController.swift
... ... @@ -13,7 +13,7 @@ class FilterViewController: UIViewController,FilterViewDelegate {
13 13 var dataSchoolSection:[SchoolSection]=[]
14 14 var dataGrade:[Grade]=[]
15 15 var dataSubject:[Subject]=[]
16   -
  16 + var dataMaterials:[Material]=[]
17 17 var type=FilterParameter()
18 18 override func viewDidLoad() {
19 19 super.viewDidLoad()
... ... @@ -38,25 +38,35 @@ class FilterViewController: UIViewController,FilterViewDelegate {
38 38 case 3:
39 39 //学科
40 40 type.subject=arry[0].f_Id
  41 + case 4:
  42 + //教材
  43 + type.materials=arry[0].f_Id
41 44 default:
  45 +
42 46 break
43 47 }
44 48 }else{
45 49 filterView.selected = -1
46 50 if index==2{
47 51 type.grade=nil
  52 + }else if index==4{
  53 + type.materials=nil
48 54 }
49 55 }
50 56  
51 57 filterView.isOpen=false
52 58 filterView.changeItems(array: arry)
53   - filterView.constraints.last!.constant=60+(getScreenWidth()-80)/12
  59 + if index==4{
  60 + filterView.constraints.last!.constant=60+(getScreenWidth()-80)/12*2+10
  61 + }else{
  62 + filterView.constraints.last!.constant=60+(getScreenWidth()-80)/12
  63 + }
54 64 filterView.collectionView.reloadData()
55 65 }
56 66 @IBAction func determineAction(_ sender: UIButton) {
57 67 // AppDelegate.instance().httpServer.postResourceList(parameters: <#T##[String : AnyObject]?#>, completionHandler: <#T##(String?, NSError?) -> ()#>)
58 68 }
59   - //请求年级 并添加控件
  69 + //请求学段 并添加控件
60 70 func getSchoolSection(){
61 71 SVProgressHUD.show(withStatus: "获取学段...")
62 72 SVProgressHUD.setDefaultMaskType(.black)
... ... @@ -89,15 +99,19 @@ class FilterViewController: UIViewController,FilterViewDelegate {
89 99 self.scrollContentView.addArrangedSubview(filterView)
90 100 filterView.translatesAutoresizingMaskIntoConstraints=false
91 101 filterView.addConstraint(NSLayoutConstraint(item: filterView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1.0, constant: 60+(getScreenWidth()-80)/12))
92   - for i in 1..<3{
  102 + for i in 1...3{
93 103 let filterView=Bundle.main.loadNibNamed("FilterView", owner: nil, options: nil)![0] as! FilterView
94   - filterView.frame.size=CGSize(width: getScreenWidth(), height: 60+(getScreenWidth()-80)/12)
  104 + filterView.frame.size=CGSize(width: getScreenWidth(), height: 60+(getScreenWidth()-80)/12*2+10)
95 105 filterView.delegate=self
96 106 filterView.tag=i
97 107 filterView.setUpWithItems(title: self.nameAry[i], array: [])
98 108 self.scrollContentView.addArrangedSubview(filterView)
99 109 filterView.translatesAutoresizingMaskIntoConstraints=false
100   - filterView.addConstraint(NSLayoutConstraint(item: filterView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1.0, constant: 60+(getScreenWidth()-80)/12))
  110 + if i==3{
  111 + filterView.addConstraint(NSLayoutConstraint(item: filterView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1.0, constant: 60+(getScreenWidth()-80)/12*2+10))
  112 + }else{
  113 + filterView.addConstraint(NSLayoutConstraint(item: filterView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1.0, constant: 60+(getScreenWidth()-80)/12))
  114 + }
101 115 }
102 116 if self.dataSchoolSection.count>0{
103 117 self.getGradeWithSchoolSectionID(id: self.dataSchoolSection[0].f_Id, index: 2)
... ... @@ -112,10 +126,22 @@ class FilterViewController: UIViewController,FilterViewDelegate {
112 126 getGradeWithSchoolSectionID(id: dataSchoolSection[index].f_Id, index: 2)
113 127 case 1:
114 128 type.grade=dataGrade[index].f_Id
  129 + if self.type.schoolSection != nil && self.type.grade != nil && self.type.subject != nil{
  130 + self.getMaterials(index: 4)
  131 + }else{
  132 + self.dataMaterials.removeAll()
  133 + self.setupFilterView(index: 4, arry: self.dataMaterials)
  134 + }
115 135 case 2:
116 136 type.subject=dataSubject[index].f_Id
117   - case 3: break
118   -
  137 + if self.type.schoolSection != nil && self.type.grade != nil && self.type.subject != nil{
  138 + self.getMaterials(index: 4)
  139 + }else{
  140 + self.dataMaterials.removeAll()
  141 + self.setupFilterView(index: 4, arry: self.dataMaterials)
  142 + }
  143 + case 3:
  144 + type.materials=dataMaterials[index].f_Id
119 145 default: break
120 146  
121 147 }
... ... @@ -143,14 +169,17 @@ class FilterViewController: UIViewController,FilterViewDelegate {
143 169 self.view.makeToast("获取年级失败:\(error!.description)")
144 170 }
145 171 self.setupFilterView(index: index, arry: self.dataGrade)
  172 + if self.type.schoolSection != nil && self.type.grade != nil && self.type.subject != nil{
  173 + self.getMaterials(index: 4)
  174 + }else{
  175 + self.dataMaterials.removeAll()
  176 + self.setupFilterView(index: 4, arry: self.dataMaterials)
  177 + }
146 178 }
147 179 }
148 180 //请求学科 并刷新
149 181 func getSubjects(index:Int){
150   - SVProgressHUD.show(withStatus: "获取学科...")
151   - SVProgressHUD.setDefaultMaskType(.black)
152 182 AppDelegate.instance().httpServer.getSubjects { (str, error) in
153   - SVProgressHUD.dismiss()
154 183 self.dataSubject.removeAll()
155 184 if error==nil {
156 185 if JSON.fromString(jsonString: str)!["status"].intValue == 1{
... ... @@ -168,6 +197,38 @@ class FilterViewController: UIViewController,FilterViewDelegate {
168 197 self.view.makeToast("获取学科失败:\(error!.description)")
169 198 }
170 199 self.setupFilterView(index: index, arry: self.dataSubject)
  200 + if self.type.schoolSection != nil && self.type.grade != nil && self.type.subject != nil{
  201 + self.getMaterials(index: 4)
  202 + }else{
  203 + self.dataMaterials.removeAll()
  204 + self.setupFilterView(index: 4, arry: self.dataMaterials)
  205 + }
  206 + }
  207 + }
  208 + //请求教材 并刷新
  209 + func getMaterials(index:Int){
  210 + SVProgressHUD.show(withStatus: "获取教材...")
  211 + SVProgressHUD.setDefaultMaskType(.black)
  212 + let parameters:Dictionary<String,AnyObject>=["vid":0 as AnyObject,"sid":type.subject as AnyObject,"stid":type.schoolSection as AnyObject,"gid":type.grade as AnyObject]
  213 + AppDelegate.instance().httpServer.getCourseWaves(parameters: parameters) { (str, error) in
  214 + SVProgressHUD.dismiss()
  215 + self.dataMaterials.removeAll()
  216 + if error==nil {
  217 + if JSON.fromString(jsonString: str)!["status"].intValue == 1{
  218 + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
  219 + for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
  220 + self.dataMaterials.append(Material(j: item))
  221 + }
  222 + }, failHandler: { (error) in
  223 + self.view.makeToast("获取教材失败:\(error.localizedDescription)")
  224 + })
  225 + }else{
  226 + self.view.makeToast("获取教材失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)")
  227 + }
  228 + }else{
  229 + self.view.makeToast("获取教材失败:\(error!.description)")
  230 + }
  231 + self.setupFilterView(index: index, arry: self.dataMaterials)
171 232 }
172 233 }
173 234 override func didReceiveMemoryWarning() {
... ... @@ -228,3 +289,37 @@ class Subject: filterModel {
228 289 f_SubjectName=j["f_SubjectName"].stringValue
229 290 }
230 291 }
  292 +class Material: filterModel {
  293 + /*
  294 + f_WaveTitle (string, optional): 教材名称 ,
  295 + f_VersionId (string, optional): 版本ID ,
  296 + f_VersionName (string, optional): 版本名称 ,
  297 + f_SubjectId (string, optional): 学科ID ,
  298 + f_SubjectName (string, optional): 学科名称 ,
  299 + f_SchoolTypeId (string, optional): 学段ID ,
  300 + f_SchoolTypeName (string, optional): 学段名称 ,
  301 + f_GradeId (string, optional): 年级ID ,
  302 + f_GradeName (string, optional): 年级名称
  303 + */
  304 + var f_WaveTitle:String=""
  305 + var f_VersionId:String=""
  306 + var f_VersionName:String=""
  307 + var f_SubjectId:String=""
  308 + var f_SubjectName:String=""
  309 + var f_SchoolTypeId:String=""
  310 + var f_SchoolTypeName:String=""
  311 + var f_GradeId:String=""
  312 + var f_GradeName:String=""
  313 + override init(j:JSON) {
  314 + super.init(j: j)
  315 + f_WaveTitle=j["f_WaveTitle"].stringValue
  316 + f_VersionId=j["f_VersionId"].stringValue
  317 + f_VersionName=j["f_VersionName"].stringValue
  318 + f_SubjectId=j["f_SubjectId"].stringValue
  319 + f_SubjectName=j["f_SubjectName"].stringValue
  320 + f_SchoolTypeId=j["f_SchoolTypeId"].stringValue
  321 + f_SchoolTypeName=j["f_SchoolTypeName"].stringValue
  322 + f_GradeId=j["f_GradeId"].stringValue
  323 + f_GradeName=j["f_GradeName"].stringValue
  324 + }
  325 +}
... ...
YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift
... ... @@ -18,14 +18,14 @@ class ResourceViewController: UIViewController,UITableViewDelegate,UITableViewDa
18 18 var searchController:UISearchController!
19 19 var dataSetAry:[String]=["葛建军","张道峰","徐晓杰","左承","段合江"]
20 20 var searchAry:[String]=[]
21   - var currentPage:Int=0 //当前页数,每次取十个数据
  21 + var currentPage:Int=1 //当前页数,每次取十个数据
22 22 var resourceData:[MicroCourseModel]=[]
23 23 override func viewDidLoad() {
24 24 super.viewDidLoad()
25 25 self.configTheme()
26 26 addSearchController()
27 27 addRefresh()
28   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  28 + self.refreshLivesAction(parameters: ["type":1 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
29 29 if success{
30 30 self.tableView.reloadData()
31 31 }
... ... @@ -53,9 +53,9 @@ class ResourceViewController: UIViewController,UITableViewDelegate,UITableViewDa
53 53 func addRefresh(){
54 54 let header=MJRefreshNormalHeader(refreshingBlock: {
55 55 //下拉刷新
56   - self.currentPage=0
  56 + self.currentPage=1
57 57 self.resourceData.removeAll()
58   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  58 + self.refreshLivesAction(parameters: ["type":1 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
59 59 if success{
60 60 self.tableView.reloadData()
61 61 }
... ... @@ -66,7 +66,7 @@ class ResourceViewController: UIViewController,UITableViewDelegate,UITableViewDa
66 66 tableView.mj_header=header
67 67 tableView.mj_footer=MJRefreshBackNormalFooter(refreshingBlock: {
68 68 //上拉加载更多
69   - self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in
  69 + self.refreshLivesAction(parameters: ["type":1 as AnyObject,"orderby":1 as AnyObject,"pageIndex":self.currentPage as AnyObject,"pageSize":10 as AnyObject], completionHandler: { (success) in
70 70 if success{
71 71 self.tableView.reloadData()
72 72 }
... ... @@ -75,9 +75,8 @@ class ResourceViewController: UIViewController,UITableViewDelegate,UITableViewDa
75 75 })
76 76 }
77 77 // MARK: - 刷新数据接口
78   - func refreshLivesAction(tag:Int,completionHandler:@escaping (Bool) -> ()){
79   - let parameters:Dictionary<String,AnyObject>=["type":1 as AnyObject,"pageIndex":tag as AnyObject,"pageSize":1 as AnyObject]
80   - AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in
  78 + func refreshLivesAction(parameters:Dictionary<String,AnyObject>,completionHandler:@escaping (Bool) -> ()){
  79 + AppDelegate.instance().httpServer.postResourceList(parameters: parameters) { (str, error) in
81 80 var success:Bool=true
82 81 if error==nil {
83 82 if JSON.fromString(jsonString: str)!["status"].intValue == 1{
... ...
YouerLiveVideo/YouerLiveVideo/controllers/Resource/View/FilterView.swift
... ... @@ -18,6 +18,7 @@ class FilterView: UIView,UICollectionViewDelegate,UICollectionViewDataSource,UIC
18 18 var numberLines:Int!
19 19 var cellWidth=(getScreenWidth()-80)/3
20 20 var cellHeight=(getScreenWidth()-80)/12
  21 + var tableViewWidth=getScreenWidth()-40
21 22 override func awakeFromNib() {
22 23 super.awakeFromNib()
23 24 collectionView.register(UINib(nibName: "FilterCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "identifier")
... ... @@ -25,28 +26,53 @@ class FilterView: UIView,UICollectionViewDelegate,UICollectionViewDataSource,UIC
25 26 func setUpWithItems(title:String,array:[filterModel]) {
26 27 titleLabel.text=title
27 28 dataAry=array
28   - numberLines = array.count%3 > 0 ? array.count/3+1 : array.count/3
  29 + if self.tag==3{
  30 + numberLines = array.count
  31 + }else{
  32 + numberLines = array.count%3 > 0 ? array.count/3+1 : array.count/3
  33 + }
29 34 self.collectionView.reloadData()
30 35 }
31 36 func changeItems(array:[filterModel]){
32 37 dataAry=array
33   - numberLines = array.count%3 > 0 ? array.count/3+1 : array.count/3
  38 + if self.tag==3{
  39 + numberLines = array.count
  40 + }else{
  41 + numberLines = array.count%3 > 0 ? array.count/3+1 : array.count/3
  42 + }
34 43 self.collectionView.reloadData()
35 44 }
36 45 @IBAction func openOrCloseAction(_ sender: UIButton) {
37   - if isOpen {
38   - isOpen=false
39   - self.constraints.last!.constant=60+cellHeight
  46 + if self.tag==3{
  47 + if isOpen {
  48 + isOpen=false
  49 + self.constraints.last!.constant=60+cellHeight*2+10
  50 + }else{
  51 + if dataAry.count>2{
  52 + isOpen=true
  53 + self.constraints.last!.constant=60+cellHeight+CGFloat(numberLines-1)*(cellHeight+10)
  54 + self.collectionView.reloadData()
  55 + }
  56 + }
40 57 }else{
41   - if dataAry.count>3{
42   - isOpen=true
43   - self.constraints.last!.constant=60+cellHeight+CGFloat(numberLines-1)*(cellHeight+10)
44   - self.collectionView.reloadData()
  58 + if isOpen {
  59 + isOpen=false
  60 + self.constraints.last!.constant=60+cellHeight
  61 + }else{
  62 + if dataAry.count>3{
  63 + isOpen=true
  64 + self.constraints.last!.constant=60+cellHeight+CGFloat(numberLines-1)*(cellHeight+10)
  65 + self.collectionView.reloadData()
  66 + }
45 67 }
46 68 }
47 69 }
48 70 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
49   - return CGSize(width: cellWidth, height: cellHeight)
  71 + if self.tag==3{
  72 + return CGSize(width: tableViewWidth,height: cellHeight)
  73 + }else{
  74 + return CGSize(width: cellWidth, height: cellHeight)
  75 + }
50 76 }
51 77 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
52 78 let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "identifier", for: indexPath) as! FilterCollectionViewCell
... ... @@ -57,6 +83,8 @@ class FilterView: UIView,UICollectionViewDelegate,UICollectionViewDataSource,UIC
57 83 cell.titleLabel.text=(dataAry as! [Grade])[indexPath.row].f_GradeName
58 84 case 2:
59 85 cell.titleLabel.text=(dataAry as! [Subject])[indexPath.row].f_SubjectName
  86 + case 3:
  87 + cell.titleLabel.text=(dataAry as! [Material])[indexPath.row].f_WaveTitle
60 88 default:
61 89 cell.titleLabel.text="未知"
62 90 }
... ...