From a94e3a8fd7e03fbcb6369387752a1678eef6d3d8 Mon Sep 17 00:00:00 2001 From: zeng Date: Tue, 13 May 2025 13:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=AF=AD=E8=A8=80BUG=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MoviaBox/AppDelegate/AppDelegate.swift | 2 - MoviaBox/AppDelegate/SceneDelegate.swift | 99 +++++++++++++------ .../Base/SPNetworkReachabilityManager.swift | 8 +- .../Class/Player/Model/SPShortModel.swift | 2 +- .../Class/Player/View/SPPlayLockView.swift | 2 +- .../Player/View/SPPlayerControlView.swift | 17 +++- .../SPOrderRecordsPageViewController.swift | 2 +- .../View/SPConsumptionRecordsCell.swift | 2 +- .../SPLocalizedManager.swift | 25 ++++- 9 files changed, 117 insertions(+), 42 deletions(-) diff --git a/MoviaBox/AppDelegate/AppDelegate.swift b/MoviaBox/AppDelegate/AppDelegate.swift index 7795583..2db27bd 100644 --- a/MoviaBox/AppDelegate/AppDelegate.swift +++ b/MoviaBox/AppDelegate/AppDelegate.swift @@ -29,8 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // SPLoginManager.manager.requestVisitorLogin(completer: nil) SPLoginManager.manager.updateUserInfo(completer: nil) - ///更新本地多语言 - SPLocalizedManager.shared.updateLocalizedData(completer: nil) ///注册消息通知 registerAPNS() diff --git a/MoviaBox/AppDelegate/SceneDelegate.swift b/MoviaBox/AppDelegate/SceneDelegate.swift index 85f0838..e19d030 100644 --- a/MoviaBox/AppDelegate/SceneDelegate.swift +++ b/MoviaBox/AppDelegate/SceneDelegate.swift @@ -17,29 +17,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let windowScene = (scene as? UIWindowScene) else { return } ///监听语言切换 NotificationCenter.default.addObserver(self, selector: #selector(localizedDidChange), name: SPLocalizedManager.localizedDidChange, object: nil) - - let tabBarController = SPTabBarController() - SPAPPTool.mainTabBarController = tabBarController - - let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool - ///引导页 - let guideVc = SPGuideViewController() - + ///监听网路变化 + NotificationCenter.default.addObserver(self, selector: #selector(reachabilityDidChangeNotification), name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil) window = UIWindow(windowScene: windowScene) - if hasOpenApp != true && guideVc.lanuchVC != nil { - SPAPPTool.isAppOpen = false - guideVc.openAppBlock = { - self.handleOpenApp() - } - window?.rootViewController = guideVc - } else { - SPAPPTool.isAppOpen = true - window?.rootViewController = tabBarController - } - window?.makeKeyAndVisible() + + startApp() + //在线状态统计 timer = Timer.scheduledTimer(timeInterval: 60 * 10, target: self, selector: #selector(handleOnLine), userInfo: nil, repeats: true) } @@ -84,27 +70,84 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { extension SceneDelegate { + private func startApp() { + let localizedManager = SPLocalizedManager.shared + + ///设置语言与当前的数据语言不同步时,需要重新获取语言后展示页面 + if localizedManager.localizedDataLocalizedKey != localizedManager.currentLocalizedKey, let lanuchVC = SPAPPTool.getLanuchViewController() { + window?.rootViewController = lanuchVC + window?.makeKeyAndVisible() + + SPLocalizedManager.shared.updateLocalizedData { [weak self] finish in + guard let self = self else { return } + self.setRootVC() + } + + } else { + SPLocalizedManager.shared.updateLocalizedData(completer: nil) + + setRootVC() + } + } + ///统计在线状态 @objc private func handleOnLine() { SPStatAPI.requestStatOnLine() } - ///打开app - @objc private func handleOpenApp() { - window?.rootViewController = SPAPPTool.mainTabBarController! - window?.makeKeyAndVisible() + private func setRootVC() { + let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool + ///引导页 + let guideVc = SPGuideViewController() - handleOpenAppMessage(webpageURL: nil) + + if hasOpenApp != true && guideVc.lanuchVC != nil { + SPAPPTool.isAppOpen = false + guideVc.openAppBlock = { + self.handleOpenApp() + } + window?.rootViewController = guideVc + window?.makeKeyAndVisible() + + } else { + SPAPPTool.isAppOpen = true + setTabBarController() + } } - ///语言切换 - @objc private func localizedDidChange() { - MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey - + private func setTabBarController() { let tabBarController = SPTabBarController() SPAPPTool.mainTabBarController = tabBarController window?.rootViewController = tabBarController window?.makeKeyAndVisible() } + + ///打开app + @objc private func handleOpenApp() { + setTabBarController() + + handleOpenAppMessage(webpageURL: nil) + } + + +} + +extension SceneDelegate { + ///语言切换 + @objc private func localizedDidChange() { + MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey + + setTabBarController() + } + + ///监听网络变化 + @objc private func reachabilityDidChangeNotification() { + let localizedData = SPLocalizedManager.shared.localizedData ?? [:] + + if SPNetworkReachabilityManager.manager.isReachable == true && localizedData.isEmpty { + ///缺少语言数据,重新获取语言数据 + self.startApp() + } + } } diff --git a/MoviaBox/Base/Networking/Base/SPNetworkReachabilityManager.swift b/MoviaBox/Base/Networking/Base/SPNetworkReachabilityManager.swift index 344106a..6d74be2 100644 --- a/MoviaBox/Base/Networking/Base/SPNetworkReachabilityManager.swift +++ b/MoviaBox/Base/Networking/Base/SPNetworkReachabilityManager.swift @@ -55,7 +55,9 @@ class SPNetworkReachabilityManager { if self.isReachable == false { print("++++++有网") self.isReachable = true - NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil) + DispatchQueue.main.async { + NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil) + } } else { self.isReachable = true } @@ -64,7 +66,9 @@ class SPNetworkReachabilityManager { if self.isReachable == true { print("++++++无网") self.isReachable = false - NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil) + DispatchQueue.main.async { + NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil) + } } else { self.isReachable = false } diff --git a/MoviaBox/Class/Player/Model/SPShortModel.swift b/MoviaBox/Class/Player/Model/SPShortModel.swift index 4bb8dd9..eecf93e 100644 --- a/MoviaBox/Class/Player/Model/SPShortModel.swift +++ b/MoviaBox/Class/Player/Model/SPShortModel.swift @@ -13,7 +13,7 @@ class SPShortModel: SPModel, SmartCodable { var id: String? var all_coins: String? var buy_type: String? - var collect_total: String? + var collect_total: Int? var sp_description: String? var episode_total: Int? var horizontally_img: String? diff --git a/MoviaBox/Class/Player/View/SPPlayLockView.swift b/MoviaBox/Class/Player/View/SPPlayLockView.swift index e0b907d..0bf9763 100644 --- a/MoviaBox/Class/Player/View/SPPlayLockView.swift +++ b/MoviaBox/Class/Player/View/SPPlayLockView.swift @@ -40,7 +40,7 @@ class SPPlayLockView: UIView { let label = UILabel() label.font = .fontRegular(ofSize: 18) label.textColor = .colorFFFFFF() - label.text = "movia_video_lock_tip".localized + label.text = "movia_video_lock_tip_01".localized return label }() diff --git a/MoviaBox/Class/Player/View/SPPlayerControlView.swift b/MoviaBox/Class/Player/View/SPPlayerControlView.swift index 15c6344..64b2f1d 100644 --- a/MoviaBox/Class/Player/View/SPPlayerControlView.swift +++ b/MoviaBox/Class/Player/View/SPPlayerControlView.swift @@ -109,7 +109,8 @@ class SPPlayerControlView: UIView { ///收藏按钮 private lazy var collectButton: UIButton = { - let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected")) +// let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected")) + let button = createFeatureButton(title: "0", image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected")) button.addTarget(self, action: #selector(handleCollectButton), for: .touchUpInside) return button }() @@ -235,7 +236,18 @@ extension SPPlayerControlView { let isCollect = !(self.shortModel?.is_collect ?? false) - SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) { + SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) { [weak self] in + guard let self = self else { return } + var count = self.shortModel?.collect_total ?? 0 + if isCollect { + count += 1 + } else { + count -= 1 + } + if count < 0 { + count = 0 + } + self.shortModel?.collect_total = count } } @@ -252,6 +264,7 @@ extension SPPlayerControlView { private func updateCollectButtonState() { self.collectButton.isSelected = self.shortModel?.is_collect ?? false + self.collectButton.setTitle("\(self.shortModel?.collect_total ?? 0)", for: .normal) } } diff --git a/MoviaBox/Class/Wallet/Controller/SPOrderRecordsPageViewController.swift b/MoviaBox/Class/Wallet/Controller/SPOrderRecordsPageViewController.swift index e143624..ba7ef1f 100644 --- a/MoviaBox/Class/Wallet/Controller/SPOrderRecordsPageViewController.swift +++ b/MoviaBox/Class/Wallet/Controller/SPOrderRecordsPageViewController.swift @@ -9,7 +9,7 @@ import UIKit class SPOrderRecordsPageViewController: SPViewController { - private lazy var titles: [String] = ["movia_Coin_Record".localized, "VIP Record".localized] + private lazy var titles: [String] = ["movia_Coin_Record".localized, "movia_VIP_Record".localized] private lazy var viewControllers: [UIViewController] = { let vc1 = SPCoinOrderRecordViewController() let vc2 = SPVIPOrderRecordViewController() diff --git a/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift b/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift index 120cb4d..1598f2f 100644 --- a/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift +++ b/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift @@ -13,8 +13,8 @@ class SPConsumptionRecordsCell: SPTableViewCell { didSet { titleLabel.text = "movia_Purchase_Single_Episode".localized timeLabel.text = model?.created_at - desLabel.text = "Ep.\(model?.episode ?? "") \(model?.name ?? "")" let episode = String(format: "movia_text_episcode_ios".localized, "\(model?.episode ?? "0")") + "\(model?.name ?? "")" + desLabel.text = episode coinLabel.text = "-\(model?.coins ?? 0) " + "movia_profile_Coins".localized } } diff --git a/MoviaBox/Libs/SPLocalizedManager/SPLocalizedManager.swift b/MoviaBox/Libs/SPLocalizedManager/SPLocalizedManager.swift index b1f3122..52fc4e4 100644 --- a/MoviaBox/Libs/SPLocalizedManager/SPLocalizedManager.swift +++ b/MoviaBox/Libs/SPLocalizedManager/SPLocalizedManager.swift @@ -11,25 +11,41 @@ class SPLocalizedManager: NSObject { static let shared = SPLocalizedManager() private let LocalizedUserDefaultsKey = "SPLocalizedManager.LocalizedUserDefaultsKey" private let LocalizedDataUserDefaultsKey = "SPLocalizedManager.LocalizedDataUserDefaultsKey" - + private let LocalizedDataLocalizedKeyUserDefaultsKey = "SPLocalizedManager.LocalizedDataLocalizedKeyUserDefaultsKey" ///语言列表 var languageList: [SPLanguageModel]? ///多语言数据 - private lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String] + private(set) lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String] { didSet { UserDefaults.standard.set(localizedData, forKey: LocalizedDataUserDefaultsKey) UserDefaults.standard.synchronize() } } + ///当前语言数据对应的key + private(set) lazy var localizedDataLocalizedKey: String? = UserDefaults.standard.object(forKey: LocalizedDataLocalizedKeyUserDefaultsKey) as? String + { + didSet { + UserDefaults.standard.set(localizedDataLocalizedKey, forKey: LocalizedDataLocalizedKeyUserDefaultsKey) + UserDefaults.standard.synchronize() + } + } // 获取当前语言代码(如果用户未手动设置,则返回系统语言) var currentLocalizedKey: String { get { -// return UserDefaults.standard.string(forKey: userDefaultsKey) ?? Locale.preferredLanguages.first ?? "en" - return UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? "en" + var key = (UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? Locale.preferredLanguages.first) ?? "en" + if key.contains("zh-Hans") { + key = "zh" + } else if key.contains("zh-Hant") { + key = "zh_hk" + } else { + let arr = key.components(separatedBy: "-") + key = arr.first ?? "en" + } + return key } set { UserDefaults.standard.set(newValue, forKey: LocalizedUserDefaultsKey) @@ -89,6 +105,7 @@ extension SPLocalizedManager { } if let localizedData = model.translates { + self.localizedDataLocalizedKey = key self.localizedData = localizedData completer?(true) } else {