diff --git a/ThimraTV/Base/Networking/API/SPVideoAPI.swift b/ThimraTV/Base/Networking/API/SPVideoAPI.swift index 95d7233..2a1772d 100644 --- a/ThimraTV/Base/Networking/API/SPVideoAPI.swift +++ b/ThimraTV/Base/Networking/API/SPVideoAPI.swift @@ -10,13 +10,11 @@ import UIKit class SPVideoAPI: NSObject { ///获取视频详情 - static func requestVideoDetail(videoId: String?, shortPlayId: String, activityId: String? = nil, completer: ((_ model: SPVideoDetailModel?) -> Void)?) { + static func requestVideoDetail(videoId: String?, shortPlayId: String, activityId: String? = nil, completer: ((_ model: SPVideoDetailModel?, _ code: Int?, _ msg: String?) -> Void)?) { var parameters: [String : Any] = [ "short_play_id" : shortPlayId ] -// if let videoId = videoId { -// } parameters["video_id"] = "0" if let activityId = activityId { parameters["activity_id"] = activityId @@ -26,9 +24,19 @@ class SPVideoAPI: NSObject { param.method = .get param.parameters = parameters param.isLoding = true + param.isToast = false SPNetwork.request(parameters: param) { (response: SPNetworkResponse) in - completer?(response.data) + + if response.code == SPNetworkCodeSucceed { + + } else if response.code == 10014 { + SPToast.show(text: "movia_no_short_found".localized) + } else { + SPToast.show(text: response.msg) + } + + completer?(response.data, response.code, response.msg) } } diff --git a/ThimraTV/Base/Networking/Base/SPNetwork.swift b/ThimraTV/Base/Networking/Base/SPNetwork.swift index da3059c..e4b4f71 100644 --- a/ThimraTV/Base/Networking/Base/SPNetwork.swift +++ b/ThimraTV/Base/Networking/Base/SPNetwork.swift @@ -121,10 +121,11 @@ class SPNetwork: NSObject { DispatchQueue.global().async { - let response: SPNetworkResponse = _deserialize(data: tempData) + var response: SPNetworkResponse = _deserialize(data: tempData) DispatchQueue.main.async { if response.code != SPNetworkCodeSucceed { + response.data = nil if parameters.isToast { SPToast.show(text: response.msg) } diff --git a/ThimraTV/Class/Player/Controller/SPPlayerDetailViewController.swift b/ThimraTV/Class/Player/Controller/SPPlayerDetailViewController.swift index fd49935..ea41728 100644 --- a/ThimraTV/Class/Player/Controller/SPPlayerDetailViewController.swift +++ b/ThimraTV/Class/Player/Controller/SPPlayerDetailViewController.swift @@ -398,33 +398,36 @@ extension SPPlayerDetailViewController { recommandTimer = nil recommandTimer = Timer.scheduledTimer(timeInterval: 6, target: YYWeakProxy(target: self), selector: #selector(handleRecommandTimer), userInfo: nil, repeats: false) - SPVideoAPI.requestVideoDetail(videoId: videoId, shortPlayId: shortPlayId, activityId: activityId) { [weak self] model in + SPVideoAPI.requestVideoDetail(videoId: videoId, shortPlayId: shortPlayId, activityId: activityId) { [weak self] model, code, msg in guard let self = self else { return } - if let model = model { - self.detailModel = model - self.reloadData { [weak self] in - guard let self = self else { return } + if code == 10014 { + self.navigationController?.popViewController(animated: true) + return + } + guard let model = model else { return } + + self.detailModel = model + self.reloadData { [weak self] in + guard let self = self else { return } + + if let indexPath = indexPath, indexPath.row < (model.episodeList?.count ?? 0) { + self.scrollToItem(indexPath: indexPath, animated: false) - if let indexPath = indexPath, indexPath.row < (model.episodeList?.count ?? 0) { - self.scrollToItem(indexPath: indexPath, animated: false) - - } else if let videoInfo = self.detailModel?.video_info { - var row: Int? - self.detailModel?.episodeList?.enumerated().forEach({ - if $1.id == videoInfo.id { - row = $0 - } - }) - if let row = row { - self.scrollToItem(indexPath: .init(row: row, section: 0), animated: false) - } else { - self.scrollToItem(indexPath: .init(row: 0, section: 0), animated: false) + } else if let videoInfo = self.detailModel?.video_info { + var row: Int? + self.detailModel?.episodeList?.enumerated().forEach({ + if $1.id == videoInfo.id { + row = $0 } + }) + if let row = row { + self.scrollToItem(indexPath: .init(row: row, section: 0), animated: false) } else { self.scrollToItem(indexPath: .init(row: 0, section: 0), animated: false) } + } else { + self.scrollToItem(indexPath: .init(row: 0, section: 0), animated: false) } - } } } diff --git a/ThimraTV/Class/Player/Controller/SPPlayerListViewController.swift b/ThimraTV/Class/Player/Controller/SPPlayerListViewController.swift index b45237d..0401e29 100644 --- a/ThimraTV/Class/Player/Controller/SPPlayerListViewController.swift +++ b/ThimraTV/Class/Player/Controller/SPPlayerListViewController.swift @@ -75,8 +75,6 @@ class SPPlayerListViewController: SPViewController { private(set) lazy var collectionView: SPCollectionView = { let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout) - collectionView.delegate = self - collectionView.dataSource = self collectionView.isPagingEnabled = true collectionView.showsVerticalScrollIndicator = false collectionView.showsHorizontalScrollIndicator = false @@ -88,6 +86,7 @@ class SPPlayerListViewController: SPViewController { deinit { NotificationCenter.default.removeObserver(self) + self.collectionView.removeFromSuperview() } override func viewDidLoad() { @@ -101,6 +100,8 @@ class SPPlayerListViewController: SPViewController { NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActiveNotification), name: UIApplication.didBecomeActiveNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(willResignActiveNotification), name: UIApplication.willResignActiveNotification, object: nil) + collectionView.delegate = self + collectionView.dataSource = self sp_setupUI() sp_addActio() diff --git a/ThimraTV/Source/en.lproj/Localizable.strings b/ThimraTV/Source/en.lproj/Localizable.strings index 0e0ca68..2974903 100644 --- a/ThimraTV/Source/en.lproj/Localizable.strings +++ b/ThimraTV/Source/en.lproj/Localizable.strings @@ -124,6 +124,7 @@ "movia_profile_Bonus" = "Bonus"; "movia_updatenowtitle" = "Discover a new version"; "movia_updatenow" = "Update Now"; +"movia_no_short_found" = "No Short Found"; "movia_vip_alert_text_01" = "Short Drama VIP Exclusive";