|
@@ -35,6 +35,19 @@ public class FloatingButton: UIView {
|
|
|
var datePull: Date?
|
|
|
|
|
|
var panGesture: UIPanGestureRecognizer?
|
|
|
+ var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
|
+ var defaultHeightFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
|
+ let defaultWidthHeightMenuFB = (UIScreen.main.bounds.height * 0.45) / 7.5
|
|
|
+ let widthFBAnim = (UIScreen.main.bounds.height * 1) / 7.5
|
|
|
+ let heightFBAnim = (UIScreen.main.bounds.height * 1) / 7.5
|
|
|
+
|
|
|
+ var countMenuFB: CGFloat = 5 {
|
|
|
+ didSet {
|
|
|
+ if isShow {
|
|
|
+ show(isShow: isShow)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public weak var mySettingDelegate: SettingMABDelegate?
|
|
|
|
|
@@ -51,24 +64,41 @@ public class FloatingButton: UIView {
|
|
|
}
|
|
|
|
|
|
private func commonInit() {
|
|
|
- backgroundColor = .clear
|
|
|
- frame = CGRect(x: UIScreen.main.bounds.width - 50, y: (UIScreen.main.bounds.height / 2) - 50, width: 50.0, height: 50.0)
|
|
|
-
|
|
|
panGesture = UIPanGestureRecognizer(target: self, action: #selector(draggedView(_:)))
|
|
|
addGestureRecognizer(panGesture!)
|
|
|
|
|
|
nexilis_button = UIImageView()
|
|
|
nexilis_button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
nexilis_button.isUserInteractionEnabled = true
|
|
|
- if Utils.getIconDock() != nil {
|
|
|
- let dataImage = try? Data(contentsOf: URL(string: Utils.getUrlDock()!)!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
- if dataImage != nil {
|
|
|
- nexilis_button.image = UIImage(data: dataImage!)
|
|
|
+ if !Utils.getIconDock().isEmpty {
|
|
|
+ var dataImage: Data?
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ defaultWidthFB = widthFBAnim
|
|
|
+ defaultHeightFB = heightFBAnim
|
|
|
+ nexilis_button.sd_setImage(with: URL(string: Utils.getIconCenterAnim()!)) { [self] (image, error, cacheType, imageURL) in
|
|
|
+ if let error = error {
|
|
|
+ //print("Error loading GIF: \(error.localizedDescription)")
|
|
|
+ } else {
|
|
|
+ // Configure the animation
|
|
|
+ nexilis_button.animationImages = image?.images
|
|
|
+ nexilis_button.animationDuration = image?.duration ?? 0.0
|
|
|
+ nexilis_button.animationRepeatCount = 0
|
|
|
+ nexilis_button.startAnimating()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dataImage = try? Data(contentsOf: URL(string: Utils.getUrlDock()!)!)
|
|
|
+ if dataImage != nil {
|
|
|
+ nexilis_button.image = UIImage(data: dataImage!)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
nexilis_button.image = UIImage(named: "pb_button", in: Bundle.resourceBundle(for: DigiX.self), with: nil)
|
|
|
}
|
|
|
|
|
|
+ backgroundColor = .clear
|
|
|
+ frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: defaultWidthFB, height: defaultHeightFB)
|
|
|
+
|
|
|
let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
|
|
|
qmeraTap.numberOfTouchesRequired = 1
|
|
|
nexilis_button.addGestureRecognizer(qmeraTap)
|
|
@@ -78,24 +108,30 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
addSubview(nexilis_button)
|
|
|
|
|
|
- nexilis_button.widthAnchor.constraint(equalToConstant: 50.0).isActive = true
|
|
|
- nexilis_button.heightAnchor.constraint(equalToConstant: 50.0).isActive = true
|
|
|
- nexilis_button.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ nexilis_button.widthAnchor.constraint(equalToConstant: defaultWidthFB).isActive = true
|
|
|
+ nexilis_button.heightAnchor.constraint(equalToConstant: defaultHeightFB).isActive = true
|
|
|
+ nexilis_button.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
|
|
|
nexilis_button.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
|
|
|
|
scrollView = UIScrollView()
|
|
|
scrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- scrollView.layer.borderWidth = 1.0
|
|
|
- scrollView.layer.borderColor = UIColor.white.cgColor
|
|
|
- scrollView.layer.cornerRadius = 8.0
|
|
|
- scrollView.layer.masksToBounds = true
|
|
|
- scrollView.backgroundColor = .black.withAlphaComponent(0.25)
|
|
|
+// scrollView.layer.borderWidth = 1.0
|
|
|
+// scrollView.layer.borderColor = UIColor.white.cgColor
|
|
|
+// scrollView.layer.cornerRadius = 8.0
|
|
|
+// scrollView.layer.masksToBounds = true
|
|
|
+// scrollView.backgroundColor = .black.withAlphaComponent(0.25)
|
|
|
addSubview(scrollView)
|
|
|
|
|
|
- scrollView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true
|
|
|
- scrollView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ scrollView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB + 10).isActive = true
|
|
|
scrollView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
|
|
- scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ scrollView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
|
+ scrollView.leftAnchor.constraint(equalTo: nexilis_button.rightAnchor, constant: -20).isActive = true
|
|
|
+ scrollView.isHidden = true
|
|
|
+ } else {
|
|
|
+ scrollView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
|
|
|
+ }
|
|
|
|
|
|
groupView = UIStackView()
|
|
|
groupView.translatesAutoresizingMaskIntoConstraints = false
|
|
@@ -104,7 +140,7 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
scrollView.addSubview(groupView)
|
|
|
|
|
|
- groupView.widthAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ groupView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
groupView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 5).isActive = true
|
|
|
groupView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: -5).isActive = true
|
|
|
groupView.leftAnchor.constraint(equalTo: scrollView.leftAnchor, constant: 6).isActive = true
|
|
@@ -134,6 +170,38 @@ public class FloatingButton: UIView {
|
|
|
return
|
|
|
}
|
|
|
DispatchQueue.global().async { [self] in
|
|
|
+ if !Utils.getCustomButtons().isEmpty {
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
+ let customButtons = Utils.getCustomButtons().components(separatedBy: ",")
|
|
|
+ let customIcons = Utils.getCustomFBIcon().components(separatedBy: ",")
|
|
|
+ countMenuFB = CGFloat(customButtons.count > 5 ? 5 : customButtons.count)
|
|
|
+ for i in 0..<customButtons.count {
|
|
|
+ let package_id = customButtons[i]
|
|
|
+ let app_id = ""
|
|
|
+ let icon = customIcons[i]
|
|
|
+ let newButton = UIButton()
|
|
|
+ newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
+ newButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ let data = try? Data(contentsOf: URL(string: "https://DigiX.io/dashboardv2/uploads/fb_icon/\(icon)")!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ if data != nil {
|
|
|
+ newButton.setImage(UIImage(data: data!), for: .normal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ groupView.addArrangedSubview(newButton)
|
|
|
+ newButton.restorationIdentifier = package_id
|
|
|
+ newButton.accessibilityIdentifier = app_id
|
|
|
+ newButton.addTarget(self, action: #selector(fbTap), for: .touchUpOutside)
|
|
|
+ }
|
|
|
+ let countSubviewsAfter = groupView.subviews.count
|
|
|
+ if countSubviewsAfter <= 4 {
|
|
|
+ scrollView.isScrollEnabled = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
if let response = DigiX.writeSync(message: CoreMessage_TMessageBank.pullFloatingButton(), timeout: 30 * 1000){
|
|
|
if response.isOk() {
|
|
|
let data = response.getBody(key: CoreMessage_TMessageKey.DATA, default_value: "")
|
|
@@ -142,14 +210,16 @@ public class FloatingButton: UIView {
|
|
|
DispatchQueue.main.async { [self] in
|
|
|
groupView.subviews.forEach({ $0.removeFromSuperview() })
|
|
|
if jsonArray.count == 0 {
|
|
|
+ countMenuFB = CGFloat(4)
|
|
|
getDefaultButton()
|
|
|
} else {
|
|
|
+ countMenuFB = CGFloat(jsonArray.count > 5 ? 5 : jsonArray.count)
|
|
|
for json in jsonArray {
|
|
|
let package_id = json["package_id"] as! String
|
|
|
let app_id = (json["app_id"] as? String) ?? ""
|
|
|
let icon = (json["icon"] as? String) ?? ""
|
|
|
let newButton = UIButton()
|
|
|
- newButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
newButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
if icon.isEmpty {
|
|
|
var indexTap = 0
|
|
@@ -211,14 +281,14 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
func getDefaultButton() {
|
|
|
button_fb1 = UIButton()
|
|
|
- button_fb1.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb1.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb1.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb1.setImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: DigiX.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb1)
|
|
|
button_fb1.addTarget(self, action: #selector(fb1Tap), for: .touchUpOutside)
|
|
|
|
|
|
button_fb2 = UIButton()
|
|
|
- button_fb2.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb2.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb2.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb2.setImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: DigiX.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb2)
|
|
@@ -226,14 +296,14 @@ public class FloatingButton: UIView {
|
|
|
checkCounter()
|
|
|
|
|
|
button_fb3 = UIButton()
|
|
|
- button_fb3.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb3.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb3.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb3.setImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: DigiX.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb3)
|
|
|
button_fb3.addTarget(self, action: #selector(fb3Tap), for: .touchUpOutside)
|
|
|
|
|
|
button_fb4 = UIButton()
|
|
|
- button_fb4.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb4.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb4.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb4.setImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: DigiX.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb4)
|
|
@@ -245,7 +315,7 @@ public class FloatingButton: UIView {
|
|
|
let widthScreen = size.width
|
|
|
let heightScreen = size.height
|
|
|
let minimumx = (widthScreen + 30) - widthScreen
|
|
|
- let maximumx = widthScreen - 30
|
|
|
+ var maximumx = widthScreen - 30
|
|
|
let translation = sender.translation(in: self)
|
|
|
var xPos = center.x + translation.x
|
|
|
var yPos = center.y + translation.y
|
|
@@ -257,8 +327,14 @@ public class FloatingButton: UIView {
|
|
|
xPos = maximumx
|
|
|
}
|
|
|
if(isShow) {
|
|
|
- let minimumy = CGFloat(120.5) //30
|
|
|
- let maximumy = heightScreen - 100
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ maximumx = widthScreen - 10 - defaultWidthHeightMenuFB
|
|
|
+ if (xPos > maximumx) {
|
|
|
+ xPos = maximumx
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let minimumy = (defaultWidthHeightMenuFB * countMenuFB) - defaultHeightFB - 10
|
|
|
+ let maximumy = heightScreen - defaultHeightFB - 10
|
|
|
if(yPos < minimumy) {
|
|
|
yPos = minimumy
|
|
|
}
|
|
@@ -266,8 +342,8 @@ public class FloatingButton: UIView {
|
|
|
yPos = maximumy
|
|
|
}
|
|
|
} else {
|
|
|
- let minimumy = (heightScreen + 50) - heightScreen
|
|
|
- let maximumy = heightScreen - 20
|
|
|
+ let minimumy = defaultHeightFB - 50
|
|
|
+ let maximumy = heightScreen - defaultHeightFB + 50
|
|
|
if(yPos < minimumy) {
|
|
|
yPos = minimumy
|
|
|
}
|
|
@@ -402,7 +478,7 @@ public class FloatingButton: UIView {
|
|
|
if self.frame.origin.x < UIScreen.main.bounds.width / 2 - 30 {
|
|
|
self.frame.origin.x = 0
|
|
|
} else {
|
|
|
- self.frame.origin.x = UIScreen.main.bounds.width - 50
|
|
|
+ self.frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -413,13 +489,23 @@ public class FloatingButton: UIView {
|
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
indicatorCounterFBBig.isHidden = true
|
|
|
}
|
|
|
- let height = CGFloat(217) //40
|
|
|
- var yPosition = frame.origin.y - height + 50
|
|
|
+ var height = CGFloat((defaultWidthHeightMenuFB * countMenuFB) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
|
|
|
+ var width = frame.width
|
|
|
+ var xPosition = frame.origin.x
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ height = CGFloat((defaultWidthHeightMenuFB * (countMenuFB - 2)) + defaultHeightFB - 5)
|
|
|
+ width = frame.width + defaultWidthHeightMenuFB
|
|
|
+ if xPosition > UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB {
|
|
|
+ xPosition = UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB
|
|
|
+ }
|
|
|
+ scrollView.isHidden = false
|
|
|
+ }
|
|
|
+ var yPosition = frame.origin.y - height + defaultHeightFB
|
|
|
if yPosition <= 25 {
|
|
|
lastPosY = frame.origin.y
|
|
|
yPosition = 25
|
|
|
}
|
|
|
- frame = CGRect(x: frame.origin.x, y: yPosition, width: frame.width, height: height)
|
|
|
+ frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in
|
|
|
if isShow {
|
|
|
let countSubviewsAfter = groupView.subviews.count
|
|
@@ -432,12 +518,16 @@ public class FloatingButton: UIView {
|
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
indicatorCounterFBBig.isHidden = false
|
|
|
}
|
|
|
- let height = CGFloat(217) //40
|
|
|
- var yPosition = frame.origin.y + height - 50
|
|
|
+ var height = CGFloat((defaultWidthHeightMenuFB * countMenuFB) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ height = CGFloat((defaultWidthHeightMenuFB * 3) + defaultHeightFB - 5)
|
|
|
+ scrollView.isHidden = true
|
|
|
+ }
|
|
|
+ var yPosition = frame.origin.y + height - defaultHeightFB
|
|
|
if lastPosY != nil {
|
|
|
yPosition = lastPosY!
|
|
|
}
|
|
|
- frame = CGRect(x: frame.origin.x, y: yPosition, width: frame.width, height: frame.width)
|
|
|
+ frame = CGRect(x: frame.origin.x, y: yPosition, width: defaultWidthFB, height: defaultHeightFB)
|
|
|
}
|
|
|
}
|
|
|
}
|