ViewController.swift 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. class ViewController: UITabBarController, UITabBarControllerDelegate {
  15. let playerController = AVPlayerViewController()
  16. static var sURL = "https://www.google.com"
  17. static var tab3 = "0"
  18. public var isShow: Bool = false
  19. public static var chatButton = UIButton()
  20. public static var callButton = UIButton()
  21. public static var ccButton = UIButton()
  22. public static var streamingButton = UIButton()
  23. public static var postButton = UIButton()
  24. public static var middleButton = UIButton()
  25. var buttonChatGR : UITapGestureRecognizer?
  26. var buttonCallGR : UITapGestureRecognizer?
  27. var buttonCCGR : UITapGestureRecognizer?
  28. var buttonStreamGR : UITapGestureRecognizer?
  29. var floating : FloatingButton?
  30. var firstTab : FirstTabViewController?
  31. var secondTab : SecondTabViewController?
  32. var thirdTab : ThirdTabViewController?
  33. var fourthTab : FourthTabViewController?
  34. let emptyTab = EmptyTabViewController()
  35. public static var isTab1 = true
  36. public static var isTab2 = false
  37. public static var isTab3 = false
  38. public static var isTab4 = false
  39. public static var isExpandButton = false
  40. public static var alwaysHideButton = false
  41. public static var def: ViewController?
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. ViewController.def = self
  45. title = Bundle.main.displayName
  46. let customTab = PrefsUtil.getCustomTab().split(separator: ",")
  47. let cpaasMode = PrefsUtil.getCpaasMode()
  48. var tabs : [UIViewController] = []
  49. firstTab = storyboard?.instantiateViewController(withIdentifier: "firstTabVC") as? FirstTabViewController
  50. secondTab = storyboard?.instantiateViewController(withIdentifier: "secondTabVC") as? SecondTabViewController
  51. thirdTab = storyboard?.instantiateViewController(withIdentifier: "thirdTabVC") as? ThirdTabViewController
  52. fourthTab = storyboard?.instantiateViewController(withIdentifier: "fourthTabVC") as? FourthTabViewController
  53. self.delegate = self
  54. firstTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_1_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
  55. firstTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  56. secondTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_2_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
  57. secondTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  58. thirdTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_3_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
  59. thirdTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  60. fourthTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_4_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
  61. fourthTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
  62. var i = 0
  63. var j = 0
  64. while j < customTab.count {
  65. if(((i == 1 && customTab.count == 3) || i == 2) &&
  66. (cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
  67. tabs.append(emptyTab)
  68. }
  69. else {
  70. switch(customTab[j]){
  71. case "1":
  72. tabs.append(firstTab!)
  73. case "2":
  74. tabs.append(secondTab!)
  75. case "3":
  76. tabs.append(thirdTab!)
  77. case "4":
  78. tabs.append(fourthTab!)
  79. default:
  80. break
  81. }
  82. j += 1
  83. }
  84. i += 1
  85. }
  86. if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
  87. navigationController?.setNavigationBarHidden(false, animated: false)
  88. print("cpaas mode burger")
  89. let childrenMenu : [UIAction] = [
  90. UIAction(title: "Contact Center", handler: {[weak self](_) in
  91. self?.ccTap()
  92. }),
  93. UIAction(title: "Chat", handler: {[weak self](_) in
  94. self?.chatTap()
  95. }),
  96. UIAction(title: "Call", handler: {[weak self](_) in
  97. self?.callTap()
  98. }),
  99. // UIAction(title: "New Post", handler: {[weak self](_) in
  100. //
  101. // }),
  102. UIAction(title: "Live Streaming", handler: {[weak self](_) in
  103. self?.streamTap()
  104. }),
  105. // UIAction(title: "Settings", handler: {[weak self](_) in
  106. // self?.settingTap()
  107. // }),
  108. ]
  109. let menu = UIMenu(title: "", children: childrenMenu)
  110. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_ball", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  111. }
  112. if((cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
  113. createMidFloatingButton()
  114. navigationController?.setNavigationBarHidden(true, animated: false)
  115. }
  116. if((cpaasMode == PrefsUtil.CPAAS_MODE_FLOATING || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)) {
  117. let rect = CGRect(x: self.view.bounds.width - 100, y: self.view.bounds.height / 2, width: 50, height: 250)
  118. floating = FloatingButton()
  119. floating?.frame = rect
  120. floating?.isShow = true
  121. view.addSubview(floating!)
  122. navigationController?.setNavigationBarHidden(true, animated: false)
  123. }
  124. self.setViewControllers(tabs, animated: false)
  125. if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
  126. if(customTab.count == 3){
  127. self.tabBar.items?[1].isEnabled = false
  128. }
  129. self.tabBar.items?[2].isEnabled = false
  130. }
  131. let numberOfItems = CGFloat(tabBar.items!.count)
  132. let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
  133. tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.grayColor, size: tabBarItemSize).resizableImage(withCapInsets: .zero)
  134. UIFont.overrideInitialize()
  135. }
  136. public static func checkIsChangePerson() -> Bool {
  137. let isChangeProfile = UserDefaults.standard.bool(forKey: "is_change_profile")
  138. if !isChangeProfile {
  139. let alert = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized().localized(), preferredStyle: .alert)
  140. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .destructive, handler: {_ in
  141. ViewController.def?.thirdTab?.webView?.evaluateJavaScript("if(resumeAll){resumeAll();}")
  142. }))
  143. alert.addAction(UIAlertAction(title: "Ok".localized(), style: UIAlertAction.Style.default, handler: {(_) in
  144. ViewController.resetTabSelected()
  145. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeNS") as! ChangeNamePassswordViewController
  146. let navigationController = UINavigationController(rootViewController: controller)
  147. navigationController.modalPresentationStyle = .fullScreen
  148. // navigationController.navigationBar.tintColor = .white
  149. navigationController.navigationBar.barTintColor = .mainColor
  150. navigationController.navigationBar.isTranslucent = false
  151. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  152. // navigationController.navigationBar.titleTextAttributes = textAttributes
  153. navigationController.view.backgroundColor = .mainColor
  154. ViewController.def?.show(b: false)
  155. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.dismiss(animated: true, completion: nil)
  156. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  157. }))
  158. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(alert, animated: true, completion: nil)
  159. return false
  160. }
  161. return true
  162. }
  163. public static func resetTabSelected(){
  164. ViewController.isTab1 = true
  165. ViewController.isTab2 = false
  166. ViewController.isTab3 = false
  167. ViewController.isTab4 = false
  168. // if ViewController.isTab1 {
  169. // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis")!
  170. // }
  171. // else {
  172. // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis_off")!
  173. // }
  174. // if ViewController.isTab2 {
  175. // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis")!
  176. // }
  177. // else {
  178. // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis_off")!
  179. // }
  180. // if ViewController.isTab3 {
  181. // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis")!
  182. // }
  183. // else {
  184. // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis_off")!
  185. // }
  186. // if ViewController.isTab4 {
  187. // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis")!
  188. // }
  189. // else {
  190. // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis_off")!
  191. // }
  192. }
  193. override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
  194. let cpaasMode = PrefsUtil.getCpaasMode()
  195. let customTab = PrefsUtil.getCustomTab().split(separator: ",")
  196. if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
  197. if(customTab.count == 2){
  198. ViewController.isTab1 = item == tabBar.items?[0]
  199. ViewController.isTab2 = item == tabBar.items?[2]
  200. }
  201. else if(customTab.count == 3){
  202. ViewController.isTab1 = item == tabBar.items?[0]
  203. ViewController.isTab2 = item == tabBar.items?[2]
  204. ViewController.isTab3 = item == tabBar.items?[3]
  205. }
  206. else if(customTab.count == 4){
  207. ViewController.isTab1 = item == tabBar.items?[0]
  208. ViewController.isTab2 = item == tabBar.items?[1]
  209. ViewController.isTab3 = item == tabBar.items?[3]
  210. ViewController.isTab4 = item == tabBar.items?[4]
  211. }
  212. }
  213. else{
  214. ViewController.isTab1 = item == tabBar.items?[0]
  215. ViewController.isTab2 = item == tabBar.items?[1]
  216. if(customTab.count > 2){
  217. ViewController.isTab3 = item == tabBar.items?[2]
  218. }
  219. if(customTab.count > 3){
  220. ViewController.isTab4 = item == tabBar.items?[3]
  221. }
  222. }
  223. }
  224. func createMidFloatingButton(){
  225. ViewController.chatButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 45, height: 45))
  226. ViewController.chatButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  227. ViewController.chatButton.layer.shadowColor = UIColor.black.cgColor
  228. ViewController.chatButton.layer.shadowOpacity = 0.1
  229. ViewController.chatButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  230. ViewController.chatButton.addTarget(self, action: #selector(chatTap), for: .touchUpInside)
  231. ViewController.callButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 45, height: 45))
  232. ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  233. ViewController.callButton.layer.shadowColor = UIColor.black.cgColor
  234. ViewController.callButton.layer.shadowOpacity = 0.1
  235. ViewController.callButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  236. ViewController.callButton.addTarget(self, action: #selector(callTap), for: .touchUpInside)
  237. ViewController.ccButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 45, height: 45))
  238. ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  239. ViewController.ccButton.layer.shadowColor = UIColor.black.cgColor
  240. ViewController.ccButton.layer.shadowOpacity = 0.1
  241. ViewController.ccButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  242. ViewController.ccButton.addTarget(self, action: #selector(ccTap), for: .touchUpInside)
  243. ViewController.streamingButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 45, height: 45))
  244. ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  245. ViewController.streamingButton.layer.shadowColor = UIColor.black.cgColor
  246. ViewController.streamingButton.layer.shadowOpacity = 0.1
  247. ViewController.streamingButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  248. ViewController.streamingButton.addTarget(self, action: #selector(streamTap), for: .touchUpInside)
  249. ViewController.postButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 30 , y: self.view.bounds.height - 80, width: 45, height: 45))
  250. ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
  251. ViewController.postButton.layer.shadowColor = UIColor.black.cgColor
  252. ViewController.postButton.layer.shadowOpacity = 0.1
  253. ViewController.postButton.layer.shadowOffset = CGSize(width: 4, height: 4)
  254. ViewController.postButton.addTarget(self, action: #selector(streamTap), for: .touchUpInside)
  255. let buttonCenterX = self.view.bounds.width / 2
  256. let buttonCenterY = self.view.bounds.height - self.tabBar.bounds.height
  257. print("buttonCenterX \(buttonCenterX)")
  258. print("buttonCenterY \(buttonCenterY)")
  259. ViewController.middleButton = UIButton(frame: CGRect(x: buttonCenterX - 40 , y: buttonCenterY - 40, width: 80, height: 80))
  260. ViewController.middleButton.setBackgroundImage(UIImage(named: "pb_ball", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
  261. ViewController.middleButton.layer.shadowColor = UIColor.black.cgColor
  262. ViewController.middleButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
  263. ViewController.middleButton.layer.shadowOpacity = 1.0
  264. ViewController.middleButton.layer.shadowRadius = 5.0
  265. ViewController.middleButton.layer.masksToBounds = false
  266. ViewController.middleButton.layer.cornerRadius = 4.0
  267. ViewController.middleButton.addTarget(self, action: #selector(middleBtnTapped), for: .touchUpInside)
  268. self.view.addSubview(ViewController.chatButton)
  269. self.view.addSubview(ViewController.callButton)
  270. self.view.addSubview(ViewController.ccButton)
  271. self.view.addSubview(ViewController.streamingButton)
  272. self.view.addSubview(ViewController.postButton)
  273. self.view.addSubview(ViewController.middleButton)
  274. ViewController.hideDockedButton()
  275. }
  276. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  277. if(viewController == secondTab){
  278. if(!ViewController.checkIsChangePerson()){
  279. return false
  280. }
  281. }
  282. return true
  283. }
  284. func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
  285. print("select tabbar")
  286. let cpaasMode = PrefsUtil.getCpaasMode()
  287. var childrenMenu = [UIAction]()
  288. if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
  289. print("cpaas mode burger")
  290. childrenMenu.append(contentsOf: [
  291. UIAction(title: "Contact Center", handler: {[weak self](_) in
  292. self?.ccTap()
  293. }),
  294. UIAction(title: "Chat", handler: {[weak self](_) in
  295. self?.chatTap()
  296. }),
  297. UIAction(title: "Call", handler: {[weak self](_) in
  298. self?.callTap()
  299. }),
  300. UIAction(title: "New Post", handler: {[weak self](_) in
  301. }),
  302. UIAction(title: "Live Streaming", handler: {[weak self](_) in
  303. self?.streamTap()
  304. }),
  305. // UIAction(title: "Settings", handler: {[weak self](_) in
  306. // self?.settingTap()
  307. // }),
  308. ])
  309. if let vc = viewController as? SecondTabViewController {
  310. childrenMenu.append(contentsOf: vc.childrenMenu)
  311. }
  312. let menu = UIMenu(title: "", children: childrenMenu)
  313. navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_ball", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
  314. }
  315. }
  316. override func viewDidAppear(_ animated: Bool) {
  317. }
  318. @objc func middleBtnTapped() {
  319. ViewController.expandButton()
  320. }
  321. public func show(b: Bool) {
  322. if(!b){
  323. if(ViewController.isExpandButton){
  324. ViewController.expandButton()
  325. }
  326. }
  327. }
  328. @objc func qmeraLongPress() {
  329. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
  330. navigationController.modalPresentationStyle = .fullScreen
  331. // navigationController.navigationBar.tintColor = .white
  332. navigationController.navigationBar.barTintColor = .mainColor
  333. navigationController.navigationBar.isTranslucent = false
  334. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  335. // navigationController.navigationBar.titleTextAttributes = textAttributes
  336. navigationController.view.backgroundColor = .mainColor
  337. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  338. }
  339. @objc func ccTap() {
  340. print("ccTap")
  341. if(ViewController.checkIsChangePerson()){
  342. var isOfficer = false
  343. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  344. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  345. if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id FROM BUDDY where f_pin='\(idMe!)'"), cursorData.next() {
  346. if cursorData.string(forColumnIndex: 0) == "24" {
  347. isOfficer = true
  348. }
  349. cursorData.close()
  350. return
  351. }
  352. })
  353. show(b: false)
  354. if isOfficer {
  355. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "myHistoryCC") as! HistoryCCViewController
  356. controller.isOfficer = true
  357. let navigationController = UINavigationController(rootViewController: controller)
  358. // navigationController.navigationBar.tintColor = .white
  359. navigationController.modalPresentationStyle = .fullScreen
  360. navigationController.navigationBar.barTintColor = .mainColor
  361. navigationController.navigationBar.isTranslucent = false
  362. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  363. // navigationController.navigationBar.titleTextAttributes = textAttributes
  364. navigationController.view.backgroundColor = .mainColor
  365. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  366. } else {
  367. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  368. controller.isContactCenter = true
  369. let navigationController = UINavigationController(rootViewController: controller)
  370. navigationController.modalPresentationStyle = .fullScreen
  371. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  372. }
  373. }
  374. }
  375. @objc func streamTap() {
  376. print("streamTap")
  377. if(ViewController.checkIsChangePerson()){
  378. show(b: false)
  379. let navigationController = UINavigationController(rootViewController: QmeraCreateStreamingViewController())
  380. navigationController.modalPresentationStyle = .fullScreen
  381. // navigationController.navigationBar.tintColor = .white
  382. navigationController.navigationBar.barTintColor = .mainColor
  383. navigationController.navigationBar.isTranslucent = false
  384. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  385. // navigationController.navigationBar.titleTextAttributes = textAttributes
  386. navigationController.view.backgroundColor = .mainColor
  387. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  388. }
  389. }
  390. @objc func callTap() {
  391. print("callTap")
  392. if(ViewController.checkIsChangePerson()){
  393. show(b: false)
  394. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID")
  395. let navigationController = UINavigationController(rootViewController: callContact)
  396. navigationController.modalPresentationStyle = .fullScreen
  397. // navigationController.navigationBar.tintColor = .white
  398. navigationController.navigationBar.barTintColor = .mainColor
  399. navigationController.navigationBar.isTranslucent = false
  400. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  401. // navigationController.navigationBar.titleTextAttributes = textAttributes
  402. navigationController.view.backgroundColor = .mainColor
  403. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  404. }
  405. }
  406. @objc func chatTap() {
  407. print("chatTap")
  408. if(ViewController.checkIsChangePerson()){
  409. show(b: false)
  410. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
  411. navigationController.modalPresentationStyle = .fullScreen
  412. // navigationController.navigationBar.tintColor = .white
  413. navigationController.navigationBar.barTintColor = .mainColor
  414. navigationController.navigationBar.isTranslucent = false
  415. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  416. // navigationController.navigationBar.titleTextAttributes = textAttributes
  417. navigationController.view.backgroundColor = .mainColor
  418. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  419. }
  420. }
  421. @objc func settingTap() {
  422. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
  423. navigationController.modalPresentationStyle = .fullScreen
  424. // navigationController.navigationBar.tintColor = .white
  425. navigationController.navigationBar.barTintColor = .mainColor
  426. navigationController.navigationBar.isTranslucent = false
  427. // let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  428. // navigationController.navigationBar.titleTextAttributes = textAttributes
  429. navigationController.view.backgroundColor = .mainColor
  430. UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.present(navigationController, animated: true, completion: nil)
  431. }
  432. public static func showDockedButton() {
  433. ViewController.chatButton.isHidden = false
  434. ViewController.callButton.isHidden = false
  435. ViewController.ccButton.isHidden = false
  436. ViewController.streamingButton.isHidden = false
  437. ViewController.postButton.isHidden = false
  438. }
  439. public static func hideDockedButton() {
  440. ViewController.chatButton.isHidden = true
  441. ViewController.callButton.isHidden = true
  442. ViewController.ccButton.isHidden = true
  443. ViewController.streamingButton.isHidden = true
  444. ViewController.postButton.isHidden = true
  445. }
  446. public static func expandButton() {
  447. if ViewController.alwaysHideButton && !ViewController.isExpandButton {
  448. return
  449. }
  450. if ViewController.isExpandButton {
  451. ViewController.isExpandButton = false
  452. let xChatPosition = ViewController.chatButton.frame.origin.x + 80
  453. let yChatPosition = ViewController.chatButton.frame.origin.y + 20
  454. let xCallPosition = ViewController.callButton.frame.origin.x + 50
  455. let yCallPosition = ViewController.callButton.frame.origin.y + 70
  456. let xCCPosition = ViewController.ccButton.frame.origin.x
  457. let yCCPosition = ViewController.ccButton.frame.origin.y + 90
  458. let xStreamingPosition = ViewController.streamingButton.frame.origin.x - 50
  459. let yStreamingPosition = ViewController.streamingButton.frame.origin.y + 70
  460. let xPostPosition = ViewController.postButton.frame.origin.x - 80
  461. let yPostPosition = ViewController.postButton.frame.origin.y + 20
  462. UIView.animate(withDuration: 0.5, animations: {
  463. // if !ViewController.isBlue {
  464. // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: 0)
  465. // }
  466. ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
  467. ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
  468. ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
  469. ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
  470. ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
  471. })
  472. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
  473. if !ViewController.isExpandButton {
  474. ViewController.hideDockedButton()
  475. }
  476. })
  477. } else {
  478. ViewController.isExpandButton = true
  479. ViewController.showDockedButton()
  480. let xChatPosition = ViewController.chatButton.frame.origin.x - 80
  481. let yChatPosition = ViewController.chatButton.frame.origin.y - 20
  482. let xCallPosition = ViewController.callButton.frame.origin.x - 50
  483. let yCallPosition = ViewController.callButton.frame.origin.y - 70
  484. let xCCPosition = ViewController.ccButton.frame.origin.x
  485. let yCCPosition = ViewController.ccButton.frame.origin.y - 90
  486. let xStreamingPosition = ViewController.streamingButton.frame.origin.x + 50
  487. let yStreamingPosition = ViewController.streamingButton.frame.origin.y - 70
  488. let xPostPosition = ViewController.postButton.frame.origin.x + 80
  489. let yPostPosition = ViewController.postButton.frame.origin.y - 20
  490. UIView.animate(withDuration: 0.5, animations: {
  491. // if !ViewController.isBlue{
  492. // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: .pi / 2)
  493. // }
  494. ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
  495. ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
  496. ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
  497. ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
  498. ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
  499. })
  500. }
  501. }
  502. public static func removeMiddleButton() {
  503. ViewController.chatButton.removeFromSuperview()
  504. ViewController.callButton.removeFromSuperview()
  505. ViewController.ccButton.removeFromSuperview()
  506. ViewController.streamingButton.removeFromSuperview()
  507. ViewController.postButton.removeFromSuperview()
  508. ViewController.middleButton.removeFromSuperview()
  509. }
  510. }
  511. class EmptyTabViewController: UIViewController {
  512. override func viewDidLoad() {
  513. }
  514. }
  515. extension Bundle {
  516. // Name of the app - title under the icon.
  517. var displayName: String? {
  518. return object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ??
  519. object(forInfoDictionaryKey: "CFBundleName") as? String
  520. }
  521. }
  522. extension BinaryInteger {
  523. var degreesToRadians: CGFloat { CGFloat(self) * .pi / 180 }
  524. }
  525. extension FloatingPoint {
  526. var degreesToRadians: Self { self * .pi / 180 }
  527. var radiansToDegrees: Self { self * 180 / .pi }
  528. }
  529. extension UIImage {
  530. class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
  531. let rect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
  532. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  533. color.setFill()
  534. UIRectFill(rect)
  535. let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  536. UIGraphicsEndImageContext()
  537. return image
  538. }
  539. }