APIS.swift 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. //
  2. // APIS.swift
  3. // DigiXLite
  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. DigiX.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 startChat(name: String) {
  154. if name.isEmpty {
  155. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  156. return
  157. }
  158. let user = User.getDataFromNameCanNil(name: name)
  159. if user == nil {
  160. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  161. return
  162. }
  163. let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  164. editorPersonalVC.hidesBottomBarWhenPushed = true
  165. editorPersonalVC.unique_l_pin = user!.pin
  166. editorPersonalVC.fromNotification = true
  167. let navigationController = UINavigationController(rootViewController: editorPersonalVC)
  168. navigationController.modalPresentationStyle = .fullScreen
  169. navigationController.navigationBar.tintColor = .white
  170. navigationController.navigationBar.barTintColor = .mainColor
  171. navigationController.navigationBar.isTranslucent = false
  172. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  173. navigationController.navigationBar.barStyle = .black
  174. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  175. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  176. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  177. navigationController.navigationBar.titleTextAttributes = textAttributes
  178. navigationController.view.backgroundColor = .mainColor
  179. if UIApplication.shared.visibleViewController?.navigationController != nil {
  180. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  181. } else {
  182. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  183. }
  184. }
  185. public static func openCall() {
  186. let isChangeProfile = Utils.getSetProfile()
  187. if !isChangeProfile {
  188. APIS.showChangeProfile()
  189. return
  190. }
  191. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID")
  192. let navigationController = UINavigationController(rootViewController: callContact)
  193. navigationController.defaultStyle()
  194. if UIApplication.shared.visibleViewController?.navigationController != nil {
  195. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  196. } else {
  197. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  198. }
  199. }
  200. public static func openStreaming() {
  201. let isChangeProfile = Utils.getSetProfile()
  202. if !isChangeProfile {
  203. APIS.showChangeProfile()
  204. return
  205. }
  206. let navigationController = UINavigationController(rootViewController: QmeraCreateStreamingViewController())
  207. navigationController.defaultStyle()
  208. if UIApplication.shared.visibleViewController?.navigationController != nil {
  209. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  210. } else {
  211. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  212. }
  213. }
  214. // public static func openSeminar() {
  215. // let isChangeProfile = Utils.getSetProfile()
  216. // if !isChangeProfile {
  217. // APIS.showChangeProfile()
  218. // return
  219. // }
  220. // let navigationController = UINavigationController(rootViewController: CreateSeminarViewController())
  221. // navigationController.defaultStyle()
  222. // if UIApplication.shared.visibleViewController?.navigationController != nil {
  223. // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  224. // } else {
  225. // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  226. // }
  227. // }
  228. public static func openAudioCall() {
  229. let isChangeProfile = Utils.getSetProfile()
  230. if !isChangeProfile {
  231. APIS.showChangeProfile()
  232. return
  233. }
  234. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  235. callContact.onlyAudioOrVideo = 1
  236. let navigationController = UINavigationController(rootViewController: callContact)
  237. navigationController.defaultStyle()
  238. if UIApplication.shared.visibleViewController?.navigationController != nil {
  239. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  240. } else {
  241. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  242. }
  243. }
  244. public static func startAudioCall(name: String) {
  245. if name.isEmpty {
  246. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  247. return
  248. }
  249. let user = User.getDataFromNameCanNil(name: name)
  250. if user == nil {
  251. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  252. return
  253. }
  254. if !CheckConnection.isConnectedToNetwork() {
  255. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  256. imageView.tintColor = .white
  257. 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)
  258. banner.show()
  259. return
  260. }
  261. let controller = QmeraAudioViewController()
  262. controller.user = user
  263. controller.isOutgoing = true
  264. controller.modalPresentationStyle = .overFullScreen
  265. if UIApplication.shared.visibleViewController?.navigationController != nil {
  266. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  267. } else {
  268. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  269. }
  270. }
  271. public static func openVideoCall() {
  272. let isChangeProfile = Utils.getSetProfile()
  273. if !isChangeProfile {
  274. APIS.showChangeProfile()
  275. return
  276. }
  277. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  278. callContact.onlyAudioOrVideo = 2
  279. let navigationController = UINavigationController(rootViewController: callContact)
  280. navigationController.defaultStyle()
  281. if UIApplication.shared.visibleViewController?.navigationController != nil {
  282. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  283. } else {
  284. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  285. }
  286. }
  287. public static func startVideoCall(name: String) {
  288. if name.isEmpty {
  289. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  290. return
  291. }
  292. let user = User.getDataFromNameCanNil(name: name)
  293. if user == nil {
  294. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  295. return
  296. }
  297. if !CheckConnection.isConnectedToNetwork() {
  298. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  299. imageView.tintColor = .white
  300. 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)
  301. banner.show()
  302. return
  303. }
  304. let videoVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "videoVCQmera") as! QmeraVideoViewController
  305. var data: [String: String?] = [:]
  306. data["f_pin"] = user!.pin
  307. data["name"] = user!.fullName
  308. data["picture"] = user!.thumb
  309. data["isOfficial"] = user!.official
  310. data["deviceId"] = user!.device_id
  311. data["isOffline"] = user!.offline_mode
  312. data["user_type"] = user!.userType
  313. videoVC.dataPerson.append(data)
  314. videoVC.isPresent = true
  315. videoVC.modalPresentationStyle = .overFullScreen
  316. if UIApplication.shared.visibleViewController?.navigationController != nil {
  317. UIApplication.shared.visibleViewController?.navigationController?.present(videoVC, animated: true, completion: nil)
  318. } else {
  319. UIApplication.shared.visibleViewController?.present(videoVC, animated: true, completion: nil)
  320. }
  321. }
  322. public static func openBroadcastForm() {
  323. let isChangeProfile = Utils.getSetProfile()
  324. if !isChangeProfile {
  325. APIS.showChangeProfile()
  326. return
  327. }
  328. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "broadcastNav")
  329. if UIApplication.shared.visibleViewController?.navigationController != nil {
  330. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  331. } else {
  332. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  333. }
  334. }
  335. public static func startConversation() {
  336. let isChangeProfile = Utils.getSetProfile()
  337. if !isChangeProfile {
  338. APIS.showChangeProfile()
  339. return
  340. }
  341. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
  342. navigationController.defaultStyle()
  343. if UIApplication.shared.visibleViewController?.navigationController != nil {
  344. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  345. } else {
  346. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  347. }
  348. }
  349. public static func openFavoriteMessage() {
  350. let isChangeProfile = Utils.getSetProfile()
  351. if !isChangeProfile {
  352. APIS.showChangeProfile()
  353. return
  354. }
  355. let editorStaredVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "staredVC") as! EditorStarMessages
  356. editorStaredVC.fromNotification = true
  357. let navigationController = UINavigationController(rootViewController: editorStaredVC)
  358. navigationController.defaultStyle()
  359. if UIApplication.shared.visibleViewController?.navigationController != nil {
  360. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  361. } else {
  362. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  363. }
  364. }
  365. public static func openCreateGroup() {
  366. let isChangeProfile = Utils.getSetProfile()
  367. if !isChangeProfile {
  368. APIS.showChangeProfile()
  369. return
  370. }
  371. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "createGroupNav") as! UINavigationController
  372. let vc = controller.topViewController as! GroupCreateViewController
  373. vc.isDismiss = { id in
  374. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "groupDetailView") as! GroupDetailViewController
  375. controller.data = id
  376. controller.fromNotification = true
  377. let navigationController = UINavigationController(rootViewController: controller)
  378. navigationController.defaultStyle()
  379. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  380. if UIApplication.shared.visibleViewController?.navigationController != nil {
  381. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  382. } else {
  383. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  384. }
  385. })
  386. }
  387. controller.defaultStyle()
  388. if UIApplication.shared.visibleViewController?.navigationController != nil {
  389. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  390. } else {
  391. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  392. }
  393. }
  394. public static func openAddFriend() {
  395. let isChangeProfile = Utils.getSetProfile()
  396. if !isChangeProfile {
  397. APIS.showChangeProfile()
  398. return
  399. }
  400. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "addFriendNav") as! UINavigationController
  401. controller.defaultStyle()
  402. if UIApplication.shared.visibleViewController?.navigationController != nil {
  403. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  404. } else {
  405. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  406. }
  407. }
  408. public static func openSignUpOrSignIn() {
  409. let isChangeProfile = Utils.getSetProfile()
  410. if !isChangeProfile {
  411. APIS.showChangeProfile()
  412. return
  413. }
  414. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
  415. controller.forceLogin = true
  416. let navigationController = UINavigationController(rootViewController: controller)
  417. navigationController.defaultStyle()
  418. if UIApplication.shared.visibleViewController?.navigationController != nil {
  419. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  420. } else {
  421. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  422. }
  423. }
  424. public static func openSetting() {
  425. let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
  426. navigationController.defaultStyle()
  427. if UIApplication.shared.visibleViewController?.navigationController != nil {
  428. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  429. } else {
  430. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  431. }
  432. }
  433. public static func openProfile() {
  434. let isChangeProfile = Utils.getSetProfile()
  435. if !isChangeProfile {
  436. APIS.showChangeProfile()
  437. return
  438. }
  439. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
  440. controller.data = UserDefaults.standard.string(forKey: "me")!
  441. controller.flag = .me
  442. controller.dismissImage = { image, imageName in
  443. var dataImage: [AnyHashable : Any] = [:]
  444. dataImage["name"] = imageName
  445. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  446. }
  447. let navigationController = UINavigationController(rootViewController: controller)
  448. navigationController.defaultStyle()
  449. if UIApplication.shared.visibleViewController?.navigationController != nil {
  450. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  451. } else {
  452. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  453. }
  454. }
  455. public static func openWhiteboard() {
  456. let isChangeProfile = Utils.getSetProfile()
  457. if !isChangeProfile {
  458. APIS.showChangeProfile()
  459. return
  460. }
  461. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  462. callContact.startWhiteBoard = true
  463. let navigationController = UINavigationController(rootViewController: callContact)
  464. navigationController.defaultStyle()
  465. if UIApplication.shared.visibleViewController?.navigationController != nil {
  466. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  467. } else {
  468. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  469. }
  470. }
  471. public static func startWhiteboard(name: String) {
  472. if name.isEmpty {
  473. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  474. return
  475. }
  476. let user = User.getDataFromNameCanNil(name: name)
  477. if user == nil {
  478. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  479. return
  480. }
  481. if !CheckConnection.isConnectedToNetwork() {
  482. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  483. imageView.tintColor = .white
  484. 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)
  485. banner.show()
  486. return
  487. }
  488. let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "wbVC") as! WhiteboardViewController
  489. controller.modalPresentationStyle = .overFullScreen
  490. controller.fromContact = 0
  491. controller.user = user
  492. if UIApplication.shared.visibleViewController?.navigationController != nil {
  493. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  494. } else {
  495. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  496. }
  497. }
  498. // public static func openScreenSharing() {
  499. // let isChangeProfile = Utils.getSetProfile()
  500. // if !isChangeProfile {
  501. // APIS.showChangeProfile()
  502. // return
  503. // }
  504. // let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  505. // callContact.startSS = true
  506. // let navigationController = UINavigationController(rootViewController: callContact)
  507. // navigationController.defaultStyle()
  508. // if UIApplication.shared.visibleViewController?.navigationController != nil {
  509. // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  510. // } else {
  511. // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  512. // }
  513. // }
  514. public static func startScreenSharing(name: String) {
  515. if name.isEmpty {
  516. UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
  517. return
  518. }
  519. let user = User.getDataFromNameCanNil(name: name)
  520. if user == nil {
  521. UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
  522. return
  523. }
  524. if !CheckConnection.isConnectedToNetwork() {
  525. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  526. imageView.tintColor = .white
  527. 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)
  528. banner.show()
  529. return
  530. }
  531. let controller = ScreenSharingViewController()
  532. controller.modalPresentationStyle = .overFullScreen
  533. controller.fromContact = 0
  534. controller.user = user
  535. if UIApplication.shared.visibleViewController?.navigationController != nil {
  536. UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
  537. } else {
  538. UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
  539. }
  540. }
  541. public static func openWhiteboardAndScreenSharing() {
  542. let isChangeProfile = Utils.getSetProfile()
  543. if !isChangeProfile {
  544. APIS.showChangeProfile()
  545. return
  546. }
  547. let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
  548. callContact.startSS = true
  549. callContact.startWhiteBoard = true
  550. let navigationController = UINavigationController(rootViewController: callContact)
  551. navigationController.defaultStyle()
  552. if UIApplication.shared.visibleViewController?.navigationController != nil {
  553. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  554. } else {
  555. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  556. }
  557. }
  558. public static func signInAdmin(password: String) {
  559. if password.isEmpty {
  560. UIApplication.shared.visibleViewController?.view.makeToast("113:Password is empty".localized(), duration: 2)
  561. return
  562. }
  563. let isChangeProfile = Utils.getSetProfile()
  564. if !isChangeProfile {
  565. APIS.showChangeProfile()
  566. return
  567. }
  568. let isAdmin = User.isAdmin()
  569. if isAdmin {
  570. UIApplication.shared.visibleViewController?.view.makeToast("112:You already login or registered as Admin".localized(), duration: 2)
  571. return
  572. }
  573. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  574. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  575. imageView.tintColor = .white
  576. 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)
  577. banner.show()
  578. return
  579. }
  580. DigiX.showLoader()
  581. self.signInAdmin(password: password, completion: { result in
  582. if result {
  583. DispatchQueue.main.async {
  584. DigiX.hideLoader {
  585. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  586. imageView.tintColor = .white
  587. 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)
  588. banner.show()
  589. }
  590. }
  591. } else {
  592. DispatchQueue.main.async {
  593. DigiX.hideLoader {}
  594. }
  595. }
  596. })
  597. }
  598. private static func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
  599. DispatchQueue.global().async {
  600. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  601. let p_password = password
  602. let md5Hex = p_password
  603. var result: Bool = false
  604. if let response = DigiX.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
  605. if response.isOk() {
  606. result = true
  607. }
  608. DispatchQueue.main.async {
  609. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  610. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  611. imageView.tintColor = .white
  612. 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)
  613. banner.show()
  614. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  615. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  616. imageView.tintColor = .white
  617. 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)
  618. banner.show()
  619. }
  620. }
  621. } else {
  622. DispatchQueue.main.async {
  623. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  624. imageView.tintColor = .white
  625. 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)
  626. banner.show()
  627. }
  628. }
  629. completion(result)
  630. }
  631. }
  632. public static func openSetAsOfficerForm() {
  633. let isChangeProfile = Utils.getSetProfile()
  634. if !isChangeProfile {
  635. APIS.showChangeProfile()
  636. return
  637. }
  638. let isAdmin = User.isAdmin()
  639. if !isAdmin {
  640. UIApplication.shared.visibleViewController?.view.makeToast("111:You must Sign In as Admin to use this feature".localized(), duration: 2)
  641. return
  642. }
  643. let controller = SetInternalCSAccount()
  644. controller.isSetCS = true
  645. controller.fromNotification = true
  646. let navigationController = UINavigationController(rootViewController: controller)
  647. navigationController.defaultStyle()
  648. if UIApplication.shared.visibleViewController?.navigationController != nil {
  649. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  650. } else {
  651. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  652. }
  653. }
  654. }
  655. extension UINavigationController {
  656. func defaultStyle() {
  657. self.modalPresentationStyle = .fullScreen
  658. self.navigationBar.tintColor = .white
  659. self.navigationBar.barTintColor = .mainColor
  660. self.navigationBar.isTranslucent = false
  661. self.navigationBar.overrideUserInterfaceStyle = .dark
  662. self.navigationBar.barStyle = .black
  663. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  664. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  665. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  666. self.navigationBar.titleTextAttributes = textAttributes
  667. self.view.backgroundColor = .mainColor
  668. }
  669. }