APIS.swift 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. //
  2. // APIS.swift
  3. // NexilisLite
  4. //
  5. // Created by Akhmad Al Qindi Irsyam on 05/05/23.
  6. //
  7. import Foundation
  8. import UIKit
  9. import FMDB
  10. import NotificationBannerSwift
  11. import Toast_Swift
  12. import nuSDKService
  13. public class APIS: NSObject {
  14. public static func connect(apiKey: String, delegate: ConnectDelegate, showButton: Bool = true) {
  15. Nexilis.connect(apiKey: apiKey, delegate: delegate, showButton: showButton)
  16. }
  17. public static func getTotalCounter() -> Int32 {
  18. var counter: Int32?
  19. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  20. if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
  21. counter = cursor.int(forColumnIndex: 0)
  22. cursor.close()
  23. }
  24. })
  25. return counter ?? 0
  26. }
  27. private static func showChangeProfile() {
  28. let alert = LibAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
  29. alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
  30. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
  31. controller.forceLogin = true
  32. let navigationController = UINavigationController(rootViewController: controller)
  33. navigationController.defaultStyle()
  34. if UIApplication.shared.visibleViewController?.navigationController != nil {
  35. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  36. } else {
  37. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  38. }
  39. }))
  40. if UIApplication.shared.visibleViewController?.navigationController != nil {
  41. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  42. } else {
  43. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  44. }
  45. }
  46. public static func openContactCenter(media: Int? = nil, category: Int? = nil) {
  47. let isChangeProfile = Utils.getSetProfile()
  48. if !isChangeProfile {
  49. APIS.showChangeProfile()
  50. return
  51. }
  52. if User.isCallCenter(userType: (User.getData(pin: User.getMyPin())?.userType)!) {
  53. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "myHistoryCC") as! HistoryCCViewController
  54. controller.isOfficer = true
  55. controller.fromAPI = true
  56. let navigationController = UINavigationController(rootViewController: controller)
  57. navigationController.defaultStyle()
  58. if UIApplication.shared.visibleViewController?.navigationController != nil {
  59. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  60. } else {
  61. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  62. }
  63. } else {
  64. if media != nil || (media == nil && category != nil) {
  65. if media == nil || media! < 0 || media! > 2 {
  66. UIApplication.shared.visibleViewController?.view.makeToast("108:Invalid Contact Center media parameter (0:Chat, 1:Audio Call, 2:Video Call)".localized(), duration: 2)
  67. return
  68. }
  69. }
  70. if category != nil {
  71. if category != 0 {
  72. let service = CategoryCC.getDataFromServiceId(service_id: "\(category!)")
  73. if service == nil {
  74. UIApplication.shared.visibleViewController?.view.makeToast("109:Invalid Contact Center category parameter".localized(), duration: 2)
  75. return
  76. }
  77. let serviceChilds = CategoryCC.getDatafromParent(parent: service!.service_id)
  78. if serviceChilds.count > 0 {
  79. UIApplication.shared.visibleViewController?.view.makeToast("109:Invalid Contact Center category parameter".localized(), duration: 2)
  80. return
  81. }
  82. }
  83. }
  84. let isWaitingRequestCC = UserDefaults.standard.bool(forKey: "waitingRequestCC")
  85. if isWaitingRequestCC {
  86. let imageView = UIImageView(image: UIImage(systemName: "info.circle"))
  87. imageView.tintColor = .white
  88. let banner = FloatingNotificationBanner(title: "You have requested Call Center, please wait for response.".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .info, colors: nil, iconPosition: .center)
  89. banner.show()
  90. return
  91. }
  92. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  93. controller.isContactCenter = true
  94. if media != nil {
  95. controller.isDirectCC = true
  96. controller.channelContactCenter = "\(media!)"
  97. controller.serviceIdCC = category == nil ? "" : "\(category!)"
  98. }
  99. let navigationController = UINavigationController(rootViewController: controller)
  100. navigationController.defaultStyle()
  101. if UIApplication.shared.visibleViewController?.navigationController != nil {
  102. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  103. } else {
  104. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  105. }
  106. }
  107. }
  108. public static func openUrl(url: String) {
  109. let isChangeProfile = Utils.getSetProfile()
  110. if !isChangeProfile {
  111. APIS.showChangeProfile()
  112. return
  113. }
  114. let controller = BNIBookingWebView()
  115. controller.customUrl = url
  116. if UIApplication.shared.visibleViewController?.navigationController != nil {
  117. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  118. } else {
  119. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  120. }
  121. }
  122. public static func openNotificationCenter() {
  123. let isChangeProfile = Utils.getSetProfile()
  124. if !isChangeProfile {
  125. APIS.showChangeProfile()
  126. return
  127. }
  128. let controller = HistoryBroadcastViewController()
  129. let navigationController = UINavigationController(rootViewController: controller)
  130. navigationController.defaultStyle()
  131. if UIApplication.shared.visibleViewController?.navigationController != nil {
  132. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  133. } else {
  134. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  135. }
  136. }
  137. public static func openChat() {
  138. let isChangeProfile = Utils.getSetProfile()
  139. if !isChangeProfile {
  140. APIS.showChangeProfile()
  141. return
  142. }
  143. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
  144. let vc = navigationController.topViewController as! ContactChatViewController
  145. vc.noUCList = true
  146. navigationController.defaultStyle()
  147. if UIApplication.shared.visibleViewController?.navigationController != nil {
  148. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  149. } else {
  150. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  151. }
  152. }
  153. public static func openSmartChatbot() {
  154. let isChangeProfile = Utils.getSetProfile()
  155. if !isChangeProfile {
  156. APIS.showChangeProfile()
  157. return
  158. }
  159. let smartChatVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "chatGptVC") as! ChatGPTBotView
  160. smartChatVC.hidesBottomBarWhenPushed = true
  161. let navigationController = UINavigationController(rootViewController: smartChatVC)
  162. navigationController.modalPresentationStyle = .fullScreen
  163. navigationController.navigationBar.tintColor = .white
  164. navigationController.navigationBar.barTintColor = .mainColor
  165. navigationController.navigationBar.isTranslucent = false
  166. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  167. navigationController.navigationBar.barStyle = .black
  168. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  169. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  170. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  171. navigationController.navigationBar.titleTextAttributes = textAttributes
  172. navigationController.view.backgroundColor = .mainColor
  173. if UIApplication.shared.visibleViewController?.navigationController != nil {
  174. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  175. } else {
  176. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  177. }
  178. }
  179. public static func startChat(name: String) {
  180. if name.isEmpty {
  181. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  182. return
  183. }
  184. let user = User.getDataFromNameCanNil(name: name)
  185. if user == nil {
  186. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  187. return
  188. }
  189. let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  190. editorPersonalVC.hidesBottomBarWhenPushed = true
  191. editorPersonalVC.unique_l_pin = user!.pin
  192. editorPersonalVC.fromNotification = true
  193. let navigationController = UINavigationController(rootViewController: editorPersonalVC)
  194. navigationController.modalPresentationStyle = .fullScreen
  195. navigationController.navigationBar.tintColor = .white
  196. navigationController.navigationBar.barTintColor = .mainColor
  197. navigationController.navigationBar.isTranslucent = false
  198. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  199. navigationController.navigationBar.barStyle = .black
  200. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  201. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  202. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  203. navigationController.navigationBar.titleTextAttributes = textAttributes
  204. navigationController.view.backgroundColor = .mainColor
  205. if UIApplication.shared.visibleViewController?.navigationController != nil {
  206. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  207. } else {
  208. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  209. }
  210. }
  211. public static func openCall() {
  212. let isChangeProfile = Utils.getSetProfile()
  213. if !isChangeProfile {
  214. APIS.showChangeProfile()
  215. return
  216. }
  217. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID")
  218. let navigationController = UINavigationController(rootViewController: callContact)
  219. navigationController.defaultStyle()
  220. if UIApplication.shared.visibleViewController?.navigationController != nil {
  221. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  222. } else {
  223. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  224. }
  225. }
  226. public static func openStreaming() {
  227. let isChangeProfile = Utils.getSetProfile()
  228. if !isChangeProfile {
  229. APIS.showChangeProfile()
  230. return
  231. }
  232. let navigationController = UINavigationController(rootViewController: QmeraCreateStreamingViewController())
  233. navigationController.defaultStyle()
  234. if UIApplication.shared.visibleViewController?.navigationController != nil {
  235. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  236. } else {
  237. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  238. }
  239. }
  240. // public static func openSeminar() {
  241. // let isChangeProfile = Utils.getSetProfile()
  242. // if !isChangeProfile {
  243. // APIS.showChangeProfile()
  244. // return
  245. // }
  246. // let navigationController = UINavigationController(rootViewController: CreateSeminarViewController())
  247. // navigationController.defaultStyle()
  248. // if UIApplication.shared.visibleViewController?.navigationController != nil {
  249. // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  250. // } else {
  251. // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  252. // }
  253. // }
  254. public static func openAudioCall() {
  255. let isChangeProfile = Utils.getSetProfile()
  256. if !isChangeProfile {
  257. APIS.showChangeProfile()
  258. return
  259. }
  260. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  261. callContact.onlyAudioOrVideo = 1
  262. let navigationController = UINavigationController(rootViewController: callContact)
  263. navigationController.defaultStyle()
  264. if UIApplication.shared.visibleViewController?.navigationController != nil {
  265. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  266. } else {
  267. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  268. }
  269. }
  270. public static func startAudioCall(name: String) {
  271. if name.isEmpty {
  272. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  273. return
  274. }
  275. let user = User.getDataFromNameCanNil(name: name)
  276. if user == nil {
  277. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  278. return
  279. }
  280. if !CheckConnection.isConnectedToNetwork() {
  281. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  282. imageView.tintColor = .white
  283. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  284. banner.show()
  285. return
  286. }
  287. let controller = QmeraAudioViewController()
  288. controller.user = user
  289. controller.isOutgoing = true
  290. controller.modalPresentationStyle = .overFullScreen
  291. if UIApplication.shared.visibleViewController?.navigationController != nil {
  292. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  293. } else {
  294. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  295. }
  296. }
  297. public static func openVideoCall() {
  298. let isChangeProfile = Utils.getSetProfile()
  299. if !isChangeProfile {
  300. APIS.showChangeProfile()
  301. return
  302. }
  303. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  304. callContact.onlyAudioOrVideo = 2
  305. let navigationController = UINavigationController(rootViewController: callContact)
  306. navigationController.defaultStyle()
  307. if UIApplication.shared.visibleViewController?.navigationController != nil {
  308. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  309. } else {
  310. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  311. }
  312. }
  313. public static func startVideoCall(name: String) {
  314. if name.isEmpty {
  315. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  316. return
  317. }
  318. let user = User.getDataFromNameCanNil(name: name)
  319. if user == nil {
  320. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  321. return
  322. }
  323. if !CheckConnection.isConnectedToNetwork() {
  324. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  325. imageView.tintColor = .white
  326. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  327. banner.show()
  328. return
  329. }
  330. let videoVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "videoVCQmera") as! QmeraVideoViewController
  331. var data: [String: String?] = [:]
  332. data["f_pin"] = user!.pin
  333. data["name"] = user!.fullName
  334. data["picture"] = user!.thumb
  335. data["isOfficial"] = user!.official
  336. data["deviceId"] = user!.device_id
  337. data["isOffline"] = user!.offline_mode
  338. data["user_type"] = user!.userType
  339. videoVC.dataPerson.append(data)
  340. videoVC.isPresent = true
  341. videoVC.modalPresentationStyle = .overFullScreen
  342. if UIApplication.shared.visibleViewController?.navigationController != nil {
  343. UIApplication.shared.visibleViewController?.navigationController?.present(videoVC, animated: true, completion: nil)
  344. } else {
  345. UIApplication.shared.visibleViewController?.present(videoVC, animated: true, completion: nil)
  346. }
  347. }
  348. public static func openBroadcastForm() {
  349. let isChangeProfile = Utils.getSetProfile()
  350. if !isChangeProfile {
  351. APIS.showChangeProfile()
  352. return
  353. }
  354. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "broadcastNav")
  355. if UIApplication.shared.visibleViewController?.navigationController != nil {
  356. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  357. } else {
  358. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  359. }
  360. }
  361. public static func startConversation() {
  362. let isChangeProfile = Utils.getSetProfile()
  363. if !isChangeProfile {
  364. APIS.showChangeProfile()
  365. return
  366. }
  367. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
  368. navigationController.defaultStyle()
  369. if UIApplication.shared.visibleViewController?.navigationController != nil {
  370. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  371. } else {
  372. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  373. }
  374. }
  375. public static func openFavoriteMessage() {
  376. let isChangeProfile = Utils.getSetProfile()
  377. if !isChangeProfile {
  378. APIS.showChangeProfile()
  379. return
  380. }
  381. let editorStaredVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "staredVC") as! EditorStarMessages
  382. editorStaredVC.fromNotification = true
  383. let navigationController = UINavigationController(rootViewController: editorStaredVC)
  384. navigationController.defaultStyle()
  385. if UIApplication.shared.visibleViewController?.navigationController != nil {
  386. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  387. } else {
  388. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  389. }
  390. }
  391. public static func openCreateGroup() {
  392. let isChangeProfile = Utils.getSetProfile()
  393. if !isChangeProfile {
  394. APIS.showChangeProfile()
  395. return
  396. }
  397. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "createGroupNav") as! UINavigationController
  398. let vc = controller.topViewController as! GroupCreateViewController
  399. vc.isDismiss = { id in
  400. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "groupDetailView") as! GroupDetailViewController
  401. controller.data = id
  402. controller.fromNotification = true
  403. let navigationController = UINavigationController(rootViewController: controller)
  404. navigationController.defaultStyle()
  405. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  406. if UIApplication.shared.visibleViewController?.navigationController != nil {
  407. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  408. } else {
  409. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  410. }
  411. })
  412. }
  413. controller.defaultStyle()
  414. if UIApplication.shared.visibleViewController?.navigationController != nil {
  415. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  416. } else {
  417. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  418. }
  419. }
  420. public static func openAddFriend() {
  421. let isChangeProfile = Utils.getSetProfile()
  422. if !isChangeProfile {
  423. APIS.showChangeProfile()
  424. return
  425. }
  426. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "addFriendNav") as! UINavigationController
  427. controller.defaultStyle()
  428. if UIApplication.shared.visibleViewController?.navigationController != nil {
  429. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  430. } else {
  431. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  432. }
  433. }
  434. public static func openSignUpOrSignIn() {
  435. let isChangeProfile = Utils.getSetProfile()
  436. if !isChangeProfile {
  437. APIS.showChangeProfile()
  438. return
  439. }
  440. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
  441. controller.forceLogin = true
  442. let navigationController = UINavigationController(rootViewController: controller)
  443. navigationController.defaultStyle()
  444. if UIApplication.shared.visibleViewController?.navigationController != nil {
  445. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  446. } else {
  447. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  448. }
  449. }
  450. public static func openSetting() {
  451. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
  452. navigationController.defaultStyle()
  453. if UIApplication.shared.visibleViewController?.navigationController != nil {
  454. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  455. } else {
  456. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  457. }
  458. }
  459. public static func openProfile() {
  460. let isChangeProfile = Utils.getSetProfile()
  461. if !isChangeProfile {
  462. APIS.showChangeProfile()
  463. return
  464. }
  465. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
  466. controller.data = UserDefaults.standard.string(forKey: "me")!
  467. controller.flag = .me
  468. controller.dismissImage = { image, imageName in
  469. var dataImage: [AnyHashable : Any] = [:]
  470. dataImage["name"] = imageName
  471. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  472. }
  473. let navigationController = UINavigationController(rootViewController: controller)
  474. navigationController.defaultStyle()
  475. if UIApplication.shared.visibleViewController?.navigationController != nil {
  476. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  477. } else {
  478. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  479. }
  480. }
  481. public static func openWhiteboard() {
  482. let isChangeProfile = Utils.getSetProfile()
  483. if !isChangeProfile {
  484. APIS.showChangeProfile()
  485. return
  486. }
  487. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  488. callContact.startWhiteBoard = true
  489. let navigationController = UINavigationController(rootViewController: callContact)
  490. navigationController.defaultStyle()
  491. if UIApplication.shared.visibleViewController?.navigationController != nil {
  492. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  493. } else {
  494. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  495. }
  496. }
  497. public static func startWhiteboard(name: String) {
  498. if name.isEmpty {
  499. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  500. return
  501. }
  502. let user = User.getDataFromNameCanNil(name: name)
  503. if user == nil {
  504. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  505. return
  506. }
  507. if !CheckConnection.isConnectedToNetwork() {
  508. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  509. imageView.tintColor = .white
  510. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  511. banner.show()
  512. return
  513. }
  514. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "wbVC") as! WhiteboardViewController
  515. controller.modalPresentationStyle = .overFullScreen
  516. controller.fromContact = 0
  517. controller.user = user
  518. if UIApplication.shared.visibleViewController?.navigationController != nil {
  519. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  520. } else {
  521. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  522. }
  523. }
  524. // public static func openScreenSharing() {
  525. // let isChangeProfile = Utils.getSetProfile()
  526. // if !isChangeProfile {
  527. // APIS.showChangeProfile()
  528. // return
  529. // }
  530. // let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  531. // callContact.startSS = true
  532. // let navigationController = UINavigationController(rootViewController: callContact)
  533. // navigationController.defaultStyle()
  534. // if UIApplication.shared.visibleViewController?.navigationController != nil {
  535. // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  536. // } else {
  537. // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  538. // }
  539. // }
  540. public static func startScreenSharing(name: String) {
  541. if name.isEmpty {
  542. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  543. return
  544. }
  545. let user = User.getDataFromNameCanNil(name: name)
  546. if user == nil {
  547. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  548. return
  549. }
  550. if !CheckConnection.isConnectedToNetwork() {
  551. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  552. imageView.tintColor = .white
  553. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  554. banner.show()
  555. return
  556. }
  557. let controller = ScreenSharingViewController()
  558. controller.modalPresentationStyle = .overFullScreen
  559. controller.fromContact = 0
  560. controller.user = user
  561. if UIApplication.shared.visibleViewController?.navigationController != nil {
  562. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  563. } else {
  564. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  565. }
  566. }
  567. public static func openWhiteboardAndScreenSharing() {
  568. let isChangeProfile = Utils.getSetProfile()
  569. if !isChangeProfile {
  570. APIS.showChangeProfile()
  571. return
  572. }
  573. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  574. callContact.startSS = true
  575. callContact.startWhiteBoard = true
  576. let navigationController = UINavigationController(rootViewController: callContact)
  577. navigationController.defaultStyle()
  578. if UIApplication.shared.visibleViewController?.navigationController != nil {
  579. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  580. } else {
  581. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  582. }
  583. }
  584. public static func signInAdmin(password: String) {
  585. if password.isEmpty {
  586. UIApplication.shared.visibleViewController?.view.makeToast("113:Password is empty".localized(), duration: 2)
  587. return
  588. }
  589. let isChangeProfile = Utils.getSetProfile()
  590. if !isChangeProfile {
  591. APIS.showChangeProfile()
  592. return
  593. }
  594. let isAdmin = User.isAdmin()
  595. if isAdmin {
  596. UIApplication.shared.visibleViewController?.view.makeToast("112:You already login or registered as Admin".localized(), duration: 2)
  597. return
  598. }
  599. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  600. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  601. imageView.tintColor = .white
  602. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  603. banner.show()
  604. return
  605. }
  606. Nexilis.showLoader()
  607. self.signInAdmin(password: password, completion: { result in
  608. if result {
  609. DispatchQueue.main.async {
  610. Nexilis.hideLoader {
  611. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  612. imageView.tintColor = .white
  613. let banner = FloatingNotificationBanner(title: "Successfully Sign-In Admin".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
  614. banner.show()
  615. }
  616. }
  617. } else {
  618. DispatchQueue.main.async {
  619. Nexilis.hideLoader {}
  620. }
  621. }
  622. })
  623. }
  624. private static func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
  625. DispatchQueue.global().async {
  626. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  627. let p_password = password
  628. let md5Hex = p_password
  629. var result: Bool = false
  630. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
  631. if response.isOk() {
  632. result = true
  633. }
  634. DispatchQueue.main.async {
  635. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  636. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  637. imageView.tintColor = .white
  638. let banner = FloatingNotificationBanner(title: "Username or password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
  639. banner.show()
  640. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  641. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  642. imageView.tintColor = .white
  643. let banner = FloatingNotificationBanner(title: "Invalid password".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
  644. banner.show()
  645. }
  646. }
  647. } else {
  648. DispatchQueue.main.async {
  649. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  650. imageView.tintColor = .white
  651. let banner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .top)
  652. banner.show()
  653. }
  654. }
  655. completion(result)
  656. }
  657. }
  658. public static func openSetAsOfficerForm() {
  659. let isChangeProfile = Utils.getSetProfile()
  660. if !isChangeProfile {
  661. APIS.showChangeProfile()
  662. return
  663. }
  664. let isAdmin = User.isAdmin()
  665. if !isAdmin {
  666. UIApplication.shared.visibleViewController?.view.makeToast("111:You must Sign In as Admin to use this feature".localized(), duration: 2)
  667. return
  668. }
  669. let controller = SetInternalCSAccount()
  670. controller.isSetCS = true
  671. controller.fromNotification = true
  672. let navigationController = UINavigationController(rootViewController: controller)
  673. navigationController.defaultStyle()
  674. if UIApplication.shared.visibleViewController?.navigationController != nil {
  675. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  676. } else {
  677. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  678. }
  679. }
  680. public static func sendWhatsapp(message: String) {
  681. var urlString = message
  682. var urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
  683. var url = NSURL(string: "whatsapp://send?text=\(urlStringEncoded!)")
  684. if UIApplication.shared.canOpenURL(url! as URL) {
  685. UIApplication.shared.open(url! as URL, options: [:]) { (success) in
  686. if success {
  687. //print("WhatsApp accessed successfully")
  688. } else {
  689. //print("Error accessing WhatsApp")
  690. }
  691. }
  692. }
  693. }
  694. public static func openMail() {
  695. Nexilis.openmailAction()
  696. }
  697. }
  698. extension UINavigationController {
  699. func defaultStyle() {
  700. self.modalPresentationStyle = .fullScreen
  701. self.navigationBar.tintColor = .white
  702. self.navigationBar.barTintColor = .mainColor
  703. self.navigationBar.isTranslucent = false
  704. self.navigationBar.overrideUserInterfaceStyle = .dark
  705. self.navigationBar.barStyle = .black
  706. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  707. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  708. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  709. self.navigationBar.titleTextAttributes = textAttributes
  710. self.view.backgroundColor = .mainColor
  711. }
  712. }