fix
无故事王国
2024-06-11 d6157c137a888d4f6931255735c3ed39575c579d
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift
@@ -10,6 +10,7 @@
import RxRelay
let NextLession_Noti = Notification.Name.init("NextLession_Noti")
//let Reload_Noti = Notification.Name.init("Reload_Noti")
enum ListenType:Int{
            case lesson1 = 1 //自主学习-听音选图
@@ -117,8 +118,6 @@
            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
            }()
@@ -149,6 +148,7 @@
                        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{
@@ -158,6 +158,10 @@
                                    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()
                        }
@@ -186,6 +190,7 @@
                                    }
                        }
            }
            private func showGameLevel(){
                        ChooseLevelView.show {[weak self] level in
@@ -239,9 +244,22 @@
            }
            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{
@@ -252,9 +270,11 @@
                                                                        }
                                                            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
                                    }
@@ -286,11 +306,12 @@
                        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 = ""
@@ -308,7 +329,17 @@
                        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)
            }
@@ -318,8 +349,29 @@
            }
            @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)
                        }
            }
@@ -327,6 +379,12 @@
                        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)
            }
}
@@ -337,10 +395,15 @@
                        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)")
            }
@@ -390,12 +453,14 @@
                        }
                        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
                        }