ViewController.swift 55 KB

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