123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702 |
- //
- // APIS.swift
- // DigiXLite
- //
- // Created by Akhmad Al Qindi Irsyam on 05/05/23.
- //
- import Foundation
- import UIKit
- import FMDB
- import NotificationBannerSwift
- import Toast_Swift
- import nuSDKService
- public class APIS: NSObject {
- public static func connect(apiKey: String, delegate: ConnectDelegate, showButton: Bool = true) {
- DigiX.connect(apiKey: apiKey, delegate: delegate, showButton: showButton)
- }
-
- public static func getTotalCounter() -> Int32 {
- var counter: Int32?
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
- counter = cursor.int(forColumnIndex: 0)
- cursor.close()
- }
- })
- return counter ?? 0
- }
-
- private static func showChangeProfile() {
- let alert = LibAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized(), preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
- controller.forceLogin = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }))
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
- }
- }
-
- public static func openContactCenter(media: Int? = nil, category: Int? = nil) {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- if User.isCallCenter(userType: (User.getData(pin: User.getMyPin())?.userType)!) {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "myHistoryCC") as! HistoryCCViewController
- controller.isOfficer = true
- controller.fromAPI = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- } else {
- if media != nil || (media == nil && category != nil) {
- if media == nil || media! < 0 || media! > 2 {
- UIApplication.shared.visibleViewController?.view.makeToast("108:Invalid Contact Center media parameter (0:Chat, 1:Audio Call, 2:Video Call)".localized(), duration: 2)
- return
- }
- }
- if category != nil {
- if category != 0 {
- let service = CategoryCC.getDataFromServiceId(service_id: "\(category!)")
- if service == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("109:Invalid Contact Center category parameter".localized(), duration: 2)
- return
- }
- let serviceChilds = CategoryCC.getDatafromParent(parent: service!.service_id)
- if serviceChilds.count > 0 {
- UIApplication.shared.visibleViewController?.view.makeToast("109:Invalid Contact Center category parameter".localized(), duration: 2)
- return
- }
- }
- }
- let isWaitingRequestCC = UserDefaults.standard.bool(forKey: "waitingRequestCC")
- if isWaitingRequestCC {
- let imageView = UIImageView(image: UIImage(systemName: "info.circle"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
- controller.isContactCenter = true
- if media != nil {
- controller.isDirectCC = true
- controller.channelContactCenter = "\(media!)"
- controller.serviceIdCC = category == nil ? "" : "\(category!)"
- }
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
- }
-
- public static func openUrl(url: String) {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = BNIBookingWebView()
- controller.customUrl = url
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func openNotificationCenter() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = HistoryBroadcastViewController()
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openChat() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
- let vc = navigationController.topViewController as! ContactChatViewController
- vc.noUCList = true
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func startChat(name: String) {
- if name.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
- return
- }
- let user = User.getDataFromNameCanNil(name: name)
- if user == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
- return
- }
- let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
- editorPersonalVC.hidesBottomBarWhenPushed = true
- editorPersonalVC.unique_l_pin = user!.pin
- editorPersonalVC.fromNotification = true
- let navigationController = UINavigationController(rootViewController: editorPersonalVC)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openCall() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID")
- let navigationController = UINavigationController(rootViewController: callContact)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openStreaming() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let navigationController = UINavigationController(rootViewController: QmeraCreateStreamingViewController())
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- // public static func openSeminar() {
- // let isChangeProfile = Utils.getSetProfile()
- // if !isChangeProfile {
- // APIS.showChangeProfile()
- // return
- // }
- // let navigationController = UINavigationController(rootViewController: CreateSeminarViewController())
- // navigationController.defaultStyle()
- // if UIApplication.shared.visibleViewController?.navigationController != nil {
- // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- // } else {
- // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- // }
- // }
-
- public static func openAudioCall() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
- callContact.onlyAudioOrVideo = 1
- let navigationController = UINavigationController(rootViewController: callContact)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func startAudioCall(name: String) {
- if name.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
- return
- }
- let user = User.getDataFromNameCanNil(name: name)
- if user == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let controller = QmeraAudioViewController()
- controller.user = user
- controller.isOutgoing = true
- controller.modalPresentationStyle = .overFullScreen
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func openVideoCall() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
- callContact.onlyAudioOrVideo = 2
- let navigationController = UINavigationController(rootViewController: callContact)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func startVideoCall(name: String) {
- if name.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
- return
- }
- let user = User.getDataFromNameCanNil(name: name)
- if user == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let videoVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "videoVCQmera") as! QmeraVideoViewController
- var data: [String: String?] = [:]
- data["f_pin"] = user!.pin
- data["name"] = user!.fullName
- data["picture"] = user!.thumb
- data["isOfficial"] = user!.official
- data["deviceId"] = user!.device_id
- data["isOffline"] = user!.offline_mode
- data["user_type"] = user!.userType
- videoVC.dataPerson.append(data)
- videoVC.isPresent = true
- videoVC.modalPresentationStyle = .overFullScreen
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(videoVC, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(videoVC, animated: true, completion: nil)
- }
- }
-
- public static func openBroadcastForm() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "broadcastNav")
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func startConversation() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openFavoriteMessage() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let editorStaredVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "staredVC") as! EditorStarMessages
- editorStaredVC.fromNotification = true
- let navigationController = UINavigationController(rootViewController: editorStaredVC)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openCreateGroup() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "createGroupNav") as! UINavigationController
- let vc = controller.topViewController as! GroupCreateViewController
- vc.isDismiss = { id in
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "groupDetailView") as! GroupDetailViewController
- controller.data = id
- controller.fromNotification = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- })
- }
- controller.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func openAddFriend() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "addFriendNav") as! UINavigationController
- controller.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func openSignUpOrSignIn() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
- controller.forceLogin = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openSetting() {
- let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "settingNav") as! UINavigationController
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openProfile() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
- controller.data = UserDefaults.standard.string(forKey: "me")!
- controller.flag = .me
- controller.dismissImage = { image, imageName in
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageName
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- }
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func openWhiteboard() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
- callContact.startWhiteBoard = true
- let navigationController = UINavigationController(rootViewController: callContact)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func startWhiteboard(name: String) {
- if name.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
- return
- }
- let user = User.getDataFromNameCanNil(name: name)
- if user == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "wbVC") as! WhiteboardViewController
- controller.modalPresentationStyle = .overFullScreen
- controller.fromContact = 0
- controller.user = user
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- // public static func openScreenSharing() {
- // let isChangeProfile = Utils.getSetProfile()
- // if !isChangeProfile {
- // APIS.showChangeProfile()
- // return
- // }
- // let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
- // callContact.startSS = true
- // let navigationController = UINavigationController(rootViewController: callContact)
- // navigationController.defaultStyle()
- // if UIApplication.shared.visibleViewController?.navigationController != nil {
- // UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- // } else {
- // UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- // }
- // }
-
- public static func startScreenSharing(name: String) {
- if name.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("92:Username is empty".localized(), duration: 2)
- return
- }
- let user = User.getDataFromNameCanNil(name: name)
- if user == nil {
- UIApplication.shared.visibleViewController?.view.makeToast("91:Invalid name or you must add Username to your contact first".localized(), duration: 2)
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let controller = ScreenSharingViewController()
- controller.modalPresentationStyle = .overFullScreen
- controller.fromContact = 0
- controller.user = user
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(controller, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(controller, animated: true, completion: nil)
- }
- }
-
- public static func openWhiteboardAndScreenSharing() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let callContact = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactSID") as! ContactCallViewController
- callContact.startSS = true
- callContact.startWhiteBoard = true
- let navigationController = UINavigationController(rootViewController: callContact)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- public static func signInAdmin(password: String) {
- if password.isEmpty {
- UIApplication.shared.visibleViewController?.view.makeToast("113:Password is empty".localized(), duration: 2)
- return
- }
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let isAdmin = User.isAdmin()
- if isAdmin {
- UIApplication.shared.visibleViewController?.view.makeToast("112:You already login or registered as Admin".localized(), duration: 2)
- return
- }
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- DigiX.showLoader()
- self.signInAdmin(password: password, completion: { result in
- if result {
- DispatchQueue.main.async {
- DigiX.hideLoader {
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- DigiX.hideLoader {}
- }
- }
- })
- }
-
- private static func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- let p_password = password
- let md5Hex = p_password
- var result: Bool = false
- if let response = DigiX.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
- if response.isOk() {
- result = true
- }
- DispatchQueue.main.async {
- if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- completion(result)
- }
- }
-
- public static func openSetAsOfficerForm() {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- APIS.showChangeProfile()
- return
- }
- let isAdmin = User.isAdmin()
- if !isAdmin {
- UIApplication.shared.visibleViewController?.view.makeToast("111:You must Sign In as Admin to use this feature".localized(), duration: 2)
- return
- }
- let controller = SetInternalCSAccount()
- controller.isSetCS = true
- controller.fromNotification = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.defaultStyle()
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
- }
- extension UINavigationController {
- func defaultStyle() {
- self.modalPresentationStyle = .fullScreen
- self.navigationBar.tintColor = .white
- self.navigationBar.barTintColor = .mainColor
- self.navigationBar.isTranslucent = false
- self.navigationBar.overrideUserInterfaceStyle = .dark
- self.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- self.navigationBar.titleTextAttributes = textAttributes
- self.view.backgroundColor = .mainColor
- }
- }
|