| | |
| | | import RxRelay |
| | | |
| | | let NextLession_Noti = Notification.Name.init("NextLession_Noti") |
| | | //let Reload_Noti = Notification.Name.init("Reload_Noti") |
| | | |
| | | enum ListenType:Int{ |
| | | case lesson1 = 1 //自主学习-听音选图 |
| | |
| | | private lazy var pageVC:FFPageViewController = { |
| | | let vc = FFPageViewController() |
| | | vc.scrollview.isScrollEnabled = false |
| | | vc.prePages = UInt(viewModel.maxPage.value) / 2 |
| | | vc.maxPages = UInt(viewModel.maxPage.value) + 1 |
| | | return vc |
| | | }() |
| | | |
| | |
| | | |
| | | btn_exit.addTarget(self, action: #selector(quitAction), for: .touchUpInside) |
| | | btn_forward.addTarget(self, action: #selector(beforeAction), for: .touchUpInside) |
| | | btn_next.addTarget(self, action: #selector(nextAction), for: .touchUpInside) |
| | | |
| | | |
| | | if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{ |
| | |
| | | if viewModel.listenType.value == .game1{ |
| | | showGameLevel() |
| | | } |
| | | }else if viewModel.listenType.value == .story1 || viewModel.listenType.value == .story2{ |
| | | let count = (data as! Listen1Model).storyList.count |
| | | viewModel.maxPage.accept(count) |
| | | label_pageNum.text = "已完成:\(viewModel.currentPage.value + 1)/\(viewModel.maxPage.value)" |
| | | }else{ |
| | | pageVC.reloadData() |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private func showGameLevel(){ |
| | | ChooseLevelView.show {[weak self] level in |
| | |
| | | } |
| | | |
| | | override func setRx() { |
| | | |
| | | // NotificationCenter.default.rx.notification(Reload_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in |
| | | // self?.pageVC.reloadData() |
| | | // }).disposed(by: disposeBag) |
| | | |
| | | |
| | | NotificationCenter.default.rx.notification(NextLession_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in |
| | | guard let weakSelf = self else { return } |
| | | let nextPage = weakSelf.viewModel.currentPage.value + 1 |
| | | |
| | | if weakSelf.viewModel.listenType.value == .story2{ |
| | | weakSelf.btn_next.isHidden = (nextPage + 1) == weakSelf.viewModel.maxPage.value |
| | | if weakSelf.btn_next.isHidden{ |
| | | weakSelf.btn_exit.setTitle("完成", for: .normal) |
| | | } |
| | | } |
| | | |
| | | //完成 |
| | | if nextPage >= weakSelf.viewModel.maxPage.value{ |
| | |
| | | } |
| | | case .lesson1,.lesson2,.lesson3,.lesson4,.lesson5: |
| | | weakSelf.studyComplete() |
| | | case .story1,.story2:break |
| | | case .story1,.story2: |
| | | if let dict = noti.object as? Dictionary<String,Any>{ |
| | | weakSelf.storyComplete(storyId: dict["storyId"] as! Int, integral: dict["storyIntegral"] as! Int) |
| | | } |
| | | } |
| | | |
| | | return |
| | | } |
| | | |
| | |
| | | |
| | | timer.invalidate() |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral) |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral, listenType: viewModel.listenType.value) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | | |
| | | //游戏类完成 |
| | | private func gamesComplete(gameId:Int,integral:Int){ |
| | | |
| | | var name = "" |
| | |
| | | |
| | | timer.invalidate() |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral) |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral, listenType: viewModel.listenType.value) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | | |
| | | private func storyComplete(storyId:Int,integral:Int){ |
| | | Services.completeStory(storyId: storyId, integral: integral).subscribe(onNext: {data in |
| | | |
| | | }).disposed(by: disposeBag) |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral, listenType: viewModel.listenType.value) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | |
| | | } |
| | | |
| | | @objc func quitAction(){ |
| | | CommonAlertView.show(content: "未完成全部答题,确认退出吗?") { |
| | | self.navigationController?.popViewController(animated: true) |
| | | if btn_exit.titleLabel?.text == "完成"{ |
| | | if viewModel.listenType.value == .story2{ |
| | | let v = data as! Listen1Model |
| | | storyComplete(storyId: v.data!.id, integral: v.data!.lookIntegral) |
| | | } |
| | | }else{ |
| | | CommonAlertView.show(content: "未完成全部答题,确认退出吗?") { |
| | | self.navigationController?.popViewController(animated: true) |
| | | } |
| | | } |
| | | } |
| | | |
| | | @objc func nextAction(){ |
| | | // var v = viewModel.currentPage.value |
| | | // v += 1 |
| | | // viewModel.currentPage.accept(v) |
| | | |
| | | if viewModel.listenType.value == .story2{ |
| | | let v = data as! Listen1Model |
| | | var dict = Dictionary<String,Any>() |
| | | dict["storyId"] = v.data?.id ?? 0 |
| | | dict["storyIntegral"] = v.data?.lookIntegral ?? 0 |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: data) |
| | | } |
| | | } |
| | | |
| | |
| | | let beforePage = max(0, viewModel.currentPage.value - 1) |
| | | pageVC.scroll(toPage: beforePage, animation: true) |
| | | viewModel.currentPage.accept(beforePage) |
| | | |
| | | if viewModel.listenType.value == .story2{ |
| | | btn_next.isHidden = false |
| | | } |
| | | |
| | | btn_exit.setTitle("退出", for: .normal) |
| | | } |
| | | } |
| | | |
| | |
| | | if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{ |
| | | return 1 |
| | | } |
| | | |
| | | if viewModel.listenType.value == .story1 || viewModel.listenType.value == .story2{ |
| | | return UInt((data as! Listen1Model).storyList.count) |
| | | } |
| | | return UInt(viewModel.maxPage.value) |
| | | } |
| | | |
| | | func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) { |
| | | print("---->\(currentPage)") |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if viewModel.listenType.value == .story1{ |
| | | let vc = HomeListenStory_1_VC() |
| | | let vc = HomeListenStory_1_VC(page: page, listen1Model: data as! Listen1Model) |
| | | vc.rootViewModel = viewModel |
| | | return vc |
| | | } |
| | | |
| | | if viewModel.listenType.value == .story2{ |
| | | let vc = HomeListenStory_2_VC() |
| | | let vc = HomeListenStory_2_VC(page: page, listen1Model: data as! Listen1Model) |
| | | vc.rootViewModel = viewModel |
| | | return vc |
| | | } |
| | | |