ViewController.swift 54 KB

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