alqindiirsyam пре 1 година
родитељ
комит
908c913131

+ 70 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/FloatingButton/FloatingButton.swift

@@ -33,6 +33,11 @@ public class FloatingButton: UIView {
     let indicatorCounterFBBig = UIImageView()
     
     var datePull: Date?
+    var animationTimer = Timer()
+    var configAnim: Int = Int(Utils.getFloatingAnim().components(separatedBy: "~")[0]) ?? 1
+    var isLoopingAnim = (Int(Utils.getFloatingAnim().components(separatedBy: "~")[1]) ?? 1) == 1 ? true : false
+    var lastRunAnimationHrz = -1
+    var lastRunAnimationVrt = -1
     
     var panGesture: UIPanGestureRecognizer?
     var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
@@ -110,6 +115,21 @@ public class FloatingButton: UIView {
         backgroundColor = .clear
         frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? UIScreen.main.bounds.width - defaultWidthFB : defaultWidthFB, height: defaultHeightFB)
         
+        if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
+            if configAnim == 0 { //left to right
+                lastRunAnimationHrz = 1
+            } else if configAnim == 1 { //right to left
+                lastRunAnimationHrz = -1
+            } else if configAnim == 2 { //top to bottom
+                lastRunAnimationVrt = 1
+            } else if configAnim == 3 { //top to bottom
+                lastRunAnimationVrt = -1
+            }
+            if configAnim >= 0 && configAnim <= 3 {
+                checkDelayAnimation()
+            }
+        }
+        
         let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
         qmeraTap.numberOfTouchesRequired = 1
         nexilis_button.addGestureRecognizer(qmeraTap)
@@ -189,6 +209,52 @@ public class FloatingButton: UIView {
         UIApplication.shared.windows.first?.rootViewController?.view.addGestureRecognizer(tapGesture)
     }
     
+    private func checkDelayAnimation() {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
+            if !isShow {
+                animationTimer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(runAnimation), userInfo: nil, repeats: true)
+            }
+        })
+    }
+    
+    @objc func runAnimation(){
+        DispatchQueue.main.async { [self] in
+            if configAnim == 0 || configAnim == 1 {
+                if (lastRunAnimationHrz == -1 && frame.origin.x >= 0) || lastRunAnimationHrz == 1 && frame.origin.x <= UIScreen.main.bounds.width - defaultWidthFB {
+                    if lastRunAnimationHrz == -1 {
+                        frame.origin.x-=0.1
+                    } else {
+                        frame.origin.x+=0.1
+                    }
+                } else {
+                    lastRunAnimationHrz = lastRunAnimationHrz == 1 ? -1 : 1
+                    if (lastRunAnimationHrz == -1 && configAnim == 1) || (lastRunAnimationHrz == 1 && configAnim == 0) {
+                        animationTimer.invalidate()
+                        if isLoopingAnim {
+                            checkDelayAnimation()
+                        }
+                    }
+                }
+            } else {
+                if (lastRunAnimationVrt == -1 && frame.origin.y >= 0) || lastRunAnimationVrt == 1 && frame.origin.y <= UIScreen.main.bounds.height - defaultHeightFB {
+                    if lastRunAnimationVrt == -1 {
+                        frame.origin.y-=0.1
+                    } else {
+                        frame.origin.y+=0.1
+                    }
+                } else {
+                    lastRunAnimationVrt = lastRunAnimationVrt == 1 ? -1 : 1
+                    if (lastRunAnimationVrt == -1 && configAnim == 3) || (lastRunAnimationVrt == 1 && configAnim == 2) {
+                        animationTimer.invalidate()
+                        if isLoopingAnim {
+                            checkDelayAnimation()
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
     private func pullButton() {
         if datePull == nil || Int(Date().timeIntervalSince(datePull!)) >= 60 {
             datePull = Date()
@@ -545,6 +611,7 @@ public class FloatingButton: UIView {
     public func show(isShow: Bool) {
         self.isShow = isShow
         if isShow {
+            animationTimer.invalidate()
             pullButton()
             if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
                 indicatorCounterFBBig.isHidden = true
@@ -610,6 +677,9 @@ public class FloatingButton: UIView {
                     frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
                 })
             }
+            if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
+                checkDelayAnimation()
+            }
         }
     }
 }

+ 3 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/IncomingThread.swift

@@ -247,6 +247,9 @@ class IncomingThread {
                     if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_button_icon" {
                         Utils.setCustomFBIcon(value: json[CoreMessage_TMessageKey.VALUE] as! String)
                     }
+                    if json[CoreMessage_TMessageKey.KEY] as! String == "fb_floating_anim" {
+                        Utils.setFloatingAnim(value: json[CoreMessage_TMessageKey.VALUE] as! String)
+                    }
                 }
                 Utils.setFinishInitPrefs(value: true)
             } else {

+ 8 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/Utils.swift

@@ -245,6 +245,14 @@ public final class Utils {
         return UserDefaults.standard.string(forKey: "default_cc")
     }
     
+    static func setFloatingAnim(value: String){
+        UserDefaults.standard.set(value, forKey: "fb_floating_anim")
+    }
+    
+    static func getFloatingAnim() -> String {
+        return UserDefaults.standard.string(forKey: "fb_floating_anim") ?? "1~1"
+    }
+    
     public static var inTabChats = false
 }
 public extension UIImage {

+ 70 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/FloatingButton/FloatingButton.swift

@@ -33,6 +33,11 @@ public class FloatingButton: UIView {
     let indicatorCounterFBBig = UIImageView()
     
     var datePull: Date?
+    var animationTimer = Timer()
+    var configAnim: Int = Int(Utils.getFloatingAnim().components(separatedBy: "~")[0]) ?? 1
+    var isLoopingAnim = (Int(Utils.getFloatingAnim().components(separatedBy: "~")[1]) ?? 1) == 1 ? true : false
+    var lastRunAnimationHrz = -1
+    var lastRunAnimationVrt = -1
     
     var panGesture: UIPanGestureRecognizer?
     var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
@@ -110,6 +115,21 @@ public class FloatingButton: UIView {
         backgroundColor = .clear
         frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? UIScreen.main.bounds.width - defaultWidthFB : defaultWidthFB, height: defaultHeightFB)
         
+        if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
+            if configAnim == 0 { //left to right
+                lastRunAnimationHrz = 1
+            } else if configAnim == 1 { //right to left
+                lastRunAnimationHrz = -1
+            } else if configAnim == 2 { //top to bottom
+                lastRunAnimationVrt = 1
+            } else if configAnim == 3 { //top to bottom
+                lastRunAnimationVrt = -1
+            }
+            if configAnim >= 0 && configAnim <= 3 {
+                checkDelayAnimation()
+            }
+        }
+        
         let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
         qmeraTap.numberOfTouchesRequired = 1
         nexilis_button.addGestureRecognizer(qmeraTap)
@@ -189,6 +209,52 @@ public class FloatingButton: UIView {
         UIApplication.shared.windows.first?.rootViewController?.view.addGestureRecognizer(tapGesture)
     }
     
+    private func checkDelayAnimation() {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
+            if !isShow {
+                animationTimer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(runAnimation), userInfo: nil, repeats: true)
+            }
+        })
+    }
+    
+    @objc func runAnimation(){
+        DispatchQueue.main.async { [self] in
+            if configAnim == 0 || configAnim == 1 {
+                if (lastRunAnimationHrz == -1 && frame.origin.x >= 0) || lastRunAnimationHrz == 1 && frame.origin.x <= UIScreen.main.bounds.width - defaultWidthFB {
+                    if lastRunAnimationHrz == -1 {
+                        frame.origin.x-=0.1
+                    } else {
+                        frame.origin.x+=0.1
+                    }
+                } else {
+                    lastRunAnimationHrz = lastRunAnimationHrz == 1 ? -1 : 1
+                    if (lastRunAnimationHrz == -1 && configAnim == 1) || (lastRunAnimationHrz == 1 && configAnim == 0) {
+                        animationTimer.invalidate()
+                        if isLoopingAnim {
+                            checkDelayAnimation()
+                        }
+                    }
+                }
+            } else {
+                if (lastRunAnimationVrt == -1 && frame.origin.y >= 0) || lastRunAnimationVrt == 1 && frame.origin.y <= UIScreen.main.bounds.height - defaultHeightFB {
+                    if lastRunAnimationVrt == -1 {
+                        frame.origin.y-=0.1
+                    } else {
+                        frame.origin.y+=0.1
+                    }
+                } else {
+                    lastRunAnimationVrt = lastRunAnimationVrt == 1 ? -1 : 1
+                    if (lastRunAnimationVrt == -1 && configAnim == 3) || (lastRunAnimationVrt == 1 && configAnim == 2) {
+                        animationTimer.invalidate()
+                        if isLoopingAnim {
+                            checkDelayAnimation()
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
     private func pullButton() {
         if datePull == nil || Int(Date().timeIntervalSince(datePull!)) >= 60 {
             datePull = Date()
@@ -545,6 +611,7 @@ public class FloatingButton: UIView {
     public func show(isShow: Bool) {
         self.isShow = isShow
         if isShow {
+            animationTimer.invalidate()
             pullButton()
             if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
                 indicatorCounterFBBig.isHidden = true
@@ -610,6 +677,9 @@ public class FloatingButton: UIView {
                     frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
                 })
             }
+            if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
+                checkDelayAnimation()
+            }
         }
     }
 }

+ 3 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -247,6 +247,9 @@ class IncomingThread {
                     if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_button_icon" {
                         Utils.setCustomFBIcon(value: json[CoreMessage_TMessageKey.VALUE] as! String)
                     }
+                    if json[CoreMessage_TMessageKey.KEY] as! String == "fb_floating_anim" {
+                        Utils.setFloatingAnim(value: json[CoreMessage_TMessageKey.VALUE] as! String)
+                    }
                 }
                 Utils.setFinishInitPrefs(value: true)
             } else {

+ 8 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Utils.swift

@@ -245,6 +245,14 @@ public final class Utils {
         return UserDefaults.standard.string(forKey: "default_cc")
     }
     
+    static func setFloatingAnim(value: String){
+        UserDefaults.standard.set(value, forKey: "fb_floating_anim")
+    }
+    
+    static func getFloatingAnim() -> String {
+        return UserDefaults.standard.string(forKey: "fb_floating_anim") ?? "1~1"
+    }
+    
     public static var inTabChats = false
 }
 public extension UIImage {