FloatingButton.swift 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. //
  2. // FloatingButton.swift
  3. // Qmera
  4. //
  5. // Created by Yayan Dwi on 03/09/21.
  6. //
  7. import UIKit
  8. import nuSDKService
  9. import NotificationBannerSwift
  10. public class FloatingButton: UIView {
  11. var groupView: UIStackView!
  12. var scrollView: UIScrollView!
  13. var imageScrollView: UIImageView!
  14. var button_fb1: UIButton!
  15. var button_fb2: UIButton!
  16. var button_fb3: UIButton!
  17. var button_fb4: UIButton!
  18. var nexilis_button: UIImageView!
  19. var nexilis_pin: UIImageView!
  20. var leadingConstraintPin: NSLayoutConstraint!
  21. var bottomConstraintPin: NSLayoutConstraint!
  22. var trailingConstraintPin: NSLayoutConstraint!
  23. var topConstraintPin: NSLayoutConstraint!
  24. var lastPosY: CGFloat?
  25. var lastImageButton = ""
  26. var iconCC = ""
  27. let indicatorCounterFB = UIView()
  28. let labelCounterFB = UILabel()
  29. let indicatorCounterFBBig = UIImageView()
  30. var datePull: Date?
  31. var animationTimer = Timer()
  32. var configAnim: Int = Int(Utils.getFloatingAnim().components(separatedBy: "~")[0]) ?? 1
  33. var isLoopingAnim = (Int(Utils.getFloatingAnim().components(separatedBy: "~")[1]) ?? 1) == 1 ? true : false
  34. var lastRunAnimationHrz = -1
  35. var lastRunAnimationVrt = -1
  36. var panGesture: UIPanGestureRecognizer?
  37. var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
  38. var defaultHeightFB = (UIScreen.main.bounds.height * 0.5) / 7.5
  39. let defaultWidthHeightMenuFB = (UIScreen.main.bounds.height * 0.45) / 7.5
  40. let widthFBAnim = (UIScreen.main.bounds.height * 0.8) / 7.5
  41. let heightFBAnim = (UIScreen.main.bounds.height * 1) / 7.5
  42. let heightFBSideTab = (UIScreen.main.bounds.height * 1.05) / 7.5
  43. let widthFBSideTab: CGFloat = 18
  44. let widthVerticalSideTab: CGFloat = 50
  45. let heightVerticalSideTab: CGFloat = 220
  46. final let MODE_VERTICAL_FLOATING_BUTTON = "1"
  47. final let MODE_VERTICAL_ANIMATION = "2"
  48. final let MODE_HORIZONTAL_ANIMATION = "3"
  49. final let MODE_HORIZONTAL_SIDE_TAB = "4"
  50. final let MODE_VERTICAL_SIDE_TAB = "5"
  51. var countMenuFB: CGFloat = 6 {
  52. didSet {
  53. if isShow {
  54. show(isShow: isShow)
  55. }
  56. }
  57. }
  58. public weak var mySettingDelegate: SettingMABDelegate?
  59. public var isShow: Bool = false
  60. override init(frame: CGRect) {
  61. super.init(frame: frame)
  62. commonInit()
  63. }
  64. required init?(coder: NSCoder) {
  65. super.init(coder: coder)
  66. commonInit()
  67. }
  68. private func commonInit() {
  69. panGesture = UIPanGestureRecognizer(target: self, action: #selector(draggedView(_:)))
  70. addGestureRecognizer(panGesture!)
  71. nexilis_button = UIImageView()
  72. nexilis_button.translatesAutoresizingMaskIntoConstraints = false
  73. nexilis_button.isUserInteractionEnabled = true
  74. var dataImage: Data?
  75. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  76. defaultWidthFB = widthFBAnim
  77. if Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  78. defaultHeightFB = heightFBAnim + 30
  79. } else {
  80. defaultHeightFB = heightFBAnim
  81. }
  82. var urlGif = URL(string: Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION ? Utils.getIconCenterAnim2() : Utils.getIconCenterAnim4())
  83. if (urlGif == nil) {
  84. urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION ? "pb_def_icon_mode2" : "pb_def_icon_mode4", withExtension: "gif")! //resourcesMediaBundle
  85. }
  86. nexilis_button.sd_setImage(with: urlGif) { [self] (image, error, cacheType, imageURL) in
  87. if error == nil {
  88. nexilis_button.animationImages = image?.images
  89. nexilis_button.animationDuration = image?.duration ?? 0.0
  90. nexilis_button.animationRepeatCount = 0
  91. nexilis_button.startAnimating()
  92. }
  93. }
  94. } else {
  95. if !Utils.getIconDock().isEmpty && Utils.getConfigModeFB() == MODE_VERTICAL_FLOATING_BUTTON {
  96. dataImage = try? Data(contentsOf: URL(string: Utils.getUrlDock()!)!)
  97. if dataImage != nil {
  98. if let image = UIImage(data: dataImage!) {
  99. nexilis_button.image = image
  100. } else {
  101. nexilis_button.image = UIImage(named: Utils.getFBIconBg() == "1" ? "pb_button" : "pb_ball", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
  102. }
  103. } else {
  104. nexilis_button.image = UIImage(named: Utils.getFBIconBg() == "1" ? "pb_button" : "pb_ball", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
  105. }
  106. } else {
  107. if Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB || Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  108. defaultWidthFB = widthFBSideTab
  109. defaultHeightFB = heightFBSideTab
  110. }
  111. nexilis_button.image = UIImage(named: Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB ? "pb_side_tab_vtc" : Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? "pb_side_tab" : "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
  112. }
  113. }
  114. backgroundColor = .clear
  115. frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB ? 50 + defaultWidthFB : Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? UIScreen.main.bounds.width - defaultWidthFB : defaultWidthFB, height: Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB ? heightVerticalSideTab : defaultHeightFB)
  116. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  117. if configAnim == 0 { //left to right
  118. lastRunAnimationHrz = 1
  119. } else if configAnim == 1 { //right to left
  120. lastRunAnimationHrz = -1
  121. } else if configAnim == 2 { //top to bottom
  122. lastRunAnimationVrt = 1
  123. } else if configAnim == 3 { //top to bottom
  124. lastRunAnimationVrt = -1
  125. }
  126. if configAnim >= 0 && configAnim <= 3 {
  127. checkDelayAnimation()
  128. }
  129. }
  130. let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
  131. qmeraTap.numberOfTouchesRequired = 1
  132. nexilis_button.addGestureRecognizer(qmeraTap)
  133. let qmeraLongPress = UILongPressGestureRecognizer(target: self, action: #selector(qmeraLongPress(gestureRecognizer:)))
  134. nexilis_button.addGestureRecognizer(qmeraLongPress)
  135. addSubview(nexilis_button)
  136. nexilis_button.widthAnchor.constraint(equalToConstant: defaultWidthFB).isActive = true
  137. nexilis_button.heightAnchor.constraint(equalToConstant: defaultHeightFB).isActive = true
  138. nexilis_button.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
  139. if Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  140. nexilis_button.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
  141. } else {
  142. nexilis_button.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
  143. }
  144. scrollView = UIScrollView()
  145. scrollView.translatesAutoresizingMaskIntoConstraints = false
  146. if Utils.getFBItemBg() == "1" && Utils.getConfigModeFB() == MODE_VERTICAL_FLOATING_BUTTON {
  147. scrollView.layer.borderWidth = 1.0
  148. scrollView.layer.borderColor = UIColor.white.cgColor
  149. scrollView.layer.cornerRadius = 8.0
  150. scrollView.layer.masksToBounds = true
  151. scrollView.backgroundColor = .black.withAlphaComponent(0.25)
  152. }
  153. addSubview(scrollView)
  154. if Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  155. let bgImage = resizeImage(image: UIImage(named: "pb_button_background_vtcst", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: widthVerticalSideTab, height: heightVerticalSideTab))
  156. scrollView.backgroundColor = UIColor.init(patternImage: bgImage)
  157. scrollView.leftAnchor.constraint(equalTo: nexilis_button.rightAnchor).isActive = true
  158. scrollView.centerYAnchor.constraint(equalTo: nexilis_button.centerYAnchor).isActive = true
  159. scrollView.widthAnchor.constraint(equalToConstant: widthVerticalSideTab).isActive = true
  160. scrollView.heightAnchor.constraint(equalToConstant: heightVerticalSideTab).isActive = true
  161. } else if Utils.getConfigModeFB() != MODE_HORIZONTAL_SIDE_TAB {
  162. scrollView.topAnchor.constraint(equalTo: topAnchor).isActive = true
  163. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION {
  164. scrollView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
  165. scrollView.leftAnchor.constraint(equalTo: nexilis_button.rightAnchor, constant: -20).isActive = true
  166. scrollView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB + 10).isActive = true
  167. scrollView.isHidden = true
  168. } else if Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  169. scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
  170. scrollView.leftAnchor.constraint(equalTo: nexilis_button.leftAnchor).isActive = true
  171. scrollView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB * (countMenuFB - 1)).isActive = true
  172. } else {
  173. scrollView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB + 10).isActive = true
  174. scrollView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
  175. scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
  176. }
  177. } else {
  178. scrollView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width - defaultWidthFB).isActive = true
  179. scrollView.heightAnchor.constraint(equalToConstant: defaultHeightFB).isActive = true
  180. scrollView.leftAnchor.constraint(equalTo: nexilis_button.rightAnchor).isActive = true
  181. scrollView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
  182. scrollView.backgroundColor = .black.withAlphaComponent(0.25)
  183. }
  184. groupView = UIStackView()
  185. groupView.translatesAutoresizingMaskIntoConstraints = false
  186. groupView.axis = (Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION) ? .horizontal : .vertical
  187. if Utils.getConfigModeFB() != MODE_HORIZONTAL_SIDE_TAB && Utils.getConfigModeFB() != MODE_HORIZONTAL_ANIMATION {
  188. groupView.distribution = .fillEqually
  189. }
  190. scrollView.addSubview(groupView)
  191. if Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  192. groupView.spacing = 10.0
  193. groupView.centerYAnchor.constraint(equalTo: scrollView.centerYAnchor).isActive = true
  194. groupView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor).isActive = true
  195. groupView.heightAnchor.constraint(equalToConstant: heightVerticalSideTab - 20).isActive = true
  196. groupView.widthAnchor.constraint(equalToConstant: 30).isActive = true
  197. } else if Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB {
  198. groupView.leftAnchor.constraint(equalTo: scrollView.leftAnchor).isActive = true
  199. groupView.rightAnchor.constraint(equalTo: scrollView.rightAnchor).isActive = true
  200. groupView.centerYAnchor.constraint(equalTo: scrollView.centerYAnchor).isActive = true
  201. groupView.heightAnchor.constraint(equalToConstant: defaultHeightFB - 10).isActive = true
  202. } else {
  203. groupView.widthAnchor.constraint(equalToConstant: Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? defaultWidthHeightMenuFB * (countMenuFB - 1) : defaultWidthHeightMenuFB).isActive = true
  204. groupView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? 0 : 5).isActive = true
  205. groupView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? 0 : -5).isActive = true
  206. groupView.leftAnchor.constraint(equalTo: scrollView.leftAnchor, constant: Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? 0 : 6).isActive = true
  207. }
  208. pullButton()
  209. let center: NotificationCenter = NotificationCenter.default
  210. center.addObserver(self, selector: #selector(imageFBUpdate(notification:)), name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil)
  211. center.addObserver(self, selector: #selector(checkCounter), name: NSNotification.Name(rawValue: Nexilis.listenerReceiveChat), object: nil)
  212. center.addObserver(self, selector: #selector(checkCounter), name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil)
  213. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(hideButton))
  214. tapGesture.cancelsTouchesInView = false
  215. UIApplication.shared.windows.first?.rootViewController?.view.addGestureRecognizer(tapGesture)
  216. }
  217. private func checkDelayAnimation() {
  218. DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
  219. if !isShow {
  220. animationTimer.invalidate()
  221. animationTimer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(runAnimation), userInfo: nil, repeats: true)
  222. }
  223. })
  224. }
  225. @objc func runAnimation(){
  226. DispatchQueue.main.async { [self] in
  227. if configAnim == 0 || configAnim == 1 {
  228. if (lastRunAnimationHrz == -1 && frame.origin.x >= 0) || lastRunAnimationHrz == 1 && frame.origin.x <= UIScreen.main.bounds.width - defaultWidthFB {
  229. if lastRunAnimationHrz == -1 {
  230. frame.origin.x-=0.1
  231. } else {
  232. frame.origin.x+=0.1
  233. }
  234. } else {
  235. lastRunAnimationHrz = lastRunAnimationHrz == 1 ? -1 : 1
  236. if (lastRunAnimationHrz == -1 && configAnim == 1) || (lastRunAnimationHrz == 1 && configAnim == 0) {
  237. animationTimer.invalidate()
  238. if isLoopingAnim {
  239. checkDelayAnimation()
  240. }
  241. }
  242. }
  243. } else {
  244. if (lastRunAnimationVrt == -1 && frame.origin.y >= 0) || lastRunAnimationVrt == 1 && frame.origin.y <= UIScreen.main.bounds.height - defaultHeightFB {
  245. if lastRunAnimationVrt == -1 {
  246. frame.origin.y-=0.1
  247. } else {
  248. frame.origin.y+=0.1
  249. }
  250. } else {
  251. lastRunAnimationVrt = lastRunAnimationVrt == 1 ? -1 : 1
  252. if (lastRunAnimationVrt == -1 && configAnim == 3) || (lastRunAnimationVrt == 1 && configAnim == 2) {
  253. animationTimer.invalidate()
  254. if isLoopingAnim {
  255. checkDelayAnimation()
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. private func pullButton() {
  263. if datePull == nil || Int(Date().timeIntervalSince(datePull!)) >= 60 {
  264. datePull = Date()
  265. } else if Int(Date().timeIntervalSince(datePull!)) < 60 {
  266. return
  267. }
  268. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  269. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  270. imageView.tintColor = .white
  271. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  272. banner.show()
  273. return
  274. }
  275. if groupView.subviews.count == 0 {
  276. getDefaultButton()
  277. }
  278. DispatchQueue.global().async { [self] in
  279. if !Utils.getCustomButtons().isEmpty && Utils.getConfigModeFB() != MODE_HORIZONTAL_SIDE_TAB && Utils.getConfigModeFB() != MODE_HORIZONTAL_ANIMATION && Utils.getConfigModeFB() != MODE_VERTICAL_SIDE_TAB {
  280. DispatchQueue.main.async { [self] in
  281. groupView.subviews.forEach({ $0.removeFromSuperview() })
  282. let customButtons = Utils.getCustomButtons().components(separatedBy: ",")
  283. let customIcons = Utils.getCustomFBIcon().components(separatedBy: ",")
  284. countMenuFB = CGFloat(customButtons.count > 5 ? 5 : customButtons.count)
  285. for i in 0..<customButtons.count {
  286. let package_id = customButtons[i]
  287. let app_id = ""
  288. let icon = customIcons[i]
  289. let newButton = UIButton()
  290. newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  291. newButton.translatesAutoresizingMaskIntoConstraints = false
  292. DispatchQueue.global().async {[self] in
  293. getDataImageFromUrl(from: URL(string: Utils.getURLBase() + "get_file_from_path?img=" + icon)!) { data, response, error in
  294. guard let data = data, error == nil else { return }
  295. DispatchQueue.main.async {
  296. if let image = UIImage(data: data) {
  297. newButton.setImage(image, for: .normal)
  298. }
  299. }
  300. }
  301. }
  302. groupView.addArrangedSubview(newButton)
  303. newButton.restorationIdentifier = package_id
  304. newButton.accessibilityIdentifier = app_id
  305. newButton.addTarget(self, action: #selector(fbTap), for: .touchUpInside)
  306. }
  307. }
  308. return
  309. }
  310. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.pullFloatingButton(), timeout: 30 * 1000){
  311. if response.isOk() {
  312. let data = response.getBody(key: CoreMessage_TMessageKey.DATA, default_value: "")
  313. if !data.isEmpty {
  314. if let jsonArray = try! JSONSerialization.jsonObject(with: data.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
  315. DispatchQueue.main.async { [self] in
  316. let filteredData = jsonArray.filter({ $0["mode"] as? Int == Int(Utils.getConfigModeFB()) })
  317. if filteredData.count != 0 {
  318. groupView.subviews.forEach({ $0.removeFromSuperview() })
  319. countMenuFB = CGFloat(filteredData.count > 5 ? 5 : filteredData.count)
  320. for json in filteredData {
  321. let package_id = json["package_id"] as! String
  322. let app_id = (json["app_id"] as? String) ?? ""
  323. let icon = (json["icon"] as? String) ?? ""
  324. let mode = "\((json["mode"] as? Int) ?? 1)"
  325. let newButton = UIButton()
  326. if mode != Utils.getConfigModeFB() {
  327. continue
  328. }
  329. if mode == MODE_HORIZONTAL_SIDE_TAB {
  330. newButton.widthAnchor.constraint(equalToConstant: defaultHeightFB - 10).isActive = true
  331. newButton.heightAnchor.constraint(equalToConstant: defaultHeightFB - 10).isActive = true
  332. } else if mode == MODE_HORIZONTAL_ANIMATION {
  333. newButton.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  334. newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  335. } else if mode == MODE_VERTICAL_SIDE_TAB {
  336. newButton.imageView?.contentMode = .scaleAspectFit
  337. } else {
  338. newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  339. }
  340. newButton.translatesAutoresizingMaskIntoConstraints = false
  341. var indexTap = 0
  342. if package_id.contains("_fb"){
  343. let listSplit = package_id.split(separator: "_", maxSplits: 1)
  344. let numIdx = listSplit[listSplit.firstIndex(where: { $0.contains("fb") }) ?? 0]
  345. indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count))!
  346. }
  347. if indexTap == Nexilis.IDX_CHAT {
  348. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_chat" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_chat" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_chat" : "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  349. } else if indexTap == Nexilis.IDX_CONVERSATION {
  350. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_chat" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_conversation" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_conversation" : "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  351. } else if indexTap == Nexilis.IDX_CALL {
  352. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_call" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_call" : "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  353. } else if indexTap == Nexilis.IDX_CC {
  354. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_cc" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_cc" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_cc" : "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  355. } else if indexTap == Nexilis.IDX_STREAM {
  356. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_stream" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_stream" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_stream" : "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  357. } else if indexTap == Nexilis.IDX_SOCIAL_COMMERCE {
  358. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_commerce" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_social_commerce" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_commerce" : "pb_button_commerce", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  359. } else if indexTap == Nexilis.IDX_NEWS {
  360. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_news" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_news" : "pb_button_news", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  361. } else if indexTap == Nexilis.IDX_POST {
  362. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_post" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_post" : "pb_button_post", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  363. } else if indexTap == Nexilis.IDX_NOTIF_CENTER {
  364. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_notif_center" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_notif_center" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_notif_center" : "pb_button_notification", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  365. } else {
  366. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_more" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_more" : "pb_button_others", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  367. }
  368. if !icon.isEmpty {
  369. DispatchQueue.global().async { [self] in
  370. getDataImageFromUrl(from: URL(string: Utils.getURLBase() + "get_file_from_path?img=" + icon)!) { data, response, error in
  371. guard let data = data, error == nil else { return }
  372. DispatchQueue.main.async {
  373. newButton.setImage(UIImage(data: data), for: .normal)
  374. }
  375. }
  376. }
  377. }
  378. groupView.addArrangedSubview(newButton)
  379. newButton.restorationIdentifier = package_id
  380. newButton.accessibilityIdentifier = app_id
  381. newButton.addTarget(self, action: #selector(fbTap), for: .touchUpInside)
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. private func getDataImageFromUrl(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
  392. let urlConfig = URLSessionConfiguration.default
  393. let sessionDelegate = SelfSignedURLSessionDelegate()
  394. let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
  395. session.dataTask(with: url, completionHandler: completion).resume()
  396. }
  397. func getDefaultButton() {
  398. let mode = Utils.getConfigModeFB()
  399. var data = [Nexilis.IDX_NOTIF_CENTER, Nexilis.IDX_CC, Nexilis.IDX_CONVERSATION, Nexilis.IDX_CALL, Nexilis.IDX_STREAM]
  400. if mode == MODE_VERTICAL_SIDE_TAB {
  401. data = [Nexilis.IDX_NOTIF_CENTER, Nexilis.IDX_CC, Nexilis.IDX_CONVERSATION, Nexilis.IDX_STREAM, Nexilis.IDX_SOCIAL_COMMERCE]
  402. } else if mode == MODE_HORIZONTAL_ANIMATION {
  403. data = [Nexilis.IDX_NOTIF_CENTER, Nexilis.IDX_CC, Nexilis.IDX_CONVERSATION, Nexilis.IDX_SOCIAL_COMMERCE, Nexilis.IDX_STREAM]
  404. }
  405. for i in 0..<data.count {
  406. let newButton = UIButton()
  407. if mode == MODE_HORIZONTAL_SIDE_TAB {
  408. newButton.widthAnchor.constraint(equalToConstant: defaultHeightFB - 10).isActive = true
  409. newButton.heightAnchor.constraint(equalToConstant: defaultHeightFB - 10).isActive = true
  410. } else if mode == MODE_HORIZONTAL_ANIMATION {
  411. newButton.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  412. newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  413. } else if mode == MODE_VERTICAL_SIDE_TAB {
  414. newButton.imageView?.contentMode = .scaleAspectFit
  415. } else {
  416. newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
  417. }
  418. newButton.translatesAutoresizingMaskIntoConstraints = false
  419. let indexTap = data[i]
  420. if indexTap == Nexilis.IDX_CHAT {
  421. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_chat" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_chat" : "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  422. } else if indexTap == Nexilis.IDX_CONVERSATION {
  423. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_chat" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_conversation" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_conversation" : "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  424. } else if indexTap == Nexilis.IDX_CALL {
  425. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_call" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_call" : "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  426. } else if indexTap == Nexilis.IDX_CC {
  427. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_cc" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_cc" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_cc" : "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  428. } else if indexTap == Nexilis.IDX_STREAM {
  429. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_stream" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_stream" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_stream" : "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  430. } else if indexTap == Nexilis.IDX_SOCIAL_COMMERCE {
  431. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_commerce" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_social_commerce" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_commerce" : "pb_button_commerce", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  432. } else if indexTap == Nexilis.IDX_NEWS {
  433. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_news" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_news" : "pb_button_news", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  434. } else if indexTap == Nexilis.IDX_POST {
  435. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_post" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_post" : "pb_button_post", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  436. } else if indexTap == Nexilis.IDX_NOTIF_CENTER {
  437. newButton.setImage(UIImage(named: mode == MODE_VERTICAL_SIDE_TAB ? "pb_button_vtcst_notif_center" : mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_notif_center" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_notif_center" : "pb_button_notification", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  438. if mode == MODE_VERTICAL_SIDE_TAB {
  439. newButton.imageView?.contentMode = .scaleAspectFit
  440. }
  441. } else {
  442. newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_more" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_more" : "pb_button_others", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  443. }
  444. groupView.addArrangedSubview(newButton)
  445. newButton.restorationIdentifier = "default_fb\(data[i])"
  446. newButton.accessibilityIdentifier = ""
  447. newButton.addTarget(self, action: #selector(fbTap), for: .touchUpInside)
  448. }
  449. }
  450. @objc func draggedView(_ sender:UIPanGestureRecognizer){
  451. let size = UIScreen.main.bounds
  452. let widthScreen = size.width
  453. let heightScreen = size.height
  454. let minimumx: CGFloat = Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION && isShow ? widthFBAnim + defaultWidthHeightMenuFB : Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION && isShow ? 60 : 40
  455. let maximumx = Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION && isShow ? widthScreen - widthFBAnim - defaultWidthHeightMenuFB : Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION && isShow ? widthScreen - 10 - defaultWidthHeightMenuFB : widthScreen - 40
  456. let maxMinXSideTab = isShow ? center.x : widthScreen + (center.x - widthScreen)
  457. let translation = sender.translation(in: self)
  458. var xPos = center.x + translation.x
  459. var yPos = center.y + translation.y
  460. bringSubviewToFront(self)
  461. if Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB || Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  462. xPos = maxMinXSideTab
  463. } else {
  464. if (xPos < minimumx) {
  465. xPos = minimumx
  466. }
  467. if (xPos > maximumx) {
  468. xPos = maximumx
  469. }
  470. }
  471. if(isShow) {
  472. let minimumy = Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB ? heightVerticalSideTab - 100 : Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? 50 : Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? defaultWidthHeightMenuFB * 2 + 10 : Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION ? defaultHeightFB + defaultWidthHeightMenuFB : defaultHeightFB * 3 + 20
  473. let maximumy = Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB ? heightScreen - (heightVerticalSideTab - 100) : Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? heightScreen - 50 : Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION ? heightScreen - defaultWidthHeightMenuFB - 30 : Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION ? heightScreen - defaultHeightFB - 30 : heightScreen - defaultHeightFB * 3 - 20
  474. if(yPos < minimumy) {
  475. yPos = minimumy
  476. }
  477. if(yPos > maximumy) {
  478. yPos = maximumy
  479. }
  480. } else {
  481. let minimumy: CGFloat = 50
  482. let maximumy = heightScreen - 50
  483. if(yPos < minimumy) {
  484. yPos = minimumy
  485. }
  486. if(yPos > maximumy) {
  487. yPos = maximumy
  488. }
  489. }
  490. center = CGPoint(x: xPos, y: yPos)
  491. sender.setTranslation(CGPoint.zero, in: self)
  492. if lastPosY != nil {
  493. lastPosY = nil
  494. }
  495. UserDefaults.standard.set(center.x, forKey: "xlastPosFB")
  496. UserDefaults.standard.set(center.y, forKey: "ylastPosFB")
  497. }
  498. @objc func imageFBUpdate(notification: NSNotification) {
  499. }
  500. @objc func checkCounter() {
  501. DispatchQueue.global().async { [self] in
  502. let counter = queryCountCounter()
  503. if counter > 0 {
  504. DispatchQueue.main.async { [self] in
  505. if button_fb2 != nil && !indicatorCounterFB.isDescendant(of: button_fb2) {
  506. button_fb2.addSubview(indicatorCounterFB)
  507. indicatorCounterFB.layer.cornerRadius = 7.5
  508. indicatorCounterFB.layer.masksToBounds = true
  509. indicatorCounterFB.backgroundColor = .systemRed
  510. indicatorCounterFB.anchor(top: button_fb2.topAnchor, left: button_fb2.leftAnchor, height: 15, minWidth: 15, maxWidth: 20)
  511. indicatorCounterFB.addSubview(labelCounterFB)
  512. labelCounterFB.anchor(left: indicatorCounterFB.leftAnchor, right: indicatorCounterFB.rightAnchor, paddingLeft: 5, paddingRight: 5, centerX: indicatorCounterFB.centerXAnchor, centerY: indicatorCounterFB.centerYAnchor)
  513. labelCounterFB.font = .systemFont(ofSize: 10)
  514. labelCounterFB.textColor = .white
  515. }
  516. if !indicatorCounterFBBig.isDescendant(of: nexilis_button){
  517. nexilis_button.addSubview(indicatorCounterFBBig)
  518. indicatorCounterFBBig.tintColor = .systemRed
  519. indicatorCounterFBBig.image = UIImage(systemName: "staroflife.circle.fill")
  520. indicatorCounterFBBig.anchor(top: nexilis_button.topAnchor, left: nexilis_button.leftAnchor, paddingTop: 5, paddingLeft: 5, width: 15, height: 15)
  521. }
  522. labelCounterFB.text = "\(counter)"
  523. }
  524. } else {
  525. DispatchQueue.main.async { [self] in
  526. if button_fb2 != nil && indicatorCounterFB.isDescendant(of: button_fb2) {
  527. indicatorCounterFB.removeFromSuperview()
  528. }
  529. if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
  530. indicatorCounterFBBig.removeFromSuperview()
  531. }
  532. }
  533. }
  534. }
  535. }
  536. private func queryCountCounter() -> Int32 {
  537. var counter: Int32?
  538. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  539. if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
  540. counter = cursor.int(forColumnIndex: 0)
  541. cursor.close()
  542. }
  543. })
  544. return counter ?? 0
  545. }
  546. @objc func qmeraTap() {
  547. show(isShow: !isShow)
  548. }
  549. @objc func fbTap(_ sender: UIButton) {
  550. let package_id = sender.restorationIdentifier!
  551. var app_id = sender.accessibilityIdentifier!
  552. var indexTap = 0
  553. if package_id.contains("_fb"){
  554. let listSplit = package_id.split(separator: "_", maxSplits: 1)
  555. let numIdx = listSplit[listSplit.firstIndex(where: { $0.contains("fb") }) ?? 0]
  556. indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count))!
  557. if listSplit.count == 2 {
  558. app_id = String(listSplit[1])
  559. }
  560. }
  561. Nexilis.buttonClicked(index: indexTap, id: app_id)
  562. hideButton()
  563. }
  564. @objc func qmeraLongPress(gestureRecognizer: UILongPressGestureRecognizer) {
  565. if gestureRecognizer.state == .began {
  566. if mySettingDelegate != nil {
  567. mySettingDelegate?.settingDelegate()
  568. } else {
  569. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
  570. Utils.addBackground(view: navigationController.view)
  571. navigationController.modalPresentationStyle = .fullScreen
  572. navigationController.navigationBar.tintColor = .white
  573. navigationController.navigationBar.barTintColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  574. navigationController.navigationBar.isTranslucent = false
  575. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  576. navigationController.navigationBar.barStyle = .black
  577. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  578. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  579. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  580. navigationController.navigationBar.titleTextAttributes = textAttributes
  581. UIApplication.shared.rootViewController?.present(navigationController, animated: true, completion: nil)
  582. }
  583. hideButton()
  584. }
  585. }
  586. @objc public func hideButton() {
  587. animationTimer.invalidate()
  588. if isShow {
  589. show(isShow: false)
  590. }
  591. if self.frame.origin.x < UIScreen.main.bounds.width / 2 - 30 {
  592. self.frame.origin.x = 0
  593. } else {
  594. self.frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
  595. }
  596. }
  597. public func show(isShow: Bool) {
  598. self.isShow = isShow
  599. if isShow {
  600. animationTimer.invalidate()
  601. pullButton()
  602. if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
  603. indicatorCounterFBBig.isHidden = true
  604. }
  605. var height = CGFloat((defaultWidthHeightMenuFB * countMenuFB) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
  606. var width = frame.width
  607. var xPosition = frame.origin.x
  608. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION {
  609. height = CGFloat((defaultWidthHeightMenuFB * (countMenuFB - 2)) + defaultHeightFB - 5)
  610. width = frame.width + defaultWidthHeightMenuFB
  611. if xPosition > UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB {
  612. xPosition = UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB
  613. }
  614. scrollView.isHidden = false
  615. } else if Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  616. height = defaultHeightFB + defaultWidthHeightMenuFB
  617. width = defaultWidthHeightMenuFB * (countMenuFB - 1)
  618. if xPosition > UIScreen.main.bounds.width - width {
  619. xPosition = UIScreen.main.bounds.width - width
  620. }
  621. }
  622. var yPosition = frame.origin.y - height + defaultHeightFB
  623. if yPosition <= 25 {
  624. lastPosY = frame.origin.y
  625. yPosition = 25
  626. }
  627. if Utils.getConfigModeFB() != MODE_HORIZONTAL_SIDE_TAB && Utils.getConfigModeFB() != MODE_VERTICAL_SIDE_TAB {
  628. frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
  629. } else {
  630. UIView.animate(withDuration: 0.5, animations: { [self] in
  631. var vst: CGFloat = 0.0
  632. if Utils.getConfigModeFB() == MODE_VERTICAL_SIDE_TAB {
  633. vst = UIScreen.main.bounds.width - defaultWidthFB - widthVerticalSideTab
  634. let size = UIScreen.main.bounds
  635. let heightScreen = size.height
  636. if frame.origin.y < 20 {
  637. frame.origin.y = 20
  638. } else if frame.origin.y > heightScreen - heightVerticalSideTab {
  639. frame.origin.y = heightScreen - heightVerticalSideTab
  640. }
  641. }
  642. frame.origin.x = 0 + vst
  643. })
  644. }
  645. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in
  646. if isShow {
  647. let countSubviewsAfter = groupView.subviews.count
  648. if countSubviewsAfter > 5 {
  649. scrollView.flashScrollIndicators()
  650. }
  651. }
  652. })
  653. } else {
  654. if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
  655. indicatorCounterFBBig.isHidden = false
  656. }
  657. var height = CGFloat((defaultWidthHeightMenuFB * countMenuFB) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
  658. var width = defaultWidthFB
  659. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION {
  660. height = CGFloat((defaultWidthHeightMenuFB * 3) + defaultHeightFB - 5)
  661. scrollView.isHidden = true
  662. } else if Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  663. height = defaultHeightFB + defaultWidthHeightMenuFB
  664. width = defaultWidthFB
  665. }
  666. var yPosition = frame.origin.y + height - defaultHeightFB
  667. if lastPosY != nil {
  668. yPosition = lastPosY!
  669. }
  670. if Utils.getConfigModeFB() != MODE_HORIZONTAL_SIDE_TAB && Utils.getConfigModeFB() != MODE_VERTICAL_SIDE_TAB {
  671. frame = CGRect(x: frame.origin.x, y: yPosition, width: width, height: defaultHeightFB)
  672. } else {
  673. UIView.animate(withDuration: 0.5, animations: { [self] in
  674. frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
  675. })
  676. }
  677. if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
  678. checkDelayAnimation()
  679. }
  680. }
  681. }
  682. }
  683. public protocol SettingMABDelegate: AnyObject {
  684. func settingDelegate()
  685. }