| | |
| | | var teamScheduleModel:TeamScheduleModel? |
| | | private var voicePlayer = VoicePlayer.share() |
| | | private var playIndex = Set<IndexPath>() //顺序播放 |
| | | private var currentPlayIndex = IndexPath(row: 0, section: 0) |
| | | |
| | | private var isPlayingIndex:IndexPath? //正在播放中 |
| | | private var islisten:Bool = false |
| | | private var handleClouse:(()->Void)? |
| | |
| | | listenNewModel.subjectList[page][1].isQuestion = 1 |
| | | listenNewModel.subjectList[page][3].isQuestion = 1 |
| | | |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) { |
| | | self.isPlayingIndex = IndexPath(row: 0, section: 0) |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][self.currentPlayIndex.row].correct) |
| | | self.collectionView.reloadData() |
| | | } |
| | | |
| | | rootViewModel.currentPage.subscribe(onNext: {[unowned self] cpage in |
| | | if cpage == self.page{ |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) { |
| | | self.restore() |
| | | self.isPlayingIndex = IndexPath(row: 0, section: 0) |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][0].correct) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | |
| | | //回传记录,始终保持答题进度 |
| | |
| | | } |
| | | |
| | | func restore(){ |
| | | listenNewModel.subjectList.forEach { list in |
| | | list.forEach { sub in |
| | | sub.isAnster = false |
| | | } |
| | | } |
| | | isPlayingIndex = nil |
| | | playIndex.removeAll() |
| | | playIndex.insert(IndexPath(row: 0, section: 0)) |
| | | answterCount = 0 |
| | |
| | | |
| | | @objc private func chooseAnswerAction(btn:UIButton){ |
| | | |
| | | guard viewModel.selectIndex.value != nil else {return} |
| | | |
| | | if !islisten{ |
| | | alertError(msg: "请先听题");return |
| | | } |
| | | |
| | | if answterCount == 0 && !playIndex.contains(IndexPath(row: 2, section: 0)){ |
| | | alertError(msg: "请先听题");return |
| | | } |
| | | |
| | | if answterCount == 1 && !playIndex.contains(IndexPath(row: 1, section: 1)){ |
| | | alertError(msg: "请先听题");return |
| | | } |
| | | |
| | | if answterCount == 2 && !playIndex.contains(IndexPath(row: 2, section: 1)){ |
| | | alertError(msg: "请先听题");return |
| | | } |
| | | |
| | | var subV:Lesson_3_AnswerView? |
| | | |
| | | for (_,v) in (stackView.arrangedSubviews as! [Lesson_3_AnswerView]).enumerated(){ |
| | |
| | | var answerType:Fight_lessonType = .none |
| | | |
| | | var valueIndex:Int! //图片的角标 |
| | | if viewModel.selectIndex.value?.section == 0{ |
| | | valueIndex = viewModel.selectIndex.value!.row |
| | | } |
| | | if viewModel.selectIndex.value?.section == 1{ |
| | | valueIndex = viewModel.selectIndex.value!.row + 3 |
| | | if answterCount == 0{ |
| | | valueIndex = 2 |
| | | }else if answterCount == 1{ |
| | | valueIndex = 4 |
| | | }else if answterCount == 2{ |
| | | valueIndex = 5 |
| | | } |
| | | |
| | | if subV?.imageUrl == listenNewModel.subjectList[page][valueIndex].img{ |
| | | answterCount += 1 |
| | | listenNewModel.subjectList[page][valueIndex].isAnster = true |
| | | answerType = .success |
| | | subV?.alpha = 0 |
| | | voicePlayer.playSuccessVoice() |
| | | currentPlayIndex = IndexPath(row: 0, section: 1) |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][currentPlayIndex.row + 3].correct) |
| | | |
| | | let model = listenNewModel.list[self.page] |
| | | |
| | | switch answterCount{ |
| | | case 1:isPlayingIndex = IndexPath(row: 2, section: 0) |
| | | case 2:isPlayingIndex = IndexPath(row: 1, section: 1) |
| | | case 3:isPlayingIndex = IndexPath(row: 2, section: 1) |
| | | default:break |
| | | } |
| | | let index = self.isPlayingIndex!.section * 3 + self.isPlayingIndex!.row |
| | | |
| | | let model = listenNewModel.list[index] |
| | | model.status = 2 |
| | | Services.answerQuestion(id: model.id, status: 2).subscribe(onNext: {_ in |
| | | self.handleClouse?() |
| | |
| | | self.view.addSubview(copyView!) |
| | | copyView?.layoutIfNeeded() |
| | | |
| | | var ansterIndePath:IndexPath? |
| | | if viewModel.selectIndex.value?.section == 0{ |
| | | ansterIndePath = IndexPath(row: 2, section: 0) |
| | | playIndex.insert(IndexPath(row: 0, section: 1)) //下一个准备播放 |
| | | } |
| | | |
| | | if viewModel.selectIndex.value?.section == 1 && (viewModel.selectIndex.value?.row == 0 || viewModel.selectIndex.value?.row == 1){ |
| | | ansterIndePath = IndexPath(row: 1, section: 1) |
| | | playIndex.insert(IndexPath(row: 2, section: 1)) //下一个准备播放 |
| | | } |
| | | |
| | | if viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 2{ |
| | | ansterIndePath = IndexPath(row: 2, section: 1) |
| | | } |
| | | |
| | | guard ansterIndePath != nil else {return} |
| | | |
| | | if let cell = collectionView.cellForItem(at: ansterIndePath!) as? ListenFight_lesson_3_CCell{ |
| | | if let cell = collectionView.cellForItem(at: isPlayingIndex!) as? ListenFight_lesson_3_CCell{ |
| | | var newFrame = cell.img_cover.convert(cell.img_cover.bounds, to: self.view) |
| | | newFrame.origin.x += 0 |
| | | newFrame.origin.y += 0 |
| | |
| | | UIView.animate(withDuration: 0.4) { |
| | | copyView?.frame = newFrame |
| | | } completion: { _ in |
| | | self.answterCount += 1 |
| | | |
| | | let cell = self.collectionView.cellForItem(at: self.viewModel.selectIndex.value!) as! ListenFight_lesson_3_CCell |
| | | self.isPlayingIndex = self.viewModel.selectIndex.value |
| | | cell.isPlaying(isplaying: true) |
| | | let cell = self.collectionView.cellForItem(at: IndexPath(row: 0, section: 1)) as! ListenFight_lesson_3_CCell |
| | | |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][valueIndex].correct) |
| | | cell.isPlaying(isplaying: true) |
| | | |
| | | let teamId = self.listenNewModel.data?.id.components(separatedBy: ",")[self.page] |
| | | let answerId = self.listenNewModel.subjectList[self.page][valueIndex].id |
| | |
| | | v.removeFromSuperview() |
| | | } |
| | | |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1.0) { |
| | | // self.viewModel.selectIndex.accept(nil) |
| | | let v = self.rootViewModel.answerCount.value + 1 |
| | | self.rootViewModel.answerCount.accept(v) |
| | | self.collectionView.reloadData() |
| | | } |
| | | let v = self.rootViewModel.answerCount.value + 1 |
| | | self.rootViewModel.answerCount.accept(v) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | extension HomeListenFight_lesson_3_VC:VoicePlayerDelegate{ |
| | | |
| | | func playComplete() { |
| | | view.isUserInteractionEnabled = true |
| | | isPlayingIndex = nil |
| | | islisten = true |
| | | var nextRow = (viewModel.selectIndex.value?.row ?? 0) + 1 |
| | | var section = (viewModel.selectIndex.value?.section ?? 0) + 0 |
| | | |
| | | if nextRow >= 3{ |
| | | nextRow = 0;section = 1 |
| | | } |
| | | |
| | | currentPlayIndex.row+=1 |
| | | if currentPlayIndex.row < 3{ |
| | | |
| | | var row = currentPlayIndex.row |
| | | if currentPlayIndex.section == 1{ |
| | | row += 3 |
| | | } |
| | | |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][row].correct) |
| | | self.isPlayingIndex = currentPlayIndex |
| | | self.viewModel.selectIndex.accept(currentPlayIndex) |
| | | self.playIndex.insert(currentPlayIndex) |
| | | } |
| | | |
| | | if currentPlayIndex.row == 2{ |
| | | self.isPlayingIndex = currentPlayIndex |
| | | self.viewModel.selectIndex.accept(currentPlayIndex) |
| | | self.playIndex.insert(currentPlayIndex) |
| | | self.setAnswerStackView() |
| | | } |
| | | |
| | | if self.answterCount == 2{ |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: nil) |
| | | return |
| | | } |
| | | |
| | | if (viewModel.selectIndex.value?.section == 0 && viewModel.selectIndex.value?.row == 2) || (viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 1){ |
| | | //1 |
| | | if isPlayingIndex?.section == 0 && isPlayingIndex?.row == 0{ |
| | | isPlayingIndex?.row += 1 |
| | | let index = isPlayingIndex!.row |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][index].correct) |
| | | playIndex.insert(isPlayingIndex!) |
| | | collectionView.reloadData() |
| | | return |
| | | } |
| | | playIndex.insert(IndexPath(row: nextRow, section: section)) //下一个准备播放 |
| | | collectionView.reloadData() |
| | | |
| | | //2 |
| | | if isPlayingIndex?.section == 0 && isPlayingIndex?.row == 1{ |
| | | isPlayingIndex?.row += 1 |
| | | let index = isPlayingIndex!.row |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][index].correct) |
| | | playIndex.insert(isPlayingIndex!) |
| | | collectionView.reloadData() |
| | | self.setAnswerStackView() |
| | | return |
| | | } |
| | | |
| | | //3 |
| | | if isPlayingIndex?.section == 0 && isPlayingIndex?.row == 2{ |
| | | let index = isPlayingIndex!.row |
| | | if self.listenNewModel.subjectList[self.page][index].isAnster{ |
| | | isPlayingIndex?.row = 0 |
| | | isPlayingIndex?.section += 1 |
| | | let index = isPlayingIndex!.section * 3 + isPlayingIndex!.row |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][index].correct) |
| | | playIndex.insert(isPlayingIndex!) |
| | | collectionView.reloadData() |
| | | } |
| | | |
| | | return |
| | | } |
| | | |
| | | |
| | | if isPlayingIndex?.section == 1 && isPlayingIndex?.row == 0{ |
| | | let index = isPlayingIndex!.section * 3 + isPlayingIndex!.row |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][index].correct) |
| | | isPlayingIndex?.row += 1 |
| | | playIndex.insert(isPlayingIndex!) |
| | | collectionView.reloadData() |
| | | return |
| | | } |
| | | |
| | | if isPlayingIndex?.section == 1 && isPlayingIndex?.row == 1{ |
| | | let index = isPlayingIndex!.section * 3 + isPlayingIndex!.row |
| | | if self.listenNewModel.subjectList[self.page][index].isAnster{ |
| | | isPlayingIndex?.row += 1 |
| | | let index = isPlayingIndex!.section * 3 + isPlayingIndex!.row |
| | | self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][index].correct) |
| | | playIndex.insert(isPlayingIndex!) |
| | | collectionView.reloadData() |
| | | return |
| | | } |
| | | self.setAnswerStackView() |
| | | } |
| | | |
| | | if isPlayingIndex?.section == 1 && isPlayingIndex?.row == 2{ |
| | | let index = isPlayingIndex!.section * 3 + isPlayingIndex!.row |
| | | if self.listenNewModel.subjectList[self.page][index].isAnster{ |
| | | //答完了 |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: nil) |
| | | return |
| | | } |
| | | self.setAnswerStackView() |
| | | } |
| | | } |
| | | |
| | | func playing() { |