| | |
| | | var maxPage = BehaviorRelay<Int>(value: 5) |
| | | var listenType = BehaviorRelay<ListenType>(value:.lesson1) |
| | | var times:Int = 0 |
| | | var quarter = BehaviorRelay<Int?>(value: 0) |
| | | var week = BehaviorRelay<Int?>(value: 0) |
| | | |
| | | //游戏专属,游戏等级 |
| | | var gameLevel = BehaviorRelay<Int>(value:0) |
| | | |
| | | //回答错误数量 |
| | | var correctNum:Int = 0{ |
| | |
| | | private var timer:Timer! |
| | | |
| | | |
| | | init(listenType:ListenType) { |
| | | init(listenType:ListenType,quarter:Int? = nil,week:Int? = nil) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.viewModel.listenType.accept(listenType) |
| | | self.viewModel.week.accept(week) |
| | | self.viewModel.quarter.accept(quarter) |
| | | |
| | | if listenType == .game1 || listenType == .game2{ |
| | | self.viewModel.maxPage.accept(1) |
| | | } |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | |
| | | self?.quitAction() |
| | | } |
| | | |
| | | pageVC.reloadData() |
| | | |
| | | btn_exit.addTarget(self, action: #selector(quitAction), for: .touchUpInside) |
| | | btn_forward.addTarget(self, action: #selector(beforeAction), for: .touchUpInside) |
| | | |
| | |
| | | if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{ |
| | | btn_forward.isHidden = true |
| | | label_pageNum.isHidden = true |
| | | |
| | | if viewModel.listenType.value == .game1{ |
| | | showGameLevel() |
| | | } |
| | | }else{ |
| | | pageVC.reloadData() |
| | | } |
| | | |
| | | timer = Timer(fire: .distantPast, interval: 1.0, repeats: true, block: {[weak self] _ in |
| | |
| | | }else{ |
| | | make.bottom.equalTo(self.label_pageNum.snp.top).offset(-32) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private func showGameLevel(){ |
| | | ChooseLevelView.show {[weak self] level in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.viewModel.gameLevel.accept(level) |
| | | Services.gameHearing(difficulty: level, quarter: weakSelf.viewModel.quarter.value!, week: weakSelf.viewModel.week.value!).subscribe(onNext: {result in |
| | | GameBeginTipView.show { |
| | | if let data = result.data{ |
| | | weakSelf.data = data |
| | | weakSelf.pageVC.reloadData() |
| | | } |
| | | } |
| | | },onError: { _ in |
| | | weakSelf.showGameLevel() |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | //完成 |
| | | if nextPage >= weakSelf.viewModel.maxPage.value{ |
| | | |
| | | var toalIntegral:Int = 0 |
| | | var ids = [Int]() |
| | | for v in weakSelf.viewModel.answerItems.values{ |
| | | if let v = v as? Listen1Model{ |
| | | toalIntegral += v.data?.integral ?? 0 |
| | | ids.append(v.data?.studyId ?? 0) |
| | | } |
| | | switch weakSelf.viewModel.listenType.value { |
| | | case .game1,.game2: |
| | | if let dict = noti.object as? Dictionary<String,Any>{ |
| | | weakSelf.gamesComplete(gameId: dict["gameId"] as! Int,integral: dict["gameIntegral"] as! Int) |
| | | } |
| | | case .lesson1,.lesson2,.lesson3,.lesson4,.lesson5: |
| | | weakSelf.studyComplete() |
| | | case .story1,.story2:break |
| | | } |
| | | |
| | | Services.completeLearing(type: weakSelf.viewModel.listenType.value.rawValue, studyTime: weakSelf.viewModel.times, studyIds: ids, isComplete: false).subscribe(onNext: {data in |
| | | |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | |
| | | weakSelf.timer.invalidate() |
| | | let vc = HomeStudyCompleteVC(correctNum: weakSelf.viewModel.correctNum, errorNum: weakSelf.viewModel.errorNum, totalCoin: toalIntegral) |
| | | vc.title = weakSelf.viewModel.listenType.value.rawTitle |
| | | weakSelf.push(vc: vc) |
| | | return |
| | | } |
| | | |
| | |
| | | self?.btn_forward.isHidden = currentPage <= 0 |
| | | self?.label_pageNum.text = "已完成:\(weakSelf.viewModel.currentPage.value + 1)/\(weakSelf.viewModel.maxPage.value)" |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | //学习类完成 |
| | | private func studyComplete(){ |
| | | var toalIntegral:Int = 0 |
| | | var ids = [Int]() |
| | | for v in viewModel.answerItems.values{ |
| | | if let v = v as? Listen1Model{ |
| | | toalIntegral += v.data?.integral ?? 0 |
| | | ids.append(v.data?.studyId ?? 0) |
| | | } |
| | | } |
| | | |
| | | Services.completeLearing(type: viewModel.listenType.value.rawValue, studyTime: viewModel.times, studyIds: ids, isComplete: false).subscribe(onNext: {data in |
| | | |
| | | }).disposed(by: disposeBag) |
| | | |
| | | timer.invalidate() |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | | |
| | | private func gamesComplete(gameId:Int,integral:Int){ |
| | | |
| | | var name = "" |
| | | if viewModel.listenType.value == .game1{ |
| | | name = "超级听力" |
| | | }else{ |
| | | name = "超级记忆" |
| | | } |
| | | |
| | | let accuracy = Int(Double(viewModel.correctNum) / Double(viewModel.correctNum + viewModel.errorNum) * 100) |
| | | |
| | | Services.completeGames(gameId: gameId, gameName: name, difficulty: viewModel.gameLevel.value, accuracy: accuracy, useTime: viewModel.times).subscribe(onNext: {data in |
| | | |
| | | }).disposed(by: disposeBag) |
| | | |
| | | timer.invalidate() |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | | |
| | | deinit{ |
| | |
| | | |
| | | extension HomeListenFightVC:FFPageViewControllerDelegate{ |
| | | func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt { |
| | | |
| | | //超级听力,只有一页 |
| | | if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{ |
| | | return 1 |
| | | } |
| | | return UInt(viewModel.maxPage.value) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if viewModel.listenType.value == .game1{ |
| | | let vc = HomeListenGame_1_VC() |
| | | if data == nil{return UIViewController()} |
| | | let vc = HomeListenGame_1_VC(listen1Model: data as! Listen1Model) |
| | | vc.rootViewModel = viewModel |
| | | return vc |
| | | } |
| | | |
| | | if viewModel.listenType.value == .game2{ |
| | | let vc = HomeListenGame_2_VC() |
| | | let vc = HomeListenGame_2_VC(listen1Model: data as! Listen1Model) |
| | | vc.rootViewModel = viewModel |
| | | return vc |
| | | } |
| | | |