123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // KMAdvertisementModelTansition.swift
- // KMAdvertisement
- //
- // Created by lizhe on 2022/12/2.
- //
- import AppKit
- @objcMembers open class KMAdvertisementModelTransition: NSObject {
- //MARK: 模型转换
-
- //图片转换
- public static func transitionImagePath(image: KMAdvertisementItemInfo.Image?, highlight:Bool) -> String {
- var result = ""
- guard let tempImage = image else { return result }
-
- if highlight {
- result = (KMAdvertisementConfig.isDarkModel() ? tempImage.hover_Dark : tempImage.hover_Light) ?? ""
- } else {
- result = (KMAdvertisementConfig.isDarkModel() ? tempImage.normal_Dark : tempImage.normal_Light) ?? ""
- }
-
- if result.count == 0 {
- let language = Language()
- language.en = image?.en
- language.zh_TW = image?.zh_TW
- language.zh_CN = image?.zh_CN
- result = KMAdvertisementModelTransition.transitionLanguage(langeuage: language)
- }
-
- return result
- }
-
- //多语转换
- @objc public static func transitionLanguage(langeuage: Language?) -> String {
- var result = ""
-
- // let string = KMAdvertisementModelTransition.getLanguageType()
- // if string == "zh-Hans-CN" {
- // result = langeuage?.zh_CN ?? ""
- // } else if string == "zh-Hans-TW" {
- let string = KMAdvertisementModelTransition.getLanguageType()
- if string == "zh-Hans-CN" || string == "zh-Hans" {
- result = langeuage?.zh_CN ?? ""
- } else if string == "zh-Hans-TW" ||
- string == "zh-Hant-CN" ||
- string == "zh-Hant" {
- result = langeuage?.zh_TW ?? ""
- } else {
- result = langeuage?.en ?? ""
- }
- return result
- }
-
- public static func getLanguageType() -> String {
- #if os(iOS)
- let def = UserDefaults.standard
- let allLanguages: [String] = def.object(forKey: "AppleLanguages") as! [String]
- let chooseLanguage = allLanguages.first
- return chooseLanguage ?? "en"
- #elseif os(OSX)
- let allLanguages: [String] = UserDefaults.standard.object(forKey: "AppleLanguages") as! [String]
- let chooseLanguage: String = allLanguages.first ?? "en"
- return chooseLanguage
- #endif
- }
-
- @objc public static func sendFireBaseEvent(firebase: firebaseInfo?) -> Void {
- guard let firebaseInfo = firebase else {
- return
- }
- guard let fireBaseEvent = firebaseInfo.event else {
- return
- }
- guard let firebasePropertyKey = firebaseInfo.propertyKey else {
- return
- }
- guard let firebasePropertyValue = firebaseInfo.propertyValue else {
- return
- }
- FMTrackEventManager.defaultManager.trackEvent(event: fireBaseEvent, withProperties: [firebasePropertyKey : firebasePropertyValue])
- }
- }
- extension NSColor {
- convenience init(hex: String) {
- var hexString = hex
- if hex.starts(with: "#") {
- hexString = String(hex.dropFirst())
- }
- if let ui64 = UInt64(hexString, radix: 16) {
- self.init(hex: Int(ui64))
- } else {
- self.init(hex: 0) // <--- black
- }
- }
-
- convenience init(hex: Int) {
- let components = (
- R: CGFloat((hex >> 16) & 0xff) / 255,
- G: CGFloat((hex >> 08) & 0xff) / 255,
- B: CGFloat((hex >> 00) & 0xff) / 255
- )
- self.init(red: components.R, green: components.G, blue: components.B, alpha: 1)
- }
-
- }
|