|
@@ -53,6 +53,9 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
let privacyWV = WKWebView()
|
|
|
let indicatorCounterFB = UIView()
|
|
|
let labelCounterFB = UILabel()
|
|
|
+ var indicatorView : UIView!
|
|
|
+ var indicatorImage : UIImageView!
|
|
|
+ var imageIndicator: UIImage!
|
|
|
|
|
|
public static var def: ViewController?
|
|
|
|
|
@@ -120,50 +123,122 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
if !Utils.getTab1Icon().isEmpty {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab1Icon())")!) { data, response, error in
|
|
|
- guard let data = data, error == nil else { return }
|
|
|
- // always update the UI from the main thread
|
|
|
- DispatchQueue.main.async() { [self] in
|
|
|
- tabs[0].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ let urlString = "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab1Icon())"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ tabs[0].tabBarItem = UITabBarItem(title: "", image: self.resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: self.resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ // always update the UI from the main thread
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ tabs[0].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !Utils.getTab2Icon().isEmpty {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab2Icon())")!) { data, response, error in
|
|
|
- guard let data = data, error == nil else { return }
|
|
|
- // always update the UI from the main thread
|
|
|
+ let urlString = "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab2Icon())"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
DispatchQueue.main.async() { [self] in
|
|
|
- tabs[1].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ tabs[1].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ // always update the UI from the main thread
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ tabs[1].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !Utils.getTab3Icon().isEmpty {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab3Icon())")!) { data, response, error in
|
|
|
- guard let data = data, error == nil else { return }
|
|
|
- // always update the UI from the main thread
|
|
|
+ let urlString = "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab3Icon())"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
DispatchQueue.main.async() { [self] in
|
|
|
if cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX {
|
|
|
- tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
} else {
|
|
|
- tabs[2].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ tabs[2].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ // always update the UI from the main thread
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ if cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX {
|
|
|
+ tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ } else {
|
|
|
+ tabs[2].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !Utils.getTab4Icon().isEmpty {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab4Icon())")!) { data, response, error in
|
|
|
- guard let data = data, error == nil else { return }
|
|
|
- // always update the UI from the main thread
|
|
|
+ let urlString = "\(PrefsUtil.getURLBase())get_file_from_path?img=\(Utils.getTab4Icon())"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
DispatchQueue.main.async() { [self] in
|
|
|
if cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX {
|
|
|
- tabs[4].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ tabs[4].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
} else {
|
|
|
- tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: cachedImage, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ // always update the UI from the main thread
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ if cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX {
|
|
|
+ tabs[4].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ } else {
|
|
|
+ tabs[3].tabBarItem = UITabBarItem(title: "", image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal), selectedImage: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 30, height: 30)).withRenderingMode(.alwaysOriginal))
|
|
|
+ }
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if !Utils.getIndicatorTabImage().isEmpty {
|
|
|
+ let indicatorImage = Utils.getIndicatorTabImage()
|
|
|
+ let fullUrl = "\(PrefsUtil.getURLBase())get_file_from_path?img=\(indicatorImage)"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: fullUrl) {
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ imageIndicator = cachedImage
|
|
|
+ addCustomViewAboveTabBarItem(at: 0, image: imageIndicator)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: fullUrl)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ // always update the UI from the main thread
|
|
|
+ DispatchQueue.main.async() { [self] in
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ imageIndicator = UIImage(data: data)!
|
|
|
+ addCustomViewAboveTabBarItem(at: 0, image: imageIndicator)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: fullUrl)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+// addCustomViewAboveTabBarItem(at: 0, image: imageIndicator)
|
|
|
+ }
|
|
|
if((cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
|
|
|
createMidFloatingButton()
|
|
|
navigationController?.setNavigationBarHidden(true, animated: false)
|
|
@@ -194,6 +269,39 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
// Nexilis.debugBroadcast()
|
|
|
}
|
|
|
|
|
|
+ func addCustomViewAboveTabBarItem(at index: Int, image: UIImage?) {
|
|
|
+ guard let tabBarItems = tabBar.items, index < tabBarItems.count else { return }
|
|
|
+ let tabBarFrame = tabBar.frame
|
|
|
+ let tabBarItemWidth = tabBarFrame.width / CGFloat(tabBarItems.count)
|
|
|
+ let xCenter = CGFloat(index) * tabBarItemWidth + (tabBarItemWidth / 2)
|
|
|
+ let yCenter = tabBarFrame.origin.y + (tabBarFrame.height / 2)
|
|
|
+ if image != nil {
|
|
|
+ indicatorImage = UIImageView(image: image)
|
|
|
+ indicatorImage.contentMode = .scaleAspectFit
|
|
|
+ indicatorImage.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
|
|
|
+ indicatorImage.center = CGPoint(x: xCenter, y: yCenter)
|
|
|
+ view.addSubview(indicatorImage)
|
|
|
+ } else {
|
|
|
+ indicatorView = UIView()
|
|
|
+ indicatorView.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
|
|
|
+ indicatorView.center = CGPoint(x: xCenter, y: yCenter)
|
|
|
+ let gradientLayer = CAGradientLayer()
|
|
|
+ gradientLayer.type = .radial
|
|
|
+ gradientLayer.colors = [
|
|
|
+ UIColor(white: 1.0, alpha: 0.0).cgColor,
|
|
|
+ UIColor(white: 1.0, alpha: 0.0).cgColor,
|
|
|
+ UIColor(red: 0.75, green: 0.71, blue: 0.71, alpha: 1.0).cgColor
|
|
|
+ ]
|
|
|
+ gradientLayer.locations = [0.0, 0.7, 1.0]
|
|
|
+ gradientLayer.bounds = CGRect(x: 0, y: 0, width: 90, height: 90)
|
|
|
+ gradientLayer.position = CGPoint(x: 45, y: 45)
|
|
|
+ indicatorView.layer.insertSublayer(gradientLayer, at: 0)
|
|
|
+ indicatorView.layer.cornerRadius = indicatorView.frame.width / 2
|
|
|
+ indicatorView.clipsToBounds = true
|
|
|
+ view.addSubview(indicatorView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static func getiPhoneModel() -> String {
|
|
|
var systemInfo = utsname()
|
|
|
uname(&systemInfo)
|
|
@@ -358,30 +466,6 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
ViewController.isTab2 = false
|
|
|
ViewController.isTab3 = false
|
|
|
ViewController.isTab4 = false
|
|
|
-// if ViewController.isTab1 {
|
|
|
-// ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis")!
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis_off")!
|
|
|
-// }
|
|
|
-// if ViewController.isTab2 {
|
|
|
-// ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis")!
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis_off")!
|
|
|
-// }
|
|
|
-// if ViewController.isTab3 {
|
|
|
-// ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis")!
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis_off")!
|
|
|
-// }
|
|
|
-// if ViewController.isTab4 {
|
|
|
-// ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis")!
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis_off")!
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
|
|
@@ -467,13 +551,7 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
ViewController.middleButton = UIButton(frame: CGRect(x: buttonCenterX - 40 , y: buttonCenterY - 40, width: 80, height: 80))
|
|
|
if !PrefsUtil.getIconDock().isEmpty {
|
|
|
if PrefsUtil.getIconDock().contains(".gif") {
|
|
|
- ViewController.middleButton.sd_setBackgroundImage(with: URL(string: PrefsUtil.getIconCenterAnim()!), for: .normal, completed: { (image, error, cacheType, imageURL) in
|
|
|
- if let error = error {
|
|
|
- //print("Error loading image: \(error.localizedDescription)")
|
|
|
- } else {
|
|
|
- //print("Image loaded successfully")
|
|
|
- }
|
|
|
- })
|
|
|
+ ViewController.middleButton.sd_setBackgroundImage(with: URL(string: PrefsUtil.getIconCenterAnim()!), for: .normal, completed: nil)
|
|
|
} else {
|
|
|
DispatchQueue.global().async {
|
|
|
let urlString = PrefsUtil.getUrlDock()!
|
|
@@ -539,6 +617,12 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
}
|
|
|
|
|
|
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
|
|
+ if let selectedIndex = viewControllers?.firstIndex(of: viewController) {
|
|
|
+ if indicatorImage != nil {
|
|
|
+ indicatorImage.removeFromSuperview()
|
|
|
+ addCustomViewAboveTabBarItem(at: selectedIndex, image: imageIndicator)
|
|
|
+ }
|
|
|
+ }
|
|
|
if viewController != secondTab {
|
|
|
let idxTabChat = self.viewControllers?.firstIndex(where: {$0 == secondTab})
|
|
|
if idxTabChat != nil {
|
|
@@ -1036,20 +1120,38 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
let icon = customIcons[i]
|
|
|
listPullFB.append("\(package_id)|\(app_id)")
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "get_file_from_path?img=\(icon)")!) { data, response, error in
|
|
|
+ let urlString = PrefsUtil.getURLBase() + "get_file_from_path?img=\(icon)"
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ if i == 0 {
|
|
|
+ ViewController.chatButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ } else if i == 1 {
|
|
|
+ ViewController.callButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ } else if i == 2 {
|
|
|
+ ViewController.ccButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ } else if i == 3 {
|
|
|
+ ViewController.postButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ } else if i == 4 {
|
|
|
+ ViewController.streamingButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- if i == 0 {
|
|
|
- ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
- } else if i == 1 {
|
|
|
- ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
- } else if i == 2 {
|
|
|
- ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
- } else if i == 3 {
|
|
|
- ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
- } else if i == 4 {
|
|
|
- ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ if i == 0 {
|
|
|
+ ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ } else if i == 1 {
|
|
|
+ ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ } else if i == 2 {
|
|
|
+ ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ } else if i == 3 {
|
|
|
+ ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ } else if i == 4 {
|
|
|
+ ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ }
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1072,14 +1174,24 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
let app_id = (json["app_id"] as? String) ?? ""
|
|
|
let icon = (json["icon"] as? String) ?? ""
|
|
|
listPullFB.append("\(package_id)|\(app_id)")
|
|
|
+ let urlString = "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)"
|
|
|
if count == 0 {
|
|
|
if !icon.isEmpty {
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) { data, response, error in
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ ViewController.chatButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1089,58 +1201,94 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
} else if count == 1 {
|
|
|
if !icon.isEmpty {
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) { data, response, error in
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ ViewController.callButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
+ ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
}
|
|
|
} else if count == 2 {
|
|
|
if !icon.isEmpty {
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) { data, response, error in
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ ViewController.ccButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
+ ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
}
|
|
|
} else if count == 3 {
|
|
|
if !icon.isEmpty {
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) { data, response, error in
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ ViewController.postButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
+ ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_post", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
}
|
|
|
} else if count == 4 {
|
|
|
if !icon.isEmpty {
|
|
|
DispatchQueue.global().async {
|
|
|
- ViewController.getDataImageFromUrl(from: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) { data, response, error in
|
|
|
+ if let cachedImage = ImageCache.shared.image(forKey: urlString) {
|
|
|
+ DispatchQueue.main.async() {
|
|
|
+ ViewController.streamingButton.setBackgroundImage(cachedImage, for: .normal)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
|
|
|
guard let data = data, error == nil else { return }
|
|
|
// always update the UI from the main thread
|
|
|
DispatchQueue.main.async() {
|
|
|
- ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ if UIImage(data: data) != nil {
|
|
|
+ ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
|
|
|
+ ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
+ ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
|
|
|
}
|
|
|
}
|
|
|
count += 1
|
|
@@ -1253,13 +1401,6 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
|
|
|
// ViewController.postButton.removeFromSuperview()
|
|
|
ViewController.middleButton.isHidden = true
|
|
|
}
|
|
|
-
|
|
|
- public static func getDataImageFromUrl(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
|
|
|
- let urlConfig = URLSessionConfiguration.default
|
|
|
- let sessionDelegate = SelfSignedURLSessionDelegate()
|
|
|
- let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
|
|
|
- session.dataTask(with: url, completionHandler: completion).resume()
|
|
|
- }
|
|
|
|
|
|
}
|
|
|
|