FourthTabViewController.swift 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. //
  2. // SettingTableViewController.swift
  3. // Qmera
  4. //
  5. // Created by Yayan Dwi on 16/09/21.
  6. //
  7. import UIKit
  8. import NotificationBannerSwift
  9. import nuSDKService
  10. import NexilisLite
  11. import Photos
  12. public class FourthTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UIGestureRecognizerDelegate {
  13. var language: [[String: String]] = [["Indonesia": "id"],["English": "en"]]
  14. var alert: UIAlertController?
  15. var textFields = [UITextField]()
  16. var switchVibrateMode = UISwitch()
  17. var switchSaveToGallery = UISwitch()
  18. var switchAutoDownload = UISwitch()
  19. @IBOutlet weak var tableView: UITableView!
  20. @IBOutlet weak var backgroundImage: UIImageView!
  21. var notInTab = false
  22. public override func viewDidLoad() {
  23. super.viewDidLoad()
  24. self.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
  25. self.navigationController?.navigationBar.topItem?.backButtonTitle = ""
  26. tableView.delegate = self
  27. tableView.dataSource = self
  28. tableView.layoutMargins = .init(top: 0, left: 0, bottom: 0, right: 0)
  29. // tableView.separatorColor = .gray
  30. tableView.separatorStyle = .none
  31. if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
  32. tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 80, right: 0)
  33. }
  34. switchVibrateMode.tintColor = .gray
  35. switchSaveToGallery.tintColor = .gray
  36. switchAutoDownload.tintColor = .gray
  37. switchVibrateMode.onTintColor = .mainColor
  38. switchSaveToGallery.onTintColor = .mainColor
  39. switchAutoDownload.onTintColor = .mainColor
  40. let vibrateMode: Bool = SecureUserDefaults.shared.value(forKey: "vibrateMode") ?? false
  41. let saveGallery: Bool = SecureUserDefaults.shared.value(forKey: "saveToGallery") ?? false
  42. let autoDownload: Bool = SecureUserDefaults.shared.value(forKey: "autoDownload") ?? false
  43. if vibrateMode {
  44. switchVibrateMode.setOn(true, animated: false)
  45. }
  46. if saveGallery {
  47. switchSaveToGallery.setOn(true, animated: false)
  48. }
  49. if autoDownload {
  50. switchAutoDownload.setOn(true, animated: false)
  51. }
  52. switchVibrateMode.addTarget(self, action: #selector(vibrateModeSwitch), for: .valueChanged)
  53. switchSaveToGallery.addTarget(self, action: #selector(saveToGallerySwitch), for: .valueChanged)
  54. switchAutoDownload.addTarget(self, action: #selector(autoDownloadSwitch), for: .valueChanged)
  55. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(collapseDocked))
  56. tapGesture.cancelsTouchesInView = false
  57. tapGesture.delegate = self
  58. self.view.addGestureRecognizer(tapGesture)
  59. // navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapCancel))
  60. }
  61. @objc func collapseDocked() {
  62. if ViewController.isExpandButton {
  63. ViewController.expandButton()
  64. }
  65. }
  66. public override func viewWillDisappear(_ animated: Bool) {
  67. if ViewController.isExpandButton {
  68. ViewController.expandButton()
  69. }
  70. }
  71. public override func viewDidAppear(_ animated: Bool) {
  72. self.navigationController?.navigationBar.topItem?.title = "Settings".localized()
  73. self.navigationController?.navigationBar.setNeedsLayout()
  74. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
  75. var viewController = UIApplication.shared.windows.first!.rootViewController
  76. if !(viewController is ViewController) {
  77. viewController = self.parent
  78. }
  79. if ViewController.middleButton.isHidden {
  80. ViewController.isExpandButton = false
  81. if let viewController = viewController as? ViewController {
  82. if viewController.tabBar.isHidden {
  83. viewController.tabBar.isHidden = false
  84. ViewController.alwaysHideButton = false
  85. ViewController.middleButton.isHidden = false
  86. }
  87. }
  88. } else if PrefsUtil.getCpaasMode() != PrefsUtil.CPAAS_MODE_DOCKED {
  89. DispatchQueue.main.async {
  90. if let viewController = viewController as? ViewController {
  91. if viewController.tabBar.isHidden {
  92. viewController.tabBar.isHidden = false
  93. ViewController.alwaysHideButton = false
  94. }
  95. }
  96. }
  97. }
  98. })
  99. }
  100. @objc func vibrateModeSwitch() {
  101. SecureUserDefaults.shared.set(switchVibrateMode.isOn, forKey: "vibrateMode")
  102. }
  103. @objc func saveToGallerySwitch() {
  104. if switchSaveToGallery.isOn {
  105. PHPhotoLibrary.requestAuthorization({status in
  106. DispatchQueue.main.async {
  107. if status == .authorized {
  108. SecureUserDefaults.shared.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
  109. } else {
  110. self.switchSaveToGallery.setOn(false, animated: true)
  111. }
  112. }
  113. })
  114. } else {
  115. SecureUserDefaults.shared.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
  116. }
  117. }
  118. @objc func autoDownloadSwitch() {
  119. SecureUserDefaults.shared.set(switchAutoDownload.isOn, forKey: "autoDownload")
  120. }
  121. func makeMenu(imageSignIn: String = ""){
  122. let isChangeProfile = Utils.getSetProfile()
  123. if Database.shared.database == nil {
  124. Item.menus["Personal"] = [
  125. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  126. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  127. Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()),
  128. ]
  129. } else {
  130. Database.shared.database?.inTransaction({ fmdb, rollback in
  131. let idMe = User.getMyPin() as String?
  132. if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id, official_account FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
  133. if (User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") && User.isAdmin(fmdb: fmdb)) || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
  134. Item.menus["Personal"] = [
  135. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  136. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  137. // Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
  138. Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
  139. // Item(icon: UIImage(named: "ic_internal", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set Internal Account".localized()),
  140. Item(icon: UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set CS Account".localized()),
  141. ]
  142. } else if User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isCallCenter(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isVerified(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
  143. Item.menus["Personal"] = [
  144. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  145. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  146. Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
  147. ]
  148. } else {
  149. Item.menus["Personal"] = [
  150. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  151. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  152. // Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
  153. ]
  154. }
  155. if !isChangeProfile {
  156. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
  157. } else if isChangeProfile {
  158. if Nexilis.checkingAccess(key: "backup_restore") {
  159. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.clockwise.icloud"), title: "Backup & Restore".localized()))
  160. }
  161. if Utils.getLimitValidTrans() == "1" {
  162. Item.menus["Personal"]?.insert(Item(icon: UIImage(systemName: "lessthan.circle"), title: "Validation Transaction Limit".localized()), at: 1)
  163. }
  164. }
  165. let image = cursorUser.string(forColumnIndex: 1)
  166. if image != nil {
  167. if !image!.isEmpty {
  168. do {
  169. let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  170. let file = documentDir.appendingPathComponent(image!)
  171. if FileManager().fileExists(atPath: file.path) {
  172. let image = UIImage(contentsOfFile: file.path)
  173. Item.menus["Personal"]?[0].icon = image?.circleMasked
  174. if !imageSignIn.isEmpty {
  175. var dataImage: [AnyHashable : Any] = [:]
  176. dataImage["name"] = imageSignIn
  177. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  178. }
  179. } else {
  180. Download().start(forKey: image!) { (name, progress) in
  181. guard progress == 100 else {
  182. return
  183. }
  184. DispatchQueue.main.async {
  185. let image = UIImage(contentsOfFile: file.path)
  186. Item.menus["Personal"]?[0].icon = image?.circleMasked
  187. self.tableView.reloadData()
  188. if !imageSignIn.isEmpty {
  189. var dataImage: [AnyHashable : Any] = [:]
  190. dataImage["name"] = imageSignIn
  191. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  192. }
  193. }
  194. }
  195. }
  196. } catch {}
  197. }
  198. }
  199. cursorUser.close()
  200. } else {
  201. Item.menus["Personal"] = [
  202. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  203. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  204. // Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
  205. ]
  206. if Nexilis.showButtonFB {
  207. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))
  208. }
  209. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
  210. if !imageSignIn.isEmpty {
  211. do {
  212. let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  213. let file = documentDir.appendingPathComponent(imageSignIn)
  214. if FileManager().fileExists(atPath: file.path) {
  215. let image = UIImage(contentsOfFile: file.path)
  216. Item.menus["Personal"]?[0].icon = image?.circleMasked
  217. var dataImage: [AnyHashable : Any] = [:]
  218. dataImage["name"] = imageSignIn
  219. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  220. } else {
  221. Download().start(forKey: imageSignIn) { (name, progress) in
  222. guard progress == 100 else {
  223. return
  224. }
  225. DispatchQueue.main.async {
  226. let image = UIImage(contentsOfFile: file.path)
  227. Item.menus["Personal"]?[0].icon = image?.circleMasked
  228. self.tableView.reloadData()
  229. var dataImage: [AnyHashable : Any] = [:]
  230. dataImage["name"] = imageSignIn
  231. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  232. }
  233. }
  234. }
  235. } catch {}
  236. }
  237. }
  238. })
  239. }
  240. Item.menus["Config"] = [
  241. Item(icon: UIImage(systemName: "iphone"), title: "Create Your Own App".localized()),
  242. Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized())
  243. ]
  244. if !isChangeProfile || Utils.getEnableMobileBuilder() != "1" {
  245. if Item.menus["Config"]!.count > 1 {
  246. Item.menus["Config"]!.remove(at: 0)
  247. } else {
  248. Item.menus["Config"]!.removeAll()
  249. }
  250. }
  251. if !Nexilis.showButtonFB {
  252. if Item.menus["Config"]!.count > 1 {
  253. Item.menus["Config"]!.remove(at: 1)
  254. } else {
  255. Item.menus["Config"]!.removeAll()
  256. }
  257. }
  258. if Utils.getIsLoadThemeFromOther() {
  259. Item.menus["Config"]?.insert(Item(icon: UIImage(systemName: "iphone"), title: "Back to Company App".localized()), at: 1)
  260. }
  261. Item.menus["Call"] = [
  262. Item(icon: UIImage(systemName: "message"), title: "Notification Message(s)".localized()),
  263. Item(icon: UIImage(systemName: "message"), title: "Notification Message(s) Group".localized()),
  264. Item(icon: UIImage(systemName: "iphone.homebutton.radiowaves.left.and.right"), title: "Vibrate Mode".localized()),
  265. Item(icon: UIImage(systemName: "photo.on.rectangle.angled"), title: "Save to Gallery".localized()),
  266. Item(icon: UIImage(systemName: "arrow.down.square"), title: "Auto Download".localized()),
  267. ]
  268. Item.menus["Version"] = [
  269. Item(icon: UIImage(systemName: "gear"), title: "Version".localized()),
  270. Item(icon: UIImage(named: "pb_powered_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), title: "Powered by Nexilis".localized()),
  271. ]
  272. if isChangeProfile {
  273. if Nexilis.checkingAccess(key: "logout"){
  274. Item.menus["Version"]?.insert(Item(icon: UIImage(systemName: "rectangle.portrait.and.arrow.right"), title: "Sign-Out".localized()), at: 0)
  275. }
  276. }
  277. }
  278. override public func viewWillAppear(_ animated: Bool) {
  279. // self.navigationController?.navigationBar.topItem?.title = ""
  280. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: self.traitCollection.userInterfaceStyle == .dark ? .white : UIColor.black]
  281. let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: self.traitCollection.userInterfaceStyle == .dark ? .white : UIColor.black, NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 16)]
  282. let navBarAppearance = UINavigationBarAppearance()
  283. navBarAppearance.configureWithTransparentBackground()
  284. navBarAppearance.titleTextAttributes = attributes
  285. navigationController?.navigationBar.standardAppearance = navBarAppearance
  286. navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
  287. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: self.traitCollection.userInterfaceStyle == .dark ? .white : UIColor.black, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  288. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  289. navigationController?.navigationBar.backgroundColor = .clear
  290. navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  291. navigationController?.navigationBar.shadowImage = UIImage()
  292. navigationController?.navigationBar.isTranslucent = true
  293. navigationController?.setNavigationBarHidden(false, animated: false)
  294. navigationController?.navigationBar.overrideUserInterfaceStyle = self.traitCollection.userInterfaceStyle == .dark ? .dark : .light
  295. navigationController?.navigationBar.barStyle = .default
  296. navigationController?.navigationBar.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  297. tabBarController?.navigationItem.leftBarButtonItem = nil
  298. tabBarController?.navigationItem.searchController = nil
  299. checkBurgerMode()
  300. backgroundImage.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
  301. backgroundImage.image = nil
  302. DispatchQueue.global().async {
  303. DispatchQueue.main.async {
  304. let listBg = PrefsUtil.getBackgroundLight().isEmpty && PrefsUtil.getBackgroundDark().isEmpty ? PrefsUtil.getBackground() :
  305. self.traitCollection.userInterfaceStyle == .dark ? PrefsUtil.getBackgroundDark() : PrefsUtil.getBackgroundLight()
  306. if listBg.isEmpty {
  307. return
  308. }
  309. var bgChoosen = ""
  310. let arrayBg = listBg.split(separator: ",")
  311. bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
  312. let urlString = PrefsUtil.getURLBase() + "get_file_from_path?img=" + bgChoosen
  313. if let cachedImage = ImageCache.shared.image(forKey: urlString) {
  314. DispatchQueue.main.async() { [self] in
  315. backgroundImage.image = cachedImage
  316. }
  317. return
  318. }
  319. Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
  320. guard let data = data, error == nil else { return }
  321. // always update the UI from the main thread
  322. DispatchQueue.main.async() { [self] in
  323. if UIImage(data: data) != nil {
  324. backgroundImage.image = UIImage(data: data)!
  325. ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
  326. }
  327. }
  328. }
  329. }
  330. }
  331. makeMenu()
  332. }
  333. // MARK: - Table view data source
  334. func checkBurgerMode() {
  335. let cpaasMode = PrefsUtil.getCpaasMode()
  336. let isBurger = cpaasMode == PrefsUtil.CPAAS_MODE_BURGER
  337. if isBurger {
  338. var childrenMenu: [UIAction] = []
  339. if !Utils.getCustomButtons().isEmpty {
  340. let customButtons = Utils.getCustomButtons().components(separatedBy: ",")
  341. for i in 0..<customButtons.count {
  342. let package_id = customButtons[i]
  343. var app_id = ""
  344. var indexTap = 0
  345. if package_id.contains("_fb"){
  346. let listSplit = package_id.split(separator: "_", maxSplits: 1)
  347. let numIdx = listSplit[listSplit.firstIndex(where: { $0.contains("fb") }) ?? 0]
  348. indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count))!
  349. if listSplit.count == 2 {
  350. app_id = String(listSplit[1])
  351. }
  352. }
  353. var nameButton = ""
  354. switch (indexTap) {
  355. case Nexilis.IDX_ADDFRIEND :
  356. nameButton = "Add Friend".localized()
  357. case Nexilis.IDX_BROADCAST_FORM :
  358. nameButton = "Broadcast Form".localized()
  359. case Nexilis.IDX_CALL :
  360. nameButton = "Call".localized()
  361. case Nexilis.IDX_CALL_AUDIO :
  362. nameButton = "Call Audio".localized()
  363. case Nexilis.IDX_CALL_VIDEO :
  364. nameButton = "Call Video".localized()
  365. case Nexilis.IDX_CC :
  366. nameButton = "Contact Center".localized()
  367. case Nexilis.IDX_CC_STREAM :
  368. nameButton = "Contact Center Streaming".localized()
  369. case Nexilis.IDX_CHAT :
  370. nameButton = "Chat".localized()
  371. case Nexilis.IDX_CONFERENCE_ROOM_FORM :
  372. nameButton = "Video Conference Room".localized()
  373. case Nexilis.IDX_CREATE_GROUP :
  374. nameButton = "Create Group".localized()
  375. case Nexilis.IDX_CONVERSATION :
  376. nameButton = "Conversation".localized()
  377. case Nexilis.IDX_EMAIL_CONFIGURATION :
  378. nameButton = "Email Configuration".localized()
  379. case Nexilis.IDX_FAVORITEMESSAGE :
  380. nameButton = "Favorite Message".localized()
  381. case Nexilis.IDX_POST :
  382. nameButton = "New post".localized()
  383. case Nexilis.IDX_QUEUE_SYSTEM :
  384. nameButton = "Custom URL".localized()
  385. case Nexilis.IDX_NOTIF_CENTER :
  386. nameButton = "Notification Center".localized()
  387. case Nexilis.IDX_SCREENSHARING :
  388. nameButton = "Screen Sharing".localized()
  389. case Nexilis.IDX_STREAM :
  390. nameButton = "Live Streaming".localized()
  391. case Nexilis.IDX_WHITEBOARD :
  392. nameButton = "Whiteboard".localized()
  393. case Nexilis.IDX_SELF_ACT :
  394. nameButton = "Custom Action".localized()
  395. case Nexilis.IDX_SOCIAL_COMMERCE :
  396. nameButton = "Social Commerce".localized()
  397. case Nexilis.IDX_NEWS :
  398. nameButton = "News".localized()
  399. default :
  400. nameButton = ""
  401. }
  402. childrenMenu.append(UIAction(title: nameButton, handler: {(_) in
  403. Nexilis.buttonClicked(index: indexTap, id: app_id)
  404. }))
  405. }
  406. } else {
  407. childrenMenu.append(UIAction(title: "Contact Center".localized(), handler: {(_) in
  408. Nexilis.buttonClicked(index: Nexilis.IDX_CC)
  409. }))
  410. childrenMenu.append(UIAction(title: "Chat".localized(), handler: {(_) in
  411. Nexilis.buttonClicked(index: Nexilis.IDX_CHAT)
  412. }))
  413. childrenMenu.append(UIAction(title: "Call".localized(), handler: {(_) in
  414. Nexilis.buttonClicked(index: Nexilis.IDX_CALL)
  415. }))
  416. childrenMenu.append(UIAction(title: "Live Streaming".localized(), handler: {(_) in
  417. Nexilis.buttonClicked(index: Nexilis.IDX_STREAM)
  418. }))
  419. }
  420. let menu = UIMenu(title: "", children: childrenMenu)
  421. let menuButton = UIBarButtonItem(image: self.traitCollection.userInterfaceStyle == .dark ? UIImage(systemName: "ellipsis")?.withTintColor(.white) : UIImage(systemName: "ellipsis"), menu: menu)
  422. tabBarController?.navigationItem.rightBarButtonItem = menuButton
  423. } else {
  424. tabBarController?.navigationItem.rightBarButtonItem = nil
  425. }
  426. }
  427. public func numberOfSections(in tableView: UITableView) -> Int {
  428. return Item.sections.count
  429. }
  430. public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  431. return Item.menuFor(section: section).count
  432. }
  433. public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  434. let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
  435. let isChangeProfile = Utils.getSetProfile()
  436. cell.accessoryType = .none
  437. cell.indentationLevel = 0
  438. var content = cell.defaultContentConfiguration()
  439. content.textProperties.font = UIFont.systemFont(ofSize: 14)
  440. content.secondaryTextProperties.font = UIFont.systemFont(ofSize: 14)
  441. content.secondaryTextProperties.color = .gray
  442. content.prefersSideBySideTextAndSecondaryText = true
  443. let section = Item.sections[indexPath.section]
  444. if let arr = Item.menus[section] {
  445. let menu = arr[indexPath.row]
  446. content.image = menu.icon
  447. content.imageProperties.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  448. content.imageProperties.maximumSize = CGSize(width: 24, height: 24)
  449. content.text = menu.title
  450. cell.accessoryView = nil
  451. switch menu.title {
  452. case "Personal Information".localized():
  453. cell.accessoryType = .disclosureIndicator
  454. case "Access Admin / Internal Features".localized():
  455. cell.accessoryType = .disclosureIndicator
  456. case "Sign-In to Web".localized():
  457. cell.accessoryType = .disclosureIndicator
  458. case "Sign-Up/Sign-In".localized():
  459. cell.accessoryType = .disclosureIndicator
  460. case "Configure Floating Button".localized():
  461. cell.accessoryType = .disclosureIndicator
  462. case "Notification Message(s)".localized():
  463. cell.accessoryType = .disclosureIndicator
  464. case "Backup & Restore".localized():
  465. cell.accessoryType = .disclosureIndicator
  466. case "Validation Transaction Limit".localized():
  467. cell.accessoryType = .disclosureIndicator
  468. case "Create Your Own App".localized():
  469. cell.accessoryType = .disclosureIndicator
  470. case "Notification Message(s) Group".localized():
  471. cell.accessoryType = .disclosureIndicator
  472. case "Change Admin / Internal Password".localized():
  473. cell.accessoryType = .disclosureIndicator
  474. case "Change Language".localized():
  475. cell.accessoryType = .disclosureIndicator
  476. case "Set Internal Account".localized():
  477. cell.accessoryType = .disclosureIndicator
  478. case "Set CS Account".localized():
  479. cell.accessoryType = .disclosureIndicator
  480. case "Version".localized():
  481. let accessoryButton = UIButton(type: .custom)
  482. accessoryButton.setTitle(UIApplication.appVersion, for: .normal)
  483. accessoryButton.setTitleColor(self.traitCollection.userInterfaceStyle == .dark ? .white : .black, for: .normal)
  484. accessoryButton.titleLabel?.font = .systemFont(ofSize: 18)
  485. accessoryButton.contentHorizontalAlignment = .right
  486. accessoryButton.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
  487. accessoryButton.contentMode = .scaleAspectFit
  488. cell.accessoryView = accessoryButton as UIView
  489. case "Vibrate Mode".localized():
  490. cell.accessoryView = switchVibrateMode
  491. case "Save to Gallery".localized():
  492. cell.accessoryView = switchSaveToGallery
  493. case "Auto Download".localized():
  494. cell.accessoryView = switchAutoDownload
  495. default:
  496. content.secondaryText = nil
  497. }
  498. }
  499. cell.contentConfiguration = content
  500. return cell
  501. }
  502. public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  503. let footerView = UIView()
  504. if section != 3 {
  505. footerView.backgroundColor = .clear
  506. let lineView = UIView()
  507. lineView.backgroundColor = .gray
  508. lineView.translatesAutoresizingMaskIntoConstraints = false
  509. footerView.addSubview(lineView)
  510. NSLayoutConstraint.activate([
  511. lineView.leadingAnchor.constraint(equalTo: footerView.leadingAnchor),
  512. lineView.trailingAnchor.constraint(equalTo: footerView.trailingAnchor),
  513. lineView.heightAnchor.constraint(equalToConstant: 1),
  514. lineView.bottomAnchor.constraint(equalTo: footerView.bottomAnchor)
  515. ])
  516. }
  517. return footerView
  518. }
  519. public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  520. let headerView = UIView()
  521. if (section == 2 && Item.menus["Config"]!.count > 0) || section == 3 || (section == 1 && Item.menus["Config"]!.count > 0) {
  522. headerView.backgroundColor = .clear
  523. let lineView = UIView()
  524. lineView.backgroundColor = .gray
  525. lineView.translatesAutoresizingMaskIntoConstraints = false
  526. headerView.addSubview(lineView)
  527. NSLayoutConstraint.activate([
  528. lineView.leadingAnchor.constraint(equalTo: headerView.leadingAnchor),
  529. lineView.trailingAnchor.constraint(equalTo: headerView.trailingAnchor),
  530. lineView.heightAnchor.constraint(equalToConstant: 1),
  531. lineView.bottomAnchor.constraint(equalTo: headerView.bottomAnchor)
  532. ])
  533. }
  534. return headerView
  535. }
  536. public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  537. if section == 2 || section == 3 || section == 1 {
  538. return 6
  539. }
  540. return 1
  541. }
  542. public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  543. let item = Item.menuFor(section: indexPath.section)[indexPath.row]
  544. if item.title == "Personal Information".localized() {
  545. if(ViewController.checkIsChangePerson()){
  546. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
  547. controller.data = User.getMyPin()!
  548. controller.flag = .me
  549. controller.dismissImage = { image, imageName in
  550. var dataImage: [AnyHashable : Any] = [:]
  551. dataImage["name"] = imageName
  552. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  553. self.makeMenu()
  554. self.tableView.reloadData()
  555. }
  556. navigationController?.show(controller, sender: nil)
  557. }
  558. } else if item.title == "Access Admin / Internal Features".localized() || item.title == "Change Admin / Internal Password".localized() {
  559. if(ViewController.checkIsChangePerson()){
  560. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  561. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  562. imageView.tintColor = .white
  563. 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)
  564. banner.show()
  565. return
  566. }
  567. let alertController = LibAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
  568. if(item.title.contains("Change")){
  569. if let action = self.actionChangePassword(for: "admin", title: "Change Admin Password".localized()) {
  570. alertController.addAction(action)
  571. }
  572. if let action = self.actionChangePassword(for: "internal", title: "Change Internal Password".localized()) {
  573. alertController.addAction(action)
  574. }
  575. }
  576. else {
  577. if let action = self.actionLogin(for: "admin", title: "Access Admin Features".localized()) {
  578. alertController.addAction(action)
  579. }
  580. if let action = self.actionLogin(for: "internal", title: "Access Internal Features".localized()) {
  581. alertController.addAction(action)
  582. }
  583. }
  584. alertController.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  585. self.present(alertController, animated: true)
  586. }
  587. } else if item.title == "Change Language".localized() {
  588. let vc = UIViewController()
  589. vc.preferredContentSize = CGSize(width: UIScreen.main.bounds.width - 10, height: 150)
  590. let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 150))
  591. pickerView.dataSource = self
  592. pickerView.delegate = self
  593. let lang: String = SecureUserDefaults.shared.value(forKey: "i18n_language") ?? "en"
  594. var index = 1
  595. if lang == "id" {
  596. index = 0
  597. }
  598. pickerView.selectRow(index, inComponent: 0, animated: false)
  599. vc.view.addSubview(pickerView)
  600. pickerView.translatesAutoresizingMaskIntoConstraints = false
  601. pickerView.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true
  602. pickerView.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true
  603. let alert = LibAlertController(title: "Select Language".localized(), message: "", preferredStyle: .actionSheet)
  604. alert.setValue(vc, forKey: "contentViewController")
  605. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { (UIAlertAction) in
  606. }))
  607. alert.addAction(UIAlertAction(title: "Select".localized(), style: .default, handler: { (UIAlertAction) in
  608. let selectedIndex = pickerView.selectedRow(inComponent: 0)
  609. let lang = self.language[selectedIndex].values.first
  610. SecureUserDefaults.shared.set(lang, forKey: "i18n_language")
  611. self.navigationController?.navigationBar.topItem?.title = "Settings".localized();
  612. self.navigationController?.navigationBar.setNeedsLayout()
  613. self.makeMenu()
  614. self.tableView.reloadData()
  615. FirstTabViewController.forceRefresh = true
  616. ThirdTabViewController.forceRefresh = true
  617. FirstTabViewController.showModal = false
  618. ThirdTabViewController.showModal = false
  619. }))
  620. self.present(alert, animated: true, completion: nil)
  621. } else if item.title == "Sign-In".localized() {
  622. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
  623. controller.isDismiss = { newThumb in
  624. self.makeMenu(imageSignIn: newThumb)
  625. self.tableView.reloadData()
  626. }
  627. navigationController?.show(controller, sender: nil)
  628. } else if item.title == "Sign-Up/Sign-In".localized() {
  629. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
  630. controller.isDismiss = { newThumb in
  631. self.makeMenu(imageSignIn: newThumb)
  632. self.tableView.reloadData()
  633. FirstTabViewController.forceRefresh = true
  634. ThirdTabViewController.forceRefresh = true
  635. FirstTabViewController.showModal = false
  636. ThirdTabViewController.showModal = false
  637. }
  638. navigationController?.show(controller, sender: nil)
  639. } else if item.title == "Sign-Out".localized() {
  640. let alert = LibAlertController(title: "Sign-Out".localized(), message: "Are you sure want to logout?".localized(), preferredStyle: .alert)
  641. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
  642. alert.addAction(UIAlertAction(title: "Yes".localized(), style: .destructive, handler: {(_) in
  643. var viewController = UIApplication.shared.windows.first!.rootViewController
  644. if !(viewController is ViewController) {
  645. viewController = self.parent
  646. }
  647. if let viewController = viewController as? ViewController {
  648. if !(viewController.selectedViewController is FourthTabViewController) {
  649. viewController.selectedIndex = (viewController.viewControllers?.firstIndex(of: viewController.fourthTab!))!
  650. }
  651. }
  652. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  653. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  654. imageView.tintColor = .white
  655. 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)
  656. banner.show()
  657. return
  658. }
  659. Nexilis.showLoader()
  660. DispatchQueue.global().async {
  661. let apiKey = Nexilis.sAPIKey
  662. var id = Utils.getConnectionID()
  663. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000) {
  664. id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
  665. if(!id.isEmpty){
  666. // Nexilis.changeUser(f_pin: id)
  667. SecureUserDefaults.shared.set(id, forKey: "me")
  668. Utils.setProfile(value: false)
  669. if Utils.getForceAnonymous() {
  670. self.deleteAllRecordDatabase()
  671. SecureUserDefaults.shared.removeValue(forKey: "device_id")
  672. Nexilis.destroyAll()
  673. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
  674. }
  675. DispatchQueue.main.async {
  676. Nexilis.hideLoader(completion: {
  677. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  678. imageView.tintColor = .white
  679. let banner = FloatingNotificationBanner(title: "Successfully Sign-Out".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)
  680. banner.show()
  681. if viewController is UINavigationController {
  682. viewController = (viewController as! UINavigationController).viewControllers[0]
  683. }
  684. if Nexilis.showFB && viewController is ViewController{
  685. Nexilis.floatingButton.removeFromSuperview()
  686. Nexilis.floatingButton = FloatingButton()
  687. Nexilis.addFB(viewController: viewController!, fromMAB: true)
  688. }
  689. var dataImage: [AnyHashable : Any] = [:]
  690. dataImage["name"] = ""
  691. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  692. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
  693. self.makeMenu()
  694. self.tableView.reloadData()
  695. FirstTabViewController.forceRefresh = true
  696. ThirdTabViewController.forceRefresh = true
  697. FirstTabViewController.showModal = false
  698. ThirdTabViewController.showModal = false
  699. if !Utils.getForceAnonymous() {
  700. Nexilis.showForceSignIn()
  701. }
  702. })
  703. }
  704. } else {
  705. DispatchQueue.main.async {
  706. Nexilis.hideLoader(completion: {
  707. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  708. imageView.tintColor = .white
  709. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".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)
  710. banner.show()
  711. })
  712. }
  713. }
  714. } else {
  715. DispatchQueue.main.async {
  716. Nexilis.hideLoader(completion: {
  717. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  718. imageView.tintColor = .white
  719. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".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)
  720. banner.show()
  721. })
  722. }
  723. }
  724. }
  725. }))
  726. self.present(alert, animated: true, completion: nil)
  727. } else if item.title == "Sign-In to Web".localized() {
  728. var permissionCheck = -1
  729. if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
  730. permissionCheck = 1
  731. } else if AVCaptureDevice.authorizationStatus(for: .video) == .denied {
  732. permissionCheck = 0
  733. } else {
  734. AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) -> Void in
  735. if granted == true {
  736. permissionCheck = 1
  737. } else {
  738. permissionCheck = 0
  739. }
  740. })
  741. }
  742. while permissionCheck == -1 {
  743. sleep(1)
  744. }
  745. if permissionCheck == 0 {
  746. let alert = LibAlertController(title: "Attention!".localized(), message: "Please allow camera permission in your settings".localized(), preferredStyle: .alert)
  747. alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: { _ in
  748. if let url = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(url) {
  749. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  750. }
  751. }))
  752. if UIApplication.shared.visibleViewController?.navigationController != nil {
  753. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  754. } else {
  755. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  756. }
  757. return
  758. }
  759. let controller = ScannerViewController()
  760. let navigationController = CustomNavigationController(rootViewController: controller)
  761. navigationController.navigationBar.tintColor = .white
  762. navigationController.navigationBar.barTintColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  763. navigationController.navigationBar.isTranslucent = false
  764. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  765. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  766. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  767. navigationController.navigationBar.titleTextAttributes = textAttributes
  768. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  769. navigationController.navigationBar.barStyle = .black
  770. navigationController.modalPresentationStyle = .custom
  771. self.present(navigationController, animated: true)
  772. } else if item.title == "Notification Message(s)".localized() || item.title == "Notification Message(s) Group".localized() {
  773. let controller = NotificationSound()
  774. if item.title != "Notification Message(s)".localized() {
  775. controller.isPersonal = false
  776. }
  777. let navigationController = CustomNavigationController(rootViewController: controller)
  778. navigationController.navigationBar.tintColor = .white
  779. navigationController.navigationBar.barTintColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  780. navigationController.navigationBar.isTranslucent = false
  781. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  782. navigationController.navigationBar.barStyle = .black
  783. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  784. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  785. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  786. navigationController.navigationBar.titleTextAttributes = textAttributes
  787. self.present(navigationController, animated: true)
  788. } else if item.title == "Backup & Restore".localized() {
  789. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "backupRestore") as! BackupRestoreView
  790. navigationController?.show(controller, sender: nil)
  791. } else if item.title == "Set Internal Account".localized() {
  792. let controller = SetInternalCSAccount()
  793. navigationController?.show(controller, sender: nil)
  794. } else if item.title == "Set CS Account".localized() {
  795. let controller = SetInternalCSAccount()
  796. controller.isSetCS = true
  797. navigationController?.show(controller, sender: nil)
  798. } else if item.title == "Configure Floating Button".localized() {
  799. let viewConfigureFB = ConfigureFloatingButton()
  800. viewConfigureFB.modalTransitionStyle = .crossDissolve
  801. viewConfigureFB.modalPresentationStyle = .custom
  802. self.present(viewConfigureFB, animated: true)
  803. } else if item.title == "Validation Transaction Limit".localized() {
  804. let controller = ValidationTransactionLimit()
  805. navigationController?.show(controller, sender: nil)
  806. } else if item.title == "Create Your Own App".localized() {
  807. let controller = BNIBookingWebView()
  808. controller.customUrl = PrefsUtil.getURLBase() + "mobile_MAB?f_pin="
  809. self.present(controller, animated: true)
  810. } else if item.title == "Back to Company App".localized() {
  811. let alert = LibAlertController(title: "", message: "Are you sure want to back to company app?".localized(), preferredStyle: .alert)
  812. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
  813. alert.addAction(UIAlertAction(title: "Yes".localized(), style: .destructive, handler: {(_) in
  814. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  815. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  816. imageView.tintColor = .white
  817. 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)
  818. banner.show()
  819. return
  820. }
  821. Nexilis.showLoader()
  822. DispatchQueue.global().async {
  823. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.backToSuperApp(), timeout: 30 * 1000) {
  824. DispatchQueue.main.async {
  825. if response.isOk() {
  826. Utils.setMyTheme(value: "")
  827. Utils.setIsLoadThemeFromOther(value: false)
  828. Utils.resetValueSuperApp()
  829. Utils.setValueInitialApp(data: Utils.getPrefTheme())
  830. UIApplication.shared.setAlternateIconName(nil)
  831. Database.shared.database?.inTransaction({ fmdb, rollback in
  832. _ = Database.shared.deleteRecord(fmdb: fmdb, table: "GROUPZ", _where: "")
  833. _ = Database.shared.deleteRecord(fmdb: fmdb, table: "GROUPZ_MEMBER", _where: "")
  834. _ = Database.shared.deleteRecord(fmdb: fmdb, table: "DISCUSSION_FORUM", _where: "")
  835. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: User.getMyPin() ?? ""))
  836. })
  837. Nexilis.hideLoader {
  838. let alert = LibAlertController(title: "Successfully changed".localized(), message: "Please open the app again to see the changes".localized(), preferredStyle: .alert)
  839. alert.addAction(UIAlertAction(title: "OK".localized(), style: .default, handler: {(_) in
  840. exit(0)
  841. }))
  842. self.present(alert, animated: true, completion: nil)
  843. }
  844. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "10" {
  845. Nexilis.hideLoader(completion: {
  846. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  847. imageView.tintColor = .white
  848. let banner = FloatingNotificationBanner(title: "Failed to back to Company App".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)
  849. banner.show()
  850. })
  851. } else {
  852. Nexilis.hideLoader(completion: {
  853. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  854. imageView.tintColor = .white
  855. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".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)
  856. banner.show()
  857. })
  858. }
  859. }
  860. } else {
  861. DispatchQueue.main.async {
  862. Nexilis.hideLoader(completion: {
  863. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  864. imageView.tintColor = .white
  865. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".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)
  866. banner.show()
  867. })
  868. }
  869. }
  870. }
  871. }))
  872. self.present(alert, animated: true, completion: nil)
  873. }
  874. }
  875. private func actionLogin(for type: String, title: String) -> UIAlertAction? {
  876. return UIAlertAction(title: title, style: .default) { _ in
  877. self.alert = LibAlertController(title:"Access Admin Features".localized(), message: nil, preferredStyle: .alert)
  878. if type == "internal" {
  879. self.alert = LibAlertController(title: "Access Internal Features".localized(), message: nil, preferredStyle: .alert)
  880. }
  881. self.textFields.removeAll()
  882. self.alert?.addTextField{ (texfield) in
  883. texfield.placeholder = "Password".localized()
  884. texfield.isSecureTextEntry = true
  885. texfield.addPadding(.right(40))
  886. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  887. let buttonHideUnhide = UIButton()
  888. buttonHideUnhide.tag = 0
  889. texfield.addSubview(buttonHideUnhide)
  890. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  891. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  892. buttonHideUnhide.tintColor = .black
  893. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  894. }
  895. let submitAction = UIAlertAction(title: "Sign-In".localized(), style: .default, handler: { (action) -> Void in
  896. let textField = self.alert?.textFields![0]
  897. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  898. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  899. imageView.tintColor = .white
  900. 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)
  901. banner.show()
  902. return
  903. }
  904. Nexilis.showLoader()
  905. if type == "admin" {
  906. self.signInAdmin(password: textField!.text!, completion: { result in
  907. if result {
  908. DispatchQueue.main.async {
  909. Nexilis.hideLoader {
  910. self.makeMenu()
  911. self.tableView.reloadData()
  912. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  913. imageView.tintColor = .white
  914. 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)
  915. banner.show()
  916. }
  917. }
  918. } else {
  919. DispatchQueue.main.async {
  920. Nexilis.hideLoader {}
  921. }
  922. }
  923. })
  924. } else {
  925. self.signInInternal(password: textField!.text!, completion: { result in
  926. if result {
  927. DispatchQueue.main.async {
  928. Nexilis.hideLoader {
  929. self.makeMenu()
  930. self.tableView.reloadData()
  931. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  932. imageView.tintColor = .white
  933. let banner = FloatingNotificationBanner(title: "Successfully Sign-In Internal Team".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)
  934. banner.show()
  935. }
  936. }
  937. } else {
  938. DispatchQueue.main.async {
  939. Nexilis.hideLoader {}
  940. }
  941. }
  942. })
  943. }
  944. })
  945. submitAction.isEnabled = false
  946. self.alert?.addAction(submitAction)
  947. self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  948. self.present(self.alert!, animated: true, completion: nil)
  949. }
  950. }
  951. private func actionChangePassword(for type: String, title: String) -> UIAlertAction? {
  952. return UIAlertAction(title: title, style: .default) { _ in
  953. self.alert = LibAlertController(title: "Change Admin Password".localized(), message: nil, preferredStyle: .alert)
  954. if type == "internal" {
  955. self.alert = LibAlertController(title: "Change Internal Password".localized(), message: nil, preferredStyle: .alert)
  956. }
  957. self.textFields.removeAll()
  958. self.alert?.addTextField{ (texfield) in
  959. texfield.placeholder = "Old Password"
  960. texfield.isSecureTextEntry = true
  961. texfield.addPadding(.right(40))
  962. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  963. self.textFields.append(texfield)
  964. let buttonHideUnhide = UIButton()
  965. buttonHideUnhide.tag = 0
  966. texfield.addSubview(buttonHideUnhide)
  967. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  968. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  969. buttonHideUnhide.tintColor = .black
  970. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  971. }
  972. self.alert?.addTextField{ (texfield) in
  973. texfield.placeholder = "New Password"
  974. texfield.isSecureTextEntry = true
  975. texfield.addPadding(.right(40))
  976. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  977. self.textFields.append(texfield)
  978. let buttonHideUnhide = UIButton()
  979. buttonHideUnhide.tag = 1
  980. texfield.addSubview(buttonHideUnhide)
  981. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  982. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  983. buttonHideUnhide.tintColor = .black
  984. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  985. }
  986. let submitAction = UIAlertAction(title: "Change Password".localized(), style: .default, handler: { (action) -> Void in
  987. let textFieldOld = self.alert?.textFields![0]
  988. let textFieldNew = self.alert?.textFields![1]
  989. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  990. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  991. imageView.tintColor = .white
  992. 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)
  993. banner.show()
  994. return
  995. }
  996. if type == "admin" {
  997. self.changePasswordAdmin(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
  998. if result {
  999. DispatchQueue.main.async {
  1000. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  1001. imageView.tintColor = .white
  1002. let banner = FloatingNotificationBanner(title: "Admin password changed successfully".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)
  1003. banner.show()
  1004. }
  1005. }
  1006. })
  1007. } else {
  1008. self.changePasswordInternal(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
  1009. if result {
  1010. DispatchQueue.main.async {
  1011. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  1012. imageView.tintColor = .white
  1013. let banner = FloatingNotificationBanner(title: "Internal password changed successfully".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)
  1014. banner.show()
  1015. }
  1016. }
  1017. })
  1018. }
  1019. })
  1020. submitAction.isEnabled = false
  1021. self.alert?.addAction(submitAction)
  1022. self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  1023. self.present(self.alert!, animated: true, completion: nil)
  1024. }
  1025. }
  1026. @objc func showPassword(_ sender:UIButton) {
  1027. if alert!.textFields![sender.tag].isSecureTextEntry {
  1028. alert!.textFields![sender.tag].isSecureTextEntry = false
  1029. let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
  1030. buttonImage.setImage(UIImage(systemName: "eye.fill"), for: .normal)
  1031. } else {
  1032. alert!.textFields![sender.tag].isSecureTextEntry = true
  1033. let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
  1034. buttonImage.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  1035. }
  1036. }
  1037. @objc func alertTextFieldDidChange(_ sender: UITextField) {
  1038. if(!textFields.isEmpty){
  1039. //print("text count 0: \(textFields[0].text!.count)")
  1040. //print("text count 1: \(textFields[1].text!.count)")
  1041. alert?.actions[0].isEnabled = textFields[0].text!.count > 0 && textFields[1].text!.count > 0
  1042. }
  1043. else {
  1044. alert?.actions[0].isEnabled = sender.text!.count > 0
  1045. }
  1046. }
  1047. private func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
  1048. DispatchQueue.global().async {
  1049. let idMe = User.getMyPin() as String?
  1050. let p_password = password
  1051. let md5Hex = p_password
  1052. var result: Bool = false
  1053. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
  1054. if response.isOk() {
  1055. result = true
  1056. }
  1057. DispatchQueue.main.async {
  1058. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  1059. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1060. imageView.tintColor = .white
  1061. 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)
  1062. banner.show()
  1063. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  1064. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1065. imageView.tintColor = .white
  1066. 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)
  1067. banner.show()
  1068. }
  1069. }
  1070. } else {
  1071. DispatchQueue.main.async {
  1072. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1073. imageView.tintColor = .white
  1074. 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)
  1075. banner.show()
  1076. }
  1077. }
  1078. completion(result)
  1079. }
  1080. }
  1081. private func signInInternal(password: String, completion: @escaping (Bool) -> ()) {
  1082. DispatchQueue.global().async {
  1083. let idMe = User.getMyPin() as String?
  1084. let p_password = password
  1085. let md5Hex = p_password
  1086. var result: Bool = false
  1087. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiInternal(p_name: idMe!, p_password: md5Hex)) {
  1088. if response.isOk() {
  1089. result = true
  1090. }
  1091. DispatchQueue.main.async {
  1092. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  1093. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1094. imageView.tintColor = .white
  1095. 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)
  1096. banner.show()
  1097. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  1098. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1099. imageView.tintColor = .white
  1100. 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)
  1101. banner.show()
  1102. }
  1103. }
  1104. } else {
  1105. DispatchQueue.main.async {
  1106. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1107. imageView.tintColor = .white
  1108. 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)
  1109. banner.show()
  1110. }
  1111. }
  1112. completion(result)
  1113. }
  1114. }
  1115. private func changePasswordAdmin(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
  1116. DispatchQueue.global().async {
  1117. let idMe = User.getMyPin() as String?
  1118. let p_password = oldPassword
  1119. let n_password = newPassword
  1120. let md5Hex = p_password
  1121. let md5HexNew = n_password
  1122. var result: Bool = false
  1123. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordAdmin(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
  1124. if response.isOk() {
  1125. result = true
  1126. }
  1127. DispatchQueue.main.async {
  1128. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  1129. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1130. imageView.tintColor = .white
  1131. 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)
  1132. banner.show()
  1133. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  1134. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1135. imageView.tintColor = .white
  1136. 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)
  1137. banner.show()
  1138. }
  1139. }
  1140. } else {
  1141. DispatchQueue.main.async {
  1142. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1143. imageView.tintColor = .white
  1144. 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)
  1145. banner.show()
  1146. }
  1147. }
  1148. completion(result)
  1149. }
  1150. }
  1151. private func changePasswordInternal(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
  1152. DispatchQueue.global().async {
  1153. let idMe = User.getMyPin() as String?
  1154. let p_password = oldPassword
  1155. let n_password = newPassword
  1156. let md5Hex = p_password
  1157. let md5HexNew = n_password
  1158. var result: Bool = false
  1159. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordInternal(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
  1160. if response.isOk() {
  1161. result = true
  1162. }
  1163. DispatchQueue.main.async {
  1164. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  1165. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1166. imageView.tintColor = .white
  1167. 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)
  1168. banner.show()
  1169. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  1170. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1171. imageView.tintColor = .white
  1172. 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)
  1173. banner.show()
  1174. }
  1175. }
  1176. } else {
  1177. DispatchQueue.main.async {
  1178. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1179. imageView.tintColor = .white
  1180. 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)
  1181. banner.show()
  1182. }
  1183. }
  1184. completion(result)
  1185. }
  1186. }
  1187. }
  1188. // MARK: - Item
  1189. struct Item: Hashable {
  1190. static func == (lhs: Item, rhs: Item) -> Bool {
  1191. return lhs.title == rhs.title
  1192. }
  1193. var icon: UIImage?
  1194. var title = ""
  1195. static var sections: [String] {
  1196. return ["Personal", "Config", "Call", "Version"]
  1197. }
  1198. static var menus: [String: [Item]] = [:]
  1199. static func menuFor(section: Int) -> [Item] {
  1200. let sec = sections[section]
  1201. if let arr = menus[sec] {
  1202. return arr
  1203. }
  1204. return []
  1205. }
  1206. }
  1207. extension FourthTabViewController: UIPickerViewDelegate, UIPickerViewDataSource {
  1208. public func numberOfComponents(in pickerView: UIPickerView) -> Int {
  1209. return 1
  1210. }
  1211. public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
  1212. return language.count
  1213. }
  1214. public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
  1215. return 60
  1216. }
  1217. public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
  1218. let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 30))
  1219. label.text = (language[row]).keys.first
  1220. label.sizeToFit()
  1221. return label
  1222. }
  1223. }