Explorar o código

update support resourcesmediabundle for release to cocoapods

alqindiirsyam hai 6 meses
pai
achega
6228e983bb

+ 3 - 0
NexilisLite/NexilisLite/Source/FloatingButton/FloatingButton.swift

@@ -100,6 +100,9 @@ public class FloatingButton: UIView, UIGestureRecognizerDelegate {
             var urlGif = URL(string: configModeFB == MODE_VERTICAL_ANIMATION ? Utils.getIconCenterAnim2() : Utils.getIconCenterAnim4())
             if (urlGif == nil) {
                 urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: configModeFB == MODE_VERTICAL_ANIMATION ? "pb_def_icon_mode2" : "pb_def_icon_mode4", withExtension: "gif")! //resourcesMediaBundle
+                if urlGif == nil {
+                    urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: configModeFB == MODE_VERTICAL_ANIMATION ? "pb_def_icon_mode2" : "pb_def_icon_mode4", withExtension: "gif")!
+                }
             }
             nexilis_button.sd_setImage(with: urlGif) { [self] (image, error, cacheType, imageURL) in
                 if error == nil {

+ 9 - 4
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -2073,13 +2073,18 @@ extension UIFont {
 //            return
 //        }
         
-        guard let pathForResourceURL = Bundle.resourceBundle(for: Nexilis.self).url(forResource: filenameString, withExtension: "otf") else { //resourcesMediaBundle
-            //print("UIFont+:  Failed to register font - path for resource not found.")
-            return
+        var pathForResourceURL = Bundle.resourceBundle(for: Nexilis.self).url(forResource: filenameString, withExtension: "otf")
+        if pathForResourceURL == nil {
+            pathForResourceURL = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: filenameString, withExtension: "otf")
         }
         
+//        guard let pathForResourceURL = Bundle.resourceBundle(for: Nexilis.self).url(forResource: filenameString, withExtension: "otf") else { //resourcesMediaBundle
+//            //print("UIFont+:  Failed to register font - path for resource not found.")
+//            return
+//        }
+        
         var errorRef: Unmanaged<CFError>? = nil
-        CTFontManagerRegisterFontsForURL(pathForResourceURL as CFURL, .process, &errorRef)
+        CTFontManagerRegisterFontsForURL(pathForResourceURL! as CFURL, .process, &errorRef)
 
 //        guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
 //            //print("UIFont+:  Failed to register font - font data could not be loaded.")

+ 15 - 2
NexilisLite/NexilisLite/Source/View/Chat/ChatGPTBotView.swift

@@ -606,7 +606,7 @@ public class ChatGPTBotView: UIViewController, UIGestureRecognizerDelegate {
             let imageProfile = UIImageView(frame: CGRect(x: 0, y: 7, width: 30, height: 30))
             imageProfile.circle()
             imageProfile.clipsToBounds = true
-            var count = 0
+//            var count = 0
             viewAppBar.addSubview(imageProfile)
             if let urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {//resourcesMediaBundle
                 imageProfile.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
@@ -617,6 +617,15 @@ public class ChatGPTBotView: UIViewController, UIGestureRecognizerDelegate {
                         imageProfile.startAnimating()
                     }
                 }
+            } else if let urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+                imageProfile.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
+                    if error == nil {
+                        imageProfile.animationImages = image?.images
+                        imageProfile.animationDuration = image?.duration ?? 0.0
+                        imageProfile.animationRepeatCount = 0
+                        imageProfile.startAnimating()
+                    }
+                }
             }
             let titleNavigation = UILabel(frame: CGRect(x: 35, y: 0, width: viewAppBar.frame.size.width - 250, height: 44))
             viewAppBar.addSubview(titleNavigation)
@@ -2087,7 +2096,11 @@ extension ChatGPTBotView: UITableViewDelegate, UITableViewDataSource {
                 imageSticker.leadingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: 15).isActive = true
                 imageSticker.bottomAnchor.constraint(equalTo: messageText.topAnchor, constant: -5).isActive = true
                 imageSticker.trailingAnchor.constraint(equalTo: containerMessage.trailingAnchor, constant: -15).isActive = true
-                imageSticker.image = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+                var imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+                if imageStickerBundle == nil {
+                    imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+                }
+                imageSticker.image = imageStickerBundle //resourcesMediaBundle
                 imageSticker.contentMode = .scaleAspectFit
             }
             else {

+ 27 - 8
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -198,12 +198,23 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
         documentPicker = DocumentPicker(presentationController: self, delegate: self)
         
         let fm = FileManager.default
-        let path = Bundle.resourceBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
-        let items = try! fm.contentsOfDirectory(atPath: path)
-        
-        for item in items {
-            if item.hasPrefix("sticker") {
-                stickers.append(item)
+        if let urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+            let path = Bundle.resourceBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
+            var items = try! fm.contentsOfDirectory(atPath: path)
+            
+            for item in items {
+                if item.hasPrefix("sticker") {
+                    stickers.append(item)
+                }
+            }
+        } else {
+            let path = Bundle.resourcesMediaBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
+            var items = try! fm.contentsOfDirectory(atPath: path)
+            
+            for item in items {
+                if item.hasPrefix("sticker") {
+                    stickers.append(item)
+                }
             }
         }
         
@@ -3907,7 +3918,11 @@ extension EditorGroup: UICollectionViewDelegate, UICollectionViewDataSource {
             imageSticker.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor),
             imageSticker.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor)
         ])
-        imageSticker.image = UIImage(named: stickers[indexPath.row], in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+        var imageStickerBundle = UIImage(named: stickers[indexPath.row], in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+        if imageStickerBundle == nil {
+            imageStickerBundle = UIImage(named: stickers[indexPath.row], in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+        }
+        imageSticker.image = imageStickerBundle //resourcesMediaBundle
         return cell
     }
     
@@ -4588,7 +4603,11 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource {
                 imageSticker.leadingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: 15).isActive = true
                 imageSticker.bottomAnchor.constraint(equalTo: messageText.topAnchor, constant: -5).isActive = true
                 imageSticker.trailingAnchor.constraint(equalTo: containerMessage.trailingAnchor, constant: -15).isActive = true
-                imageSticker.image = UIImage(named: (textChat?.components(separatedBy: "/")[1])!, in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+                var imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+                if imageStickerBundle == nil {
+                    imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+                }
+                imageSticker.image = imageStickerBundle //resourcesMediaBundle
                 imageSticker.contentMode = .scaleAspectFit
             }
             else {

+ 27 - 8
NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -206,12 +206,23 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
         documentPicker = DocumentPicker(presentationController: self, delegate: self)
         
         let fm = FileManager.default
-        let path = Bundle.resourceBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
-        let items = try! fm.contentsOfDirectory(atPath: path)
-        
-        for item in items {
-            if item.hasPrefix("sticker") {
-                stickers.append(item)
+        if let urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+            let path = Bundle.resourceBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
+            var items = try! fm.contentsOfDirectory(atPath: path)
+            
+            for item in items {
+                if item.hasPrefix("sticker") {
+                    stickers.append(item)
+                }
+            }
+        } else {
+            let path = Bundle.resourcesMediaBundle(for: Nexilis.self).resourcePath! //resourcesMediaBundle
+            var items = try! fm.contentsOfDirectory(atPath: path)
+            
+            for item in items {
+                if item.hasPrefix("sticker") {
+                    stickers.append(item)
+                }
             }
         }
         
@@ -5000,7 +5011,11 @@ extension EditorPersonal: UICollectionViewDelegate, UICollectionViewDataSource {
             imageSticker.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor),
             imageSticker.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor)
         ])
-        imageSticker.image = UIImage(named: stickers[indexPath.row], in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+        var imageStickerBundle = UIImage(named: stickers[indexPath.row], in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+        if imageStickerBundle == nil {
+            imageStickerBundle = UIImage(named: stickers[indexPath.row], in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+        }
+        imageSticker.image = imageStickerBundle //resourcesMediaBundle
         return cell
     }
     
@@ -5790,7 +5805,11 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
                 imageSticker.leadingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: 15).isActive = true
                 imageSticker.bottomAnchor.constraint(equalTo: messageText.topAnchor, constant: -5).isActive = true
                 imageSticker.trailingAnchor.constraint(equalTo: containerMessage.trailingAnchor, constant: -15).isActive = true
-                imageSticker.image = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+                var imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+                if imageStickerBundle == nil {
+                    imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+                }
+                imageSticker.image = imageStickerBundle //resourcesMediaBundle
                 imageSticker.contentMode = .scaleAspectFit
             } else if dataMessages[indexPath.row]["message_scope_id"] as! String == "18" {
                 let data = textChat

+ 5 - 1
NexilisLite/NexilisLite/Source/View/Chat/EditorStarMessages.swift

@@ -425,7 +425,11 @@ public class EditorStarMessages: UIViewController, UITableViewDataSource, UITabl
                 imageSticker.bottomAnchor.constraint(equalTo: messageText.topAnchor, constant: -5).isActive = true
                 imageSticker.trailingAnchor.constraint(equalTo: containerMessage.trailingAnchor).isActive = true
                 imageSticker.widthAnchor.constraint(equalToConstant: 80).isActive = true
-                imageSticker.image = UIImage(named: (textChat?.components(separatedBy: "/")[1])!, in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+                var imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+                if imageStickerBundle == nil {
+                    imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+                }
+                imageSticker.image = imageStickerBundle //resourcesMediaBundle
                 imageSticker.contentMode = .scaleAspectFit
             }
             else {

+ 5 - 1
NexilisLite/NexilisLite/Source/View/Chat/MessageInfo.swift

@@ -713,7 +713,11 @@ class MessageInfo: UIViewController, UITableViewDelegate, UITableViewDataSource,
                     imageSticker.leadingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: 15).isActive = true
                     imageSticker.bottomAnchor.constraint(equalTo: messageText.topAnchor, constant: -5).isActive = true
                     imageSticker.trailingAnchor.constraint(equalTo: containerMessage.trailingAnchor, constant: -15).isActive = true
-                    imageSticker.image = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil) //resourcesMediaBundle
+                    var imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
+                    if imageStickerBundle == nil {
+                        imageStickerBundle = UIImage(named: (textChat.components(separatedBy: "/")[1]), in: Bundle.resourcesMediaBundle(for: Nexilis.self), with: nil)
+                    }
+                    imageSticker.image = imageStickerBundle //resourcesMediaBundle
                     imageSticker.contentMode = .scaleAspectFit
                 } else if data["message_scope_id"] as! String == "18" {
                     let data = textChat

+ 27 - 0
NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -1039,6 +1039,15 @@ extension ContactChatViewController {
                                 imageView.startAnimating()
                             }
                         }
+                    } else if let urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+                        imageView.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
+                            if error == nil {
+                                imageView.animationImages = image?.images
+                                imageView.animationDuration = image?.duration ?? 0.0
+                                imageView.animationRepeatCount = 0
+                                imageView.startAnimating()
+                            }
+                        }
                     }
                 }
                 else {
@@ -1129,6 +1138,15 @@ extension ContactChatViewController {
                                 imageView.startAnimating()
                             }
                         }
+                    } else if let urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+                        imageView.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
+                            if error == nil {
+                                imageView.animationImages = image?.images
+                                imageView.animationDuration = image?.duration ?? 0.0
+                                imageView.animationRepeatCount = 0
+                                imageView.startAnimating()
+                            }
+                        }
                     }
                 } else {
                     if !Utils.getIconDock().isEmpty && data.profile.isEmpty {
@@ -1410,6 +1428,15 @@ extension ContactChatViewController {
                                 imageView.startAnimating()
                             }
                         }
+                    } else if let urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
+                        imageView.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
+                            if error == nil {
+                                imageView.animationImages = image?.images
+                                imageView.animationDuration = image?.duration ?? 0.0
+                                imageView.animationRepeatCount = 0
+                                imageView.startAnimating()
+                            }
+                        }
                     }
                 }
                 else {