ViewController.swift 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. //
  2. // ViewController.swift
  3. // TestQmeraLite
  4. //
  5. // Created by Qindi on 29/11/21.
  6. //
  7. import UIKit
  8. import NexilisLite
  9. import AVKit
  10. import AVFoundation
  11. import SwiftUI
  12. import Speech
  13. import Alamofire
  14. import WebKit
  15. class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMABDelegate {
  16. let playerController = AVPlayerViewController()
  17. static var sURL = "https://www.google.com"
  18. static var tab3 = "0"
  19. public var isShow: Bool = false
  20. public static var chatButton = UIButton()
  21. public static var callButton = UIButton()
  22. public static var ccButton = UIButton()
  23. public static var streamingButton = UIButton()
  24. public static var postButton = UIButton()
  25. public static var middleButton = UIButton()
  26. var buttonChatGR : UITapGestureRecognizer?
  27. var buttonCallGR : UITapGestureRecognizer?
  28. var buttonCCGR : UITapGestureRecognizer?
  29. var buttonStreamGR : UITapGestureRecognizer?
  30. var floating : FloatingButton?
  31. var firstTab : FirstTabViewController?
  32. var secondTab : SecondTabViewController?
  33. var thirdTab : ThirdTabViewController?
  34. var fourthTab : FourthTabViewController?
  35. let emptyTab = EmptyTabViewController()
  36. public static var isTab1 = true
  37. public static var isTab2 = false
  38. public static var isTab3 = false
  39. public static var isTab4 = false
  40. public static var isExpandButton = false
  41. public static var alwaysHideButton = false
  42. static var listPullFB: [String] = []
  43. static var datePullFB: Date?
  44. let welcomeVC = UIViewController()
  45. var termVC: UIViewController?
  46. let welcomeDesc = UILabel()
  47. let termText = "Read our Terms of Service. Tap \"Agree and Continue\" to accept Terms of Service.".localized()
  48. let term = "Terms of Service.".localized()
  49. var firstLoad = true
  50. public static var def: ViewController?
  51. override func viewDidLoad() {
  52. super.viewDidLoad()
  53. ViewController.def = self
  54. title = Bundle.main.displayName
  55. let customTab = PrefsUtil.getCustomTab().split(separator: ",")
  56. let cpaasMode = PrefsUtil.getCpaasMode()
  57. var tabs : [UIViewController] = []
  58. firstTab = storyboard?.instantiateViewController(withIdentifier: "firstTabVC") as? FirstTabViewController
  59. secondTab = storyboard?.instantiateViewController(withIdentifier: "secondTabVC") as? SecondTabViewController
  60. thirdTab = storyboard?.instantiateViewController(withIdentifier: "thirdTabVC") as? ThirdTabViewController
  61. fourthTab = storyboard?.instantiateViewController(withIdentifier: "fourthTabVC") as? FourthTabViewController
  62. self.delegate = self
  63. firstTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_1_icon")!, targetSize: CGSize(width: 40, height: 40)).withRenderingMode(.alwaysOriginal)
  64. firstTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  65. secondTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_2_icon")!, targetSize: CGSize(width: 40, height: 40)).withRenderingMode(.alwaysOriginal)
  66. secondTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  67. thirdTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_3_icon")!, targetSize: CGSize(width: 40, height: 40)).withRenderingMode(.alwaysOriginal)
  68. thirdTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  69. fourthTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_4_icon")!, targetSize: CGSize(width: 40, height: 40)).withRenderingMode(.alwaysOriginal)
  70. fourthTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  71. var i = 0
  72. var j = 0
  73. while j < customTab.count {
  74. if(((i == 1 && customTab.count == 3) || i == 2) &&
  75. (cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
  76. tabs.append(emptyTab)
  77. }
  78. else {
  79. switch(customTab[j]){
  80. case "1":
  81. tabs.append(firstTab!)
  82. case "2":
  83. tabs.append(secondTab!)
  84. case "3":
  85. tabs.append(thirdTab!)
  86. case "4":
  87. tabs.append(fourthTab!)
  88. default:
  89. break
  90. }
  91. j += 1
  92. }
  93. i += 1
  94. }
  95. if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
  96. navigationController?.setNavigationBarHidden(false, animated: false)
  97. print("cpaas mode burger")
  98. let childrenMenu : [UIAction] = [
  99. UIAction(title: "Contact Center", handler: {[weak self](_) in
  100. self?.ccTap()
  101. }),
  102. UIAction(title: "Chat", handler: {[weak self](_) in
  103. self?.chatTap()
  104. }),
  105. UIAction(title: "Call", handler: {[weak self](_) in
  106. self?.callTap()
  107. }),
  108. UIAction(title: "New Post", handler: {[weak self](_) in
  109. self?.postTap()
  110. }),
  111. UIAction(title: "Live Streaming", handler: {[weak self](_) in
  112. self?.streamTap()
  113. }),
  114. // UIAction(title: "Settings", handler: {[weak self](_) in
  115. // self?.settingTap()
  116. // }),
  117. ]
  118. let menu = UIMenu(title: "", children: childrenMenu)
  119. if PrefsUtil.getIconDock() != nil {
  120. DispatchQueue.global().async {
  121. ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
  122. guard let data = data, error == nil else { return }
  123. // always update the UI from the main thread
  124. DispatchQueue.main.async() { [self] in
  125. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  126. }
  127. }
  128. }
  129. } else {
  130. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  131. }
  132. }
  133. if((cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
  134. createMidFloatingButton()
  135. navigationController?.setNavigationBarHidden(true, animated: false)
  136. }
  137. // if((cpaasMode == PrefsUtil.CPAAS_MODE_FLOATING || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)) {
  138. // let rect = CGRect(x: self.view.bounds.width - 100, y: self.view.bounds.height / 2, width: 50, height: 250)
  139. // floating = FloatingButton()
  140. // floating?.frame = rect
  141. // floating?.isShow = true
  142. //
  143. // view.addSubview(floating!)
  144. // navigationController?.setNavigationBarHidden(true, animated: false)
  145. // }
  146. self.setViewControllers(tabs, animated: false)
  147. if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
  148. if(customTab.count == 3){
  149. self.tabBar.items?[1].isEnabled = false
  150. }
  151. self.tabBar.items?[2].isEnabled = false
  152. }
  153. let numberOfItems = CGFloat(tabBar.items!.count)
  154. let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: 65)
  155. tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.black.withAlphaComponent(0.2), size: tabBarItemSize).resizableImage(withCapInsets: .zero)
  156. if Bundle.main.displayName == "DigiNetS" {
  157. tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.gray, size: tabBarItemSize).resizableImage(withCapInsets: .zero)
  158. }
  159. UIFont.overrideInitialize()
  160. }
  161. override func viewDidLayoutSubviews() {
  162. super.viewDidLayoutSubviews()
  163. tabBar.frame.size.height = 65
  164. tabBar.frame.origin.y = view.frame.height - 65
  165. }
  166. func settingDelegate() {
  167. if self.viewControllers?.firstIndex(of: fourthTab!) == nil {
  168. let vc = fourthTab!
  169. vc.notInTab = true
  170. self.navigationController?.show(vc, sender: nil)
  171. } else {
  172. self.selectedIndex = (self.viewControllers?.firstIndex(of: fourthTab!))!
  173. }
  174. }
  175. public static func checkIsChangePerson() -> Bool {
  176. let isChangeProfile = Utils.getSetProfile()
  177. if !isChangeProfile {
  178. let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized().localized(), preferredStyle: .alert)
  179. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .destructive, handler: {_ in
  180. if ViewController.def?.viewControllers?.firstIndex(of: (ViewController.def?.firstTab)!) == ViewController.def?.selectedIndex {
  181. ViewController.def?.firstTab?.webView?.evaluateJavaScript("if(resumeAll){resumeAll();}")
  182. }
  183. if ViewController.def?.viewControllers?.firstIndex(of: (ViewController.def?.thirdTab)!) == ViewController.def?.selectedIndex {
  184. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("if(resumeAll){resumeAll();}")
  185. }
  186. }))
  187. alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
  188. ViewController.resetTabSelected()
  189. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeNS") as! ChangeNamePassswordViewController
  190. let navigationController = UINavigationController(rootViewController: controller)
  191. navigationController.modalPresentationStyle = .fullScreen
  192. navigationController.navigationBar.tintColor = .white
  193. navigationController.navigationBar.barTintColor = .mainColor
  194. navigationController.navigationBar.isTranslucent = false
  195. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  196. navigationController.navigationBar.titleTextAttributes = textAttributes
  197. navigationController.view.backgroundColor = .mainColor
  198. ViewController.def?.show(b: false)
  199. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  200. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  201. let rootVC = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
  202. if rootVC?.presentedViewController == nil {
  203. rootVC?.present(navigationController, animated: true, completion: nil)
  204. } else {
  205. rootVC?.presentedViewController?.present(navigationController, animated: true, completion: nil)
  206. }
  207. }))
  208. let rootVC = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
  209. if rootVC?.presentedViewController == nil {
  210. rootVC?.present(alert, animated: true, completion: nil)
  211. } else {
  212. rootVC?.presentedViewController?.present(alert, animated: true, completion: nil)
  213. }
  214. return false
  215. }
  216. return true
  217. }
  218. public static func resetTabSelected(){
  219. ViewController.isTab1 = true
  220. ViewController.isTab2 = false
  221. ViewController.isTab3 = false
  222. ViewController.isTab4 = false
  223. // if ViewController.isTab1 {
  224. // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis")!
  225. // }
  226. // else {
  227. // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis_off")!
  228. // }
  229. // if ViewController.isTab2 {
  230. // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis")!
  231. // }
  232. // else {
  233. // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis_off")!
  234. // }
  235. // if ViewController.isTab3 {
  236. // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis")!
  237. // }
  238. // else {
  239. // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis_off")!
  240. // }
  241. // if ViewController.isTab4 {
  242. // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis")!
  243. // }
  244. // else {
  245. // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis_off")!
  246. // }
  247. }
  248. override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
  249. let cpaasMode = PrefsUtil.getCpaasMode()
  250. let customTab = PrefsUtil.getCustomTab().split(separator: ",")
  251. if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
  252. if(customTab.count == 2){
  253. ViewController.isTab1 = item == tabBar.items?[0]
  254. ViewController.isTab2 = item == tabBar.items?[2]
  255. }
  256. else if(customTab.count == 3){
  257. ViewController.isTab1 = item == tabBar.items?[0]
  258. ViewController.isTab2 = item == tabBar.items?[2]
  259. ViewController.isTab3 = item == tabBar.items?[3]
  260. }
  261. else if(customTab.count == 4){
  262. ViewController.isTab1 = item == tabBar.items?[0]
  263. ViewController.isTab2 = item == tabBar.items?[1]
  264. ViewController.isTab3 = item == tabBar.items?[3]
  265. ViewController.isTab4 = item == tabBar.items?[4]
  266. }
  267. }
  268. else{
  269. ViewController.isTab1 = item == tabBar.items?[0]
  270. ViewController.isTab2 = item == tabBar.items?[1]
  271. if(customTab.count > 2){
  272. ViewController.isTab3 = item == tabBar.items?[2]
  273. }
  274. if(customTab.count > 3){
  275. ViewController.isTab4 = item == tabBar.items?[3]
  276. }
  277. }
  278. }
  279. func createMidFloatingButton(){
  280. ViewController.chatButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 60, height: 60))
  281. ViewController.chatButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  282. ViewController.chatButton.layer.shadowColor = UIColor.black.cgColor
  283. ViewController.chatButton.layer.shadowOpacity = 0.1
  284. ViewController.chatButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  285. ViewController.chatButton.addTarget(self, action: #selector(chatTap), for: .touchUpInside)
  286. ViewController.callButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 60, height: 60))
  287. ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  288. ViewController.callButton.layer.shadowColor = UIColor.black.cgColor
  289. ViewController.callButton.layer.shadowOpacity = 0.1
  290. ViewController.callButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  291. ViewController.callButton.addTarget(self, action: #selector(callTap), for: .touchUpInside)
  292. ViewController.ccButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 60, height: 60))
  293. ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  294. ViewController.ccButton.layer.shadowColor = UIColor.black.cgColor
  295. ViewController.ccButton.layer.shadowOpacity = 0.1
  296. ViewController.ccButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  297. ViewController.ccButton.addTarget(self, action: #selector(ccTap), for: .touchUpInside)
  298. ViewController.streamingButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 60, height: 60))
  299. ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  300. ViewController.streamingButton.layer.shadowColor = UIColor.black.cgColor
  301. ViewController.streamingButton.layer.shadowOpacity = 0.1
  302. ViewController.streamingButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  303. ViewController.streamingButton.addTarget(self, action: #selector(streamTap), for: .touchUpInside)
  304. ViewController.postButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 60, height: 60))
  305. ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_post", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  306. ViewController.postButton.layer.shadowColor = UIColor.black.cgColor
  307. ViewController.postButton.layer.shadowOpacity = 0.1
  308. ViewController.postButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  309. ViewController.postButton.addTarget(self, action: #selector(postTap), for: .touchUpInside)
  310. let buttonCenterX = self.view.bounds.width / 2
  311. let buttonCenterY = self.view.bounds.height - 65
  312. print("buttonCenterX \(buttonCenterX)")
  313. print("buttonCenterY \(buttonCenterY)")
  314. ViewController.middleButton = UIButton(frame: CGRect(x: buttonCenterX - 50 , y: buttonCenterY - 55, width: 100, height: 100))
  315. if PrefsUtil.getIconDock() != nil {
  316. DispatchQueue.global().async {
  317. ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
  318. guard let data = data, error == nil else { return }
  319. // always update the UI from the main thread
  320. DispatchQueue.main.async() {
  321. ViewController.middleButton.setBackgroundImage(UIImage(data: data), for: .normal)
  322. }
  323. }
  324. }
  325. } else {
  326. ViewController.middleButton.setBackgroundImage(UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  327. }
  328. ViewController.middleButton.layer.shadowColor = UIColor.black.cgColor
  329. ViewController.middleButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
  330. ViewController.middleButton.layer.shadowOpacity = 1.0
  331. ViewController.middleButton.layer.shadowRadius = 5.0
  332. ViewController.middleButton.layer.masksToBounds = false
  333. ViewController.middleButton.layer.cornerRadius = 4.0
  334. ViewController.middleButton.addTarget(self, action: #selector(middleBtnTapped), for: .touchUpInside)
  335. let longPressMidButton = UILongPressGestureRecognizer(target: self, action: #selector(longPressMidBtn(gestureRecognizer:)))
  336. ViewController.middleButton.addGestureRecognizer(longPressMidButton)
  337. self.view.addSubview(ViewController.chatButton)
  338. self.view.addSubview(ViewController.callButton)
  339. self.view.addSubview(ViewController.ccButton)
  340. self.view.addSubview(ViewController.postButton)
  341. self.view.addSubview(ViewController.streamingButton)
  342. self.view.addSubview(ViewController.middleButton)
  343. ViewController.hideDockedButton()
  344. }
  345. @objc func longPressMidBtn(gestureRecognizer: UILongPressGestureRecognizer) {
  346. if gestureRecognizer.state == .began {
  347. if self.viewControllers?.firstIndex(of: fourthTab!) == nil {
  348. let vc = fourthTab!
  349. vc.notInTab = true
  350. self.navigationController?.show(vc, sender: nil)
  351. } else {
  352. self.selectedIndex = (self.viewControllers?.firstIndex(of: fourthTab!))!
  353. }
  354. }
  355. }
  356. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  357. if(viewController == secondTab){
  358. if(!ViewController.checkIsChangePerson()){
  359. return false
  360. }
  361. }
  362. return true
  363. }
  364. func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
  365. if viewController != secondTab {
  366. let idxTabChat = self.viewControllers?.firstIndex(where: {$0 == secondTab})
  367. if idxTabChat != nil {
  368. let vcTabChats = self.viewControllers![idxTabChat!] as! SecondTabViewController
  369. if vcTabChats.searchController.isActive {
  370. vcTabChats.searchController.isActive = false
  371. }
  372. }
  373. }
  374. let cpaasMode = PrefsUtil.getCpaasMode()
  375. var childrenMenu = [UIAction]()
  376. if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
  377. print("cpaas mode burger")
  378. childrenMenu.append(contentsOf: [
  379. UIAction(title: "Contact Center", handler: {[weak self](_) in
  380. self?.ccTap()
  381. }),
  382. UIAction(title: "Chat", handler: {[weak self](_) in
  383. self?.chatTap()
  384. }),
  385. UIAction(title: "Call", handler: {[weak self](_) in
  386. self?.callTap()
  387. }),
  388. UIAction(title: "New Post", handler: {[weak self](_) in
  389. self?.postTap()
  390. }),
  391. UIAction(title: "Live Streaming", handler: {[weak self](_) in
  392. self?.streamTap()
  393. }),
  394. // UIAction(title: "Settings", handler: {[weak self](_) in
  395. // self?.settingTap()
  396. // }),
  397. ])
  398. if let vc = viewController as? SecondTabViewController {
  399. childrenMenu.append(contentsOf: vc.childrenMenu)
  400. }
  401. let menu = UIMenu(title: "", children: childrenMenu)
  402. if PrefsUtil.getIconDock() != nil {
  403. DispatchQueue.global().async {
  404. ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
  405. guard let data = data, error == nil else { return }
  406. // always update the UI from the main thread
  407. DispatchQueue.main.async() { [self] in
  408. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  409. }
  410. }
  411. }
  412. } else {
  413. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  414. }
  415. }
  416. }
  417. override func viewWillAppear(_ animated: Bool) {
  418. let acceptTerm = PrefsUtil.getTerms()
  419. if !acceptTerm {
  420. showWelocomeView()
  421. return
  422. } else {
  423. if !Utils.getForceAnonymous() && !Utils.getSetProfile() {
  424. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
  425. controller.forceLogin = true
  426. let navigationController = UINavigationController(rootViewController: controller)
  427. navigationController.navigationBar.tintColor = .white
  428. navigationController.navigationBar.barTintColor = .mainColor
  429. navigationController.navigationBar.isTranslucent = false
  430. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  431. navigationController.navigationBar.titleTextAttributes = textAttributes
  432. navigationController.view.backgroundColor = .mainColor
  433. navigationController.modalPresentationStyle = .fullScreen
  434. navigationController.modalTransitionStyle = .crossDissolve
  435. self.present(navigationController, animated: true)
  436. return
  437. }
  438. }
  439. if firstLoad {
  440. firstLoad = false
  441. if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
  442. ViewController.pullActionButton()
  443. }
  444. self.selectedViewController?.viewWillAppear(false)
  445. } else {
  446. self.selectedViewController?.viewWillAppear(false)
  447. }
  448. }
  449. func showWelocomeView() {
  450. if let viewWelcome = welcomeVC.view {
  451. let bgImage = UIImageView()
  452. viewWelcome.addSubview(bgImage)
  453. bgImage.anchor(top: viewWelcome.topAnchor, left: viewWelcome.leftAnchor, bottom: viewWelcome.bottomAnchor, right: viewWelcome.rightAnchor)
  454. bgImage.backgroundColor = .white
  455. DispatchQueue.global().async {
  456. if let listBg = PrefsUtil.getBackground() {
  457. if listBg.isEmpty {
  458. return
  459. }
  460. var bgChoosen = ""
  461. let arrayBg = listBg.split(separator: ",")
  462. bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
  463. ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "/dashboardv2/uploads/background/" + bgChoosen)!) { data, response, error in
  464. guard let data = data, error == nil else { return }
  465. // always update the UI from the main thread
  466. DispatchQueue.main.async() {
  467. bgImage.image = UIImage(data: data)!
  468. }
  469. }
  470. }
  471. }
  472. let welcomeTitle = UILabel()
  473. welcomeTitle.text = "Welcome to".localized() + " " + (Bundle.main.displayName ?? "")
  474. welcomeTitle.font = .systemFont(ofSize: 25, weight: .bold)
  475. viewWelcome.addSubview(welcomeTitle)
  476. welcomeTitle.anchor(top: viewWelcome.safeAreaLayoutGuide.topAnchor, left: viewWelcome.safeAreaLayoutGuide.leftAnchor, paddingTop: 10, paddingLeft: 10)
  477. let logoImage = UIImageView()
  478. logoImage.image = UIImage(named: "pb_icon")
  479. viewWelcome.addSubview(logoImage)
  480. logoImage.anchor(centerX: viewWelcome.centerXAnchor, centerY: viewWelcome.centerYAnchor, width: 200, height: 200)
  481. let containerButton = UIView()
  482. viewWelcome.addSubview(containerButton)
  483. containerButton.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: viewWelcome.safeAreaLayoutGuide.bottomAnchor, paddingLeft: 10, paddingBottom: 10, minHeight: 40)
  484. containerButton.rightAnchor.constraint(lessThanOrEqualTo: viewWelcome.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
  485. containerButton.isUserInteractionEnabled = true
  486. let tapgestureAgree = UITapGestureRecognizer(target: self, action: #selector(tappedOnAgree(_ :)))
  487. tapgestureAgree.numberOfTapsRequired = 1
  488. containerButton.addGestureRecognizer(tapgestureAgree)
  489. let imageAgree = UIImageView()
  490. imageAgree.image = UIImage(systemName: "arrow.forward.circle")
  491. imageAgree.tintColor = .mainColor
  492. containerButton.addSubview(imageAgree)
  493. imageAgree.anchor(left: containerButton.leftAnchor, centerY: containerButton.centerYAnchor, width: 40, height: 40)
  494. let titleAgree = UILabel()
  495. titleAgree.text = "Agree and Continue".localized()
  496. titleAgree.textColor = .mainColor
  497. containerButton.addSubview(titleAgree)
  498. titleAgree.anchor(left: imageAgree.rightAnchor, right: containerButton.rightAnchor, paddingLeft: 5, centerY: containerButton.centerYAnchor)
  499. let formattedText = String.format(strings: [term], inString: termText)
  500. welcomeDesc.isUserInteractionEnabled = true
  501. welcomeDesc.attributedText = formattedText
  502. welcomeDesc.numberOfLines = 0
  503. viewWelcome.addSubview(welcomeDesc)
  504. welcomeDesc.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: containerButton.topAnchor, right: viewWelcome.rightAnchor, paddingLeft: 10, paddingBottom: 10, paddingRight: 10)
  505. let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabelTerms(_ :)))
  506. tapgesture.numberOfTapsRequired = 1
  507. welcomeDesc.addGestureRecognizer(tapgesture)
  508. }
  509. welcomeVC.modalPresentationStyle = .fullScreen
  510. welcomeVC.modalTransitionStyle = .crossDissolve
  511. self.present(welcomeVC, animated: true)
  512. }
  513. func showWebviewTerm() {
  514. termVC = UIViewController()
  515. if let viewTerm = termVC!.view {
  516. let webView = WKWebView()
  517. let url = URL (string: "https://newuniverse.io/newuniverse-tos")
  518. let requestObj = URLRequest(url: url!)
  519. webView.load(requestObj)
  520. viewTerm.addSubview(webView)
  521. webView.anchor(top: viewTerm.safeAreaLayoutGuide.topAnchor, left: viewTerm.safeAreaLayoutGuide.leftAnchor, bottom: viewTerm.safeAreaLayoutGuide.bottomAnchor, right: viewTerm.safeAreaLayoutGuide.rightAnchor)
  522. }
  523. let navigationController = UINavigationController(rootViewController: termVC!)
  524. navigationController.navigationBar.tintColor = .mainColor
  525. navigationController.navigationBar.barTintColor = .white
  526. navigationController.navigationBar.isTranslucent = false
  527. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.mainColor]
  528. navigationController.navigationBar.titleTextAttributes = textAttributes
  529. navigationController.view.backgroundColor = .white
  530. termVC!.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close".localized(), style: .plain, target: self, action: #selector(closeTerm))
  531. welcomeVC.present(navigationController, animated: true)
  532. }
  533. @objc func closeTerm() {
  534. termVC!.dismiss(animated: true)
  535. }
  536. @objc func tappedOnLabelTerms(_ gesture: UITapGestureRecognizer) {
  537. let termString = termText as NSString
  538. let termRange = termString.range(of: term)
  539. let tapLocation = gesture.location(in: welcomeDesc)
  540. let index = welcomeDesc.indexOfAttributedTextCharacterAtPoint(point: tapLocation)
  541. if checkRange(termRange, contain: index) == true {
  542. showWebviewTerm()
  543. return
  544. }
  545. }
  546. @objc func tappedOnAgree(_ gesture: UITapGestureRecognizer) {
  547. PrefsUtil.setTerms(value: true)
  548. welcomeVC.dismiss(animated: true)
  549. }
  550. func checkRange(_ range: NSRange, contain index: Int) -> Bool {
  551. return index > range.location && index < range.location + range.length
  552. }
  553. @objc func middleBtnTapped() {
  554. ViewController.expandButton()
  555. }
  556. public func show(b: Bool) {
  557. if(!b){
  558. if(ViewController.isExpandButton){
  559. ViewController.expandButton()
  560. }
  561. }
  562. }
  563. @objc func ccTap() {
  564. print("ccTap")
  565. if(ViewController.checkIsChangePerson()){
  566. show(b: false)
  567. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  568. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  569. if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 2 {
  570. let package_id = ViewController.listPullFB[2].split(separator: "|")[0]
  571. var app_id = ""
  572. if ViewController.listPullFB[2].split(separator: "|").count > 1 {
  573. app_id = String(ViewController.listPullFB[2].split(separator: "|")[1])
  574. }
  575. if package_id.contains("_fb") {
  576. let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
  577. if indexTap == 99 {
  578. openTabPost()
  579. } else {
  580. if indexTap == 2 {
  581. let url = package_id.components(separatedBy: "_")[2]
  582. Nexilis.buttonClicked(index: indexTap, id: url)
  583. } else {
  584. Nexilis.buttonClicked(index: indexTap)
  585. }
  586. }
  587. } else {
  588. if !app_id.isEmpty {
  589. Nexilis.buttonClicked(index: 0, id: app_id)
  590. }
  591. }
  592. } else {
  593. Nexilis.buttonClicked(index: 9)
  594. }
  595. }
  596. }
  597. @objc func streamTap() {
  598. print("streamTap")
  599. if(ViewController.checkIsChangePerson()){
  600. show(b: false)
  601. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  602. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  603. if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 4 {
  604. let package_id = ViewController.listPullFB[4].split(separator: "|")[0]
  605. var app_id = ""
  606. if ViewController.listPullFB[4].split(separator: "|").count > 1 {
  607. app_id = String(ViewController.listPullFB[4].split(separator: "|")[1])
  608. }
  609. if package_id.contains("_fb") {
  610. let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
  611. if indexTap == 99 {
  612. openTabPost()
  613. } else {
  614. if indexTap == 2 {
  615. let url = package_id.components(separatedBy: "_")[2]
  616. Nexilis.buttonClicked(index: indexTap, id: url)
  617. } else {
  618. Nexilis.buttonClicked(index: indexTap)
  619. }
  620. }
  621. } else {
  622. if !app_id.isEmpty {
  623. Nexilis.buttonClicked(index: 0, id: app_id)
  624. }
  625. }
  626. } else {
  627. Nexilis.buttonClicked(index: 8)
  628. }
  629. }
  630. }
  631. @objc func callTap() {
  632. print("callTap")
  633. if(ViewController.checkIsChangePerson()){
  634. show(b: false)
  635. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  636. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  637. if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 1 {
  638. let package_id = ViewController.listPullFB[1].split(separator: "|")[0]
  639. var app_id = ""
  640. if ViewController.listPullFB[1].split(separator: "|").count > 1 {
  641. app_id = String(ViewController.listPullFB[1].split(separator: "|")[1])
  642. }
  643. if package_id.contains("_fb") {
  644. let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
  645. if indexTap == 99 {
  646. openTabPost()
  647. } else {
  648. if indexTap == 2 {
  649. let url = package_id.components(separatedBy: "_")[2]
  650. Nexilis.buttonClicked(index: indexTap, id: url)
  651. } else {
  652. Nexilis.buttonClicked(index: indexTap)
  653. }
  654. }
  655. } else {
  656. if !app_id.isEmpty {
  657. Nexilis.buttonClicked(index: 0, id: app_id)
  658. }
  659. }
  660. } else {
  661. Nexilis.buttonClicked(index: 7)
  662. }
  663. }
  664. }
  665. @objc func chatTap() {
  666. print("chatTap")
  667. if(ViewController.checkIsChangePerson()){
  668. show(b: false)
  669. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  670. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  671. if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 0 {
  672. let package_id = ViewController.listPullFB[0].split(separator: "|")[0]
  673. var app_id = ""
  674. if ViewController.listPullFB[0].split(separator: "|").count > 1 {
  675. app_id = String(ViewController.listPullFB[0].split(separator: "|")[1])
  676. }
  677. if package_id.contains("_fb") {
  678. let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
  679. if indexTap == 99 {
  680. openTabPost()
  681. } else {
  682. if indexTap == 2 {
  683. let url = package_id.components(separatedBy: "_")[2]
  684. Nexilis.buttonClicked(index: indexTap, id: url)
  685. } else {
  686. Nexilis.buttonClicked(index: indexTap)
  687. }
  688. }
  689. } else {
  690. if !app_id.isEmpty {
  691. Nexilis.buttonClicked(index: 0, id: app_id)
  692. }
  693. }
  694. } else {
  695. Nexilis.buttonClicked(index: 6)
  696. }
  697. }
  698. }
  699. @objc func postTap() {
  700. if(ViewController.checkIsChangePerson()){
  701. show(b: false)
  702. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  703. ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
  704. if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 3 {
  705. let package_id = ViewController.listPullFB[3].split(separator: "|")[0]
  706. var app_id = ""
  707. if ViewController.listPullFB[3].split(separator: "|").count > 1 {
  708. app_id = String(ViewController.listPullFB[3].split(separator: "|")[1])
  709. }
  710. if package_id.contains("_fb") {
  711. let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
  712. if indexTap == 99 {
  713. openTabPost()
  714. } else {
  715. if indexTap == 2 {
  716. let url = package_id.components(separatedBy: "_")[2]
  717. Nexilis.buttonClicked(index: indexTap, id: url)
  718. } else {
  719. Nexilis.buttonClicked(index: indexTap)
  720. }
  721. }
  722. } else {
  723. if !app_id.isEmpty {
  724. Nexilis.buttonClicked(index: 0, id: app_id)
  725. }
  726. }
  727. } else {
  728. openTabPost()
  729. }
  730. }
  731. }
  732. func openTabPost() {
  733. let customTab = PrefsUtil.getCustomTab().split(separator: ",")
  734. let cpaasMode = PrefsUtil.getCpaasMode()
  735. var i = 0
  736. var j = 0
  737. print("custom tab post tap = \(customTab)")
  738. while j < customTab.count {
  739. if(((i == 1 && customTab.count == 3) || i == 2) &&
  740. (cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
  741. }
  742. else {
  743. if customTab[j] == "3" {
  744. break
  745. }
  746. j += 1
  747. }
  748. i += 1
  749. }
  750. if(j < customTab.count){
  751. self.selectedIndex = i
  752. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(1), execute: {
  753. let me = UserDefaults.standard.string(forKey: "me")
  754. let address = "\(PrefsUtil.getURLBase() ?? "https://qmera.io/")nexilis/pages/tab5-new-post?f_pin=\(me ?? "")"
  755. self.thirdTab?.webView.evaluateJavaScript("window.location = '\(address)'")
  756. })
  757. }
  758. }
  759. static func pullActionButton() {
  760. if datePullFB == nil || Int(Date().timeIntervalSince(datePullFB!)) >= 60 {
  761. datePullFB = Date()
  762. DispatchQueue.global().async {
  763. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.pullFloatingButton(), timeout: 30 * 1000) {
  764. if response.isOk() {
  765. let data = response.getBody(key: CoreMessage_TMessageKey.DATA, default_value: "")
  766. if !data.isEmpty {
  767. if let jsonArray = try! JSONSerialization.jsonObject(with: data.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
  768. DispatchQueue.main.async { [self] in
  769. listPullFB.removeAll()
  770. if jsonArray.count != 0 {
  771. var count = 0
  772. for json in jsonArray {
  773. let package_id = json["package_act"] as! String
  774. let app_id = (json["app_id"] as? String) ?? ""
  775. let icon = (json["icon"] as? String) ?? ""
  776. listPullFB.append("\(package_id)|\(app_id)")
  777. if count == 0 {
  778. if !icon.isEmpty {
  779. DispatchQueue.global().async {
  780. ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
  781. guard let data = data, error == nil else { return }
  782. // always update the UI from the main thread
  783. DispatchQueue.main.async() {
  784. ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
  785. }
  786. }
  787. }
  788. } else {
  789. ViewController.chatButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  790. }
  791. } else if count == 1 {
  792. if !icon.isEmpty {
  793. DispatchQueue.global().async {
  794. ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
  795. guard let data = data, error == nil else { return }
  796. // always update the UI from the main thread
  797. DispatchQueue.main.async() {
  798. ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
  799. }
  800. }
  801. }
  802. } else {
  803. ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  804. }
  805. } else if count == 2 {
  806. if !icon.isEmpty {
  807. DispatchQueue.global().async {
  808. ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
  809. guard let data = data, error == nil else { return }
  810. // always update the UI from the main thread
  811. DispatchQueue.main.async() {
  812. ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
  813. }
  814. }
  815. }
  816. } else {
  817. ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  818. }
  819. } else if count == 3 {
  820. if !icon.isEmpty {
  821. DispatchQueue.global().async {
  822. ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
  823. guard let data = data, error == nil else { return }
  824. // always update the UI from the main thread
  825. DispatchQueue.main.async() {
  826. ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
  827. }
  828. }
  829. }
  830. } else {
  831. ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  832. }
  833. } else if count == 4 {
  834. if !icon.isEmpty {
  835. DispatchQueue.global().async {
  836. ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
  837. guard let data = data, error == nil else { return }
  838. // always update the UI from the main thread
  839. DispatchQueue.main.async() {
  840. ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
  841. }
  842. }
  843. }
  844. } else {
  845. ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  846. }
  847. }
  848. count += 1
  849. }
  850. }
  851. }
  852. }
  853. }
  854. }
  855. }
  856. }
  857. }
  858. }
  859. public static func showDockedButton() {
  860. ViewController.chatButton.isHidden = false
  861. ViewController.callButton.isHidden = false
  862. ViewController.ccButton.isHidden = false
  863. ViewController.streamingButton.isHidden = false
  864. ViewController.postButton.isHidden = false
  865. }
  866. public static func hideDockedButton() {
  867. ViewController.chatButton.isHidden = true
  868. ViewController.callButton.isHidden = true
  869. ViewController.ccButton.isHidden = true
  870. ViewController.streamingButton.isHidden = true
  871. ViewController.postButton.isHidden = true
  872. }
  873. public static func expandButton() {
  874. let cpaasMode = PrefsUtil.getCpaasMode()
  875. if cpaasMode != PrefsUtil.CPAAS_MODE_DOCKED && cpaasMode != PrefsUtil.CPAAS_MODE_MIX {
  876. return
  877. }
  878. if ViewController.alwaysHideButton && !ViewController.isExpandButton {
  879. return
  880. }
  881. if ViewController.isExpandButton {
  882. ViewController.isExpandButton = false
  883. let xChatPosition = ViewController.chatButton.frame.origin.x + 120
  884. let yChatPosition = ViewController.chatButton.frame.origin.y + 55
  885. let xCallPosition = ViewController.callButton.frame.origin.x + 75
  886. let yCallPosition = ViewController.callButton.frame.origin.y + 110
  887. let xCCPosition = ViewController.ccButton.frame.origin.x
  888. let yCCPosition = ViewController.ccButton.frame.origin.y + 135
  889. let xPostPosition = ViewController.postButton.frame.origin.x - 75
  890. let yPostPosition = ViewController.postButton.frame.origin.y + 110
  891. let xStreamingPosition = ViewController.streamingButton.frame.origin.x - 120
  892. let yStreamingPosition = ViewController.streamingButton.frame.origin.y + 55
  893. UIView.animate(withDuration: 0.5, animations: {
  894. // if !ViewController.isBlue {
  895. // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: 0)
  896. // }
  897. ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
  898. ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
  899. ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
  900. ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
  901. ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
  902. })
  903. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
  904. if !ViewController.isExpandButton {
  905. ViewController.hideDockedButton()
  906. }
  907. })
  908. } else {
  909. ViewController.isExpandButton = true
  910. ViewController.showDockedButton()
  911. let xChatPosition = ViewController.chatButton.frame.origin.x - 120
  912. let yChatPosition = ViewController.chatButton.frame.origin.y - 55
  913. let xCallPosition = ViewController.callButton.frame.origin.x - 75
  914. let yCallPosition = ViewController.callButton.frame.origin.y - 110
  915. let xCCPosition = ViewController.ccButton.frame.origin.x
  916. let yCCPosition = ViewController.ccButton.frame.origin.y - 135
  917. let xPostPosition = ViewController.postButton.frame.origin.x + 75
  918. let yPostPosition = ViewController.postButton.frame.origin.y - 110
  919. let xStreamingPosition = ViewController.streamingButton.frame.origin.x + 120
  920. let yStreamingPosition = ViewController.streamingButton.frame.origin.y - 55
  921. UIView.animate(withDuration: 0.5, animations: {
  922. // if !ViewController.isBlue{
  923. // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: .pi / 2)
  924. // }
  925. ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
  926. ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
  927. ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
  928. ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
  929. ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
  930. })
  931. }
  932. }
  933. public static func removeMiddleButton() {
  934. // ViewController.chatButton.removeFromSuperview()
  935. // ViewController.callButton.removeFromSuperview()
  936. // ViewController.ccButton.removeFromSuperview()
  937. // ViewController.streamingButton.removeFromSuperview()
  938. // ViewController.postButton.removeFromSuperview()
  939. ViewController.middleButton.isHidden = true
  940. }
  941. public static func getDataImageFromUrl(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
  942. URLSession.shared.dataTask(with: url, completionHandler: completion).resume()
  943. }
  944. }
  945. class EmptyTabViewController: UIViewController {
  946. override func viewDidLoad() {
  947. }
  948. }
  949. extension Bundle {
  950. // Name of the app - title under the icon.
  951. var displayName: String? {
  952. return object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ??
  953. object(forInfoDictionaryKey: "CFBundleName") as? String
  954. }
  955. }
  956. extension BinaryInteger {
  957. var degreesToRadians: CGFloat { CGFloat(self) * .pi / 180 }
  958. }
  959. extension FloatingPoint {
  960. var degreesToRadians: Self { self * .pi / 180 }
  961. var radiansToDegrees: Self { self * 180 / .pi }
  962. }
  963. extension UIImage {
  964. class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
  965. let rect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
  966. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  967. color.setFill()
  968. UIRectFill(rect)
  969. let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  970. UIGraphicsEndImageContext()
  971. return image
  972. }
  973. }
  974. extension String {
  975. static func format(strings: [String],
  976. italicFont: UIFont = UIFont.italicSystemFont(ofSize: 12),
  977. italicColor: UIColor = UIColor.systemGreen,
  978. inString string: String,
  979. font: UIFont = UIFont.systemFont(ofSize: 12),
  980. color: UIColor = UIColor.black) -> NSAttributedString {
  981. let attributedString =
  982. NSMutableAttributedString(string: string,
  983. attributes: [
  984. NSAttributedString.Key.font: font,
  985. NSAttributedString.Key.foregroundColor: color])
  986. let italicFontAttribute = [NSAttributedString.Key.font: italicFont, NSAttributedString.Key.foregroundColor: italicColor]
  987. for italic in strings {
  988. attributedString.addAttributes(italicFontAttribute, range: (string as NSString).range(of: italic))
  989. }
  990. return attributedString
  991. }
  992. }
  993. extension UILabel {
  994. func indexOfAttributedTextCharacterAtPoint(point: CGPoint) -> Int {
  995. assert(self.attributedText != nil, "This method is developed for attributed string")
  996. let textStorage = NSTextStorage(attributedString: self.attributedText!)
  997. let layoutManager = NSLayoutManager()
  998. textStorage.addLayoutManager(layoutManager)
  999. let textContainer = NSTextContainer(size: self.frame.size)
  1000. textContainer.lineFragmentPadding = 0
  1001. textContainer.maximumNumberOfLines = self.numberOfLines
  1002. textContainer.lineBreakMode = self.lineBreakMode
  1003. layoutManager.addTextContainer(textContainer)
  1004. let index = layoutManager.characterIndex(for: point, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
  1005. return index
  1006. }
  1007. }