| | |
| | | } |
| | | } |
| | | |
| | | enum ListenFightLine{ |
| | | case before |
| | | case next |
| | | case none |
| | | } |
| | | |
| | | class HomeListenFightViewModel{ |
| | | |
| | | /// 当前页数 |
| | |
| | | var times:Int = 0 |
| | | var quarter = BehaviorRelay<Int?>(value: 0) |
| | | var week = BehaviorRelay<Int?>(value: 0) |
| | | var day = BehaviorRelay<Int?>(value: 0) |
| | | |
| | | //游戏专属,游戏等级 |
| | | var gameLevel = BehaviorRelay<Int>(value:0) |
| | |
| | | |
| | | class HomeListenFightVC: BaseVC { |
| | | private var viewModel = HomeListenFightViewModel() |
| | | var studyScheduleModel:StudyScheduleModel? //学习进度(上级传递) |
| | | var listenFightLine:ListenFightLine = .none |
| | | var data:Any? |
| | | |
| | | private lazy var label_pageNum:UILabel = { |
| | |
| | | private var timer:Timer! |
| | | |
| | | |
| | | init(listenType:ListenType,quarter:Int? = nil,week:Int? = nil) { |
| | | init(listenType:ListenType,quarter:Int? = nil,week:Int? = nil,day:Int? = nil) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.viewModel.listenType.accept(listenType) |
| | | self.viewModel.week.accept(week) |
| | | self.viewModel.day.accept(day) |
| | | self.viewModel.quarter.accept(quarter) |
| | | |
| | | if listenType == .game1 || listenType == .game2{ |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | return |
| | | } |
| | | |
| | | self?.listenFightLine = .next |
| | | self?.pageVC.scroll(toPage: nextPage, animation: true) |
| | | self?.viewModel.currentPage.accept(nextPage) |
| | | }).disposed(by: disposeBag) |
| | |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | //学习类完成 |
| | | |
| | | /// 学习类完成 |
| | | /// - Parameter ignorePush: 是否忽略跳转(未完成答题 :true) |
| | | private func studyComplete(){ |
| | | var toalIntegral:Int = 0 |
| | | var ids = [Int]() |
| | |
| | | } |
| | | } |
| | | |
| | | Services.completeLearing(type: viewModel.listenType.value.rawValue, studyTime: viewModel.times, studyIds: ids, isComplete: false).subscribe(onNext: {data in |
| | | |
| | | }).disposed(by: disposeBag) |
| | | //有答题过程 |
| | | //完成进度 |
| | | var isComplete = false |
| | | switch viewModel.listenType.value { |
| | | case .lesson1:isComplete = studyScheduleModel?.listen == 100 |
| | | case .lesson2:isComplete = studyScheduleModel?.look == 100 |
| | | case .lesson3:isComplete = studyScheduleModel?.induction == 100 |
| | | case .lesson4:isComplete = studyScheduleModel?.answer == 100 |
| | | case .lesson5:isComplete = studyScheduleModel?.pair == 100 |
| | | default:isComplete = false |
| | | } |
| | | |
| | | Services.completeLearing(type: viewModel.listenType.value.rawValue, studyTime: viewModel.times, studyIds: ids, isComplete: isComplete).subscribe(onNext: {data in |
| | | NotificationCenter.default.post(name: Refresh_ListenSchedule_Noti, object: nil) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | timer.invalidate() |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral, listenType: viewModel.listenType.value) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral, listenType: viewModel.listenType.value) |
| | | vc.title = viewModel.listenType.value.rawTitle |
| | | push(vc: vc) |
| | | } |
| | | |
| | | //游戏类完成 |
| | |
| | | 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 |
| | | |
| | | NotificationCenter.default.post(name: Refresh_ListenSchedule_Noti, object: nil) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | timer.invalidate() |
| | |
| | | } |
| | | |
| | | private func storyComplete(storyId:Int,integral:Int){ |
| | | Services.completeStory(storyId: storyId, integral: integral).subscribe(onNext: {data in |
| | | timer.invalidate() |
| | | |
| | | Services.completeStory(storyId: storyId, integral: integral).subscribe(onNext: {data in |
| | | NotificationCenter.default.post(name: Refresh_ListenSchedule_Noti, object: nil) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral, listenType: viewModel.listenType.value) |
| | |
| | | storyComplete(storyId: v.data!.id, integral: v.data!.lookIntegral) |
| | | } |
| | | }else{ |
| | | CommonAlertView.show(content: "未完成全部答题,确认退出吗?") { |
| | | self.navigationController?.popViewController(animated: true) |
| | | CommonAlertView.show(content: "未完成全部答题,确认退出吗?") {[weak self] () in |
| | | guard let weakSelf = self else { return } |
| | | |
| | | var temIds = [String]() |
| | | var topicIds = [String]() |
| | | for v in weakSelf.viewModel.answerItems.values{ |
| | | if let v = v as? Listen1Model{ |
| | | temIds.append("\(v.data?.id ?? 0)") |
| | | for sV in v.subjectList{ |
| | | topicIds.append("\(sV.id)") |
| | | } |
| | | } |
| | | } |
| | | |
| | | switch weakSelf.viewModel.listenType.value{ |
| | | case .lesson1,.lesson2,.lesson3,.lesson4,.lesson5: |
| | | if temIds.count > 0 && topicIds.count > 0{ |
| | | Services.exitLearning(type:weakSelf.viewModel.listenType.value.rawValue,week: weakSelf.viewModel.week.value!, day: weakSelf.viewModel.day.value!, teamIds: temIds, topicIds: topicIds).subscribe(onNext: { data in |
| | | |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | } |
| | | default:break |
| | | } |
| | | weakSelf.navigationController?.popViewController(animated: true) |
| | | } |
| | | } |
| | | } |
| | | |
| | | @objc func nextAction(){ |
| | | // var v = viewModel.currentPage.value |
| | | // v += 1 |
| | | // viewModel.currentPage.accept(v) |
| | | |
| | | listenFightLine = .next |
| | | if viewModel.listenType.value == .story2{ |
| | | let v = data as! Listen1Model |
| | | var dict = Dictionary<String,Any>() |
| | |
| | | } |
| | | |
| | | @objc func beforeAction(){ |
| | | listenFightLine = .before |
| | | let beforePage = max(0, viewModel.currentPage.value - 1) |
| | | pageVC.scroll(toPage: beforePage, animation: true) |
| | | viewModel.currentPage.accept(beforePage) |
| | |
| | | } |
| | | |
| | | func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) { |
| | | print("---->\(currentPage)") |
| | | |
| | | if listenFightLine == .before{ |
| | | if let vc = pageViewController.currentController as? HomeListenFight_lesson_1_VC{ |
| | | vc.restore() |
| | | } |
| | | if let vc = pageViewController.currentController as? HomeListenFight_lesson_2_VC{ |
| | | vc.restore() |
| | | } |
| | | if let vc = pageViewController.currentController as? HomeListenFight_lesson_3_VC{ |
| | | vc.restore() |
| | | } |
| | | if let vc = pageViewController.currentController as? HomeListenFight_lesson_4_VC{ |
| | | vc.restore() |
| | | } |
| | | if let vc = pageViewController.currentController as? HomeListenFight_lesson_5_VC{ |
| | | vc.restore() |
| | | } |
| | | } |
| | | } |
| | | |
| | | func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController { |
| | | |
| | | print("加载======") |
| | | if viewModel.listenType.value == .lesson1{ |
| | | let vc = HomeListenFight_lesson_1_VC(page: page,listen1Model:data as! Listen1Model) |
| | | vc.rootViewModel = viewModel |