FourthTabViewController.swift 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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. let separatorLogout = UIView()
  20. let separatorNotifPersonal = UIView()
  21. let separatorAutoDownload = UIView()
  22. let separatorVersion = UIView()
  23. let separatorLogin = UIView()
  24. @IBOutlet weak var tableView: UITableView!
  25. @IBOutlet weak var backgroundImage: UIImageView!
  26. var notInTab = false
  27. public override func viewDidLoad() {
  28. super.viewDidLoad()
  29. tableView.delegate = self
  30. tableView.dataSource = self
  31. tableView.layoutMargins = .init(top: 0, left: 0, bottom: 0, right: 0)
  32. // tableView.separatorColor = .gray
  33. tableView.separatorStyle = .none
  34. if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
  35. tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 80, right: 0)
  36. }
  37. switchVibrateMode.tintColor = .gray
  38. switchSaveToGallery.tintColor = .gray
  39. switchAutoDownload.tintColor = .gray
  40. switchVibrateMode.onTintColor = .mainColor
  41. switchSaveToGallery.onTintColor = .mainColor
  42. switchAutoDownload.onTintColor = .mainColor
  43. let vibrateMode = UserDefaults.standard.bool(forKey: "vibrateMode")
  44. let saveGallery = UserDefaults.standard.bool(forKey: "saveToGallery")
  45. let autoDownload = UserDefaults.standard.bool(forKey: "autoDownload")
  46. if vibrateMode {
  47. switchVibrateMode.setOn(true, animated: false)
  48. }
  49. if saveGallery {
  50. switchSaveToGallery.setOn(true, animated: false)
  51. }
  52. if autoDownload {
  53. switchAutoDownload.setOn(true, animated: false)
  54. }
  55. switchVibrateMode.addTarget(self, action: #selector(vibrateModeSwitch), for: .valueChanged)
  56. switchSaveToGallery.addTarget(self, action: #selector(saveToGallerySwitch), for: .valueChanged)
  57. switchAutoDownload.addTarget(self, action: #selector(autoDownloadSwitch), for: .valueChanged)
  58. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(collapseDocked))
  59. tapGesture.cancelsTouchesInView = false
  60. tapGesture.delegate = self
  61. self.view.addGestureRecognizer(tapGesture)
  62. // navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapCancel))
  63. }
  64. @objc func collapseDocked() {
  65. if ViewController.isExpandButton {
  66. ViewController.expandButton()
  67. }
  68. }
  69. public override func viewWillDisappear(_ animated: Bool) {
  70. separatorLogout.removeFromSuperview()
  71. separatorNotifPersonal.removeFromSuperview()
  72. separatorAutoDownload.removeFromSuperview()
  73. separatorVersion.removeFromSuperview()
  74. separatorLogin.removeFromSuperview()
  75. if ViewController.isExpandButton {
  76. ViewController.expandButton()
  77. }
  78. }
  79. public override func viewDidAppear(_ animated: Bool) {
  80. self.navigationController?.navigationBar.topItem?.title = "Settings".localized()
  81. self.navigationController?.navigationBar.setNeedsLayout()
  82. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
  83. var viewController = UIApplication.shared.windows.first!.rootViewController
  84. if !(viewController is ViewController) {
  85. viewController = self.parent
  86. }
  87. if ViewController.middleButton.isHidden {
  88. ViewController.isExpandButton = false
  89. if let viewController = viewController as? ViewController {
  90. if viewController.tabBar.isHidden {
  91. viewController.tabBar.isHidden = false
  92. ViewController.alwaysHideButton = false
  93. ViewController.middleButton.isHidden = false
  94. }
  95. }
  96. } else if PrefsUtil.getCpaasMode() != PrefsUtil.CPAAS_MODE_DOCKED {
  97. DispatchQueue.main.async {
  98. if let viewController = viewController as? ViewController {
  99. if viewController.tabBar.isHidden {
  100. viewController.tabBar.isHidden = false
  101. ViewController.alwaysHideButton = false
  102. }
  103. }
  104. }
  105. }
  106. })
  107. }
  108. @objc func vibrateModeSwitch() {
  109. UserDefaults.standard.set(switchVibrateMode.isOn, forKey: "vibrateMode")
  110. }
  111. @objc func saveToGallerySwitch() {
  112. if switchSaveToGallery.isOn {
  113. PHPhotoLibrary.requestAuthorization({status in
  114. DispatchQueue.main.async {
  115. if status == .authorized {
  116. UserDefaults.standard.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
  117. } else {
  118. self.switchSaveToGallery.setOn(false, animated: true)
  119. }
  120. }
  121. })
  122. } else {
  123. UserDefaults.standard.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
  124. }
  125. }
  126. @objc func autoDownloadSwitch() {
  127. UserDefaults.standard.set(switchAutoDownload.isOn, forKey: "autoDownload")
  128. }
  129. func makeMenu(imageSignIn: String = ""){
  130. let isChangeProfile = Utils.getSetProfile()
  131. Database.shared.database?.inTransaction({ fmdb, rollback in
  132. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  133. if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id, official_account FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
  134. 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) ?? "") {
  135. Item.menus["Personal"] = [
  136. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  137. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  138. Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
  139. Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
  140. Item(icon: UIImage(named: "ic_internal", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set Internal Account".localized()),
  141. Item(icon: UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set CS Account".localized()),
  142. ]
  143. } else if User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isCallCenter(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isVerified(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
  144. Item.menus["Personal"] = [
  145. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  146. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  147. Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
  148. ]
  149. } else {
  150. Item.menus["Personal"] = [
  151. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  152. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  153. Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
  154. ]
  155. }
  156. if !isChangeProfile {
  157. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
  158. } else if isChangeProfile {
  159. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.clockwise.icloud"), title: "Backup & Restore".localized()))
  160. Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "rectangle.portrait.and.arrow.right"), title: "Sign-Out".localized()))
  161. }
  162. let image = cursorUser.string(forColumnIndex: 1)
  163. if image != nil {
  164. if !image!.isEmpty {
  165. do {
  166. let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  167. let file = documentDir.appendingPathComponent(image!)
  168. if FileManager().fileExists(atPath: file.path) {
  169. let image = UIImage(contentsOfFile: file.path)
  170. Item.menus["Personal"]?[0].icon = image?.circleMasked
  171. if !imageSignIn.isEmpty {
  172. var dataImage: [AnyHashable : Any] = [:]
  173. dataImage["name"] = imageSignIn
  174. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  175. }
  176. } else {
  177. Download().start(forKey: image!) { (name, progress) in
  178. guard progress == 100 else {
  179. return
  180. }
  181. DispatchQueue.main.async {
  182. let image = UIImage(contentsOfFile: file.path)
  183. Item.menus["Personal"]?[0].icon = image?.circleMasked
  184. self.tableView.reloadData()
  185. if !imageSignIn.isEmpty {
  186. var dataImage: [AnyHashable : Any] = [:]
  187. dataImage["name"] = imageSignIn
  188. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  189. }
  190. }
  191. }
  192. }
  193. } catch {}
  194. }
  195. }
  196. cursorUser.close()
  197. } else {
  198. Item.menus["Personal"] = [
  199. Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
  200. Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
  201. Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
  202. Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized())
  203. ]
  204. if !imageSignIn.isEmpty {
  205. do {
  206. let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  207. let file = documentDir.appendingPathComponent(imageSignIn)
  208. if FileManager().fileExists(atPath: file.path) {
  209. let image = UIImage(contentsOfFile: file.path)
  210. Item.menus["Personal"]?[0].icon = image?.circleMasked
  211. var dataImage: [AnyHashable : Any] = [:]
  212. dataImage["name"] = imageSignIn
  213. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  214. } else {
  215. Download().start(forKey: imageSignIn) { (name, progress) in
  216. guard progress == 100 else {
  217. return
  218. }
  219. DispatchQueue.main.async {
  220. let image = UIImage(contentsOfFile: file.path)
  221. Item.menus["Personal"]?[0].icon = image?.circleMasked
  222. self.tableView.reloadData()
  223. var dataImage: [AnyHashable : Any] = [:]
  224. dataImage["name"] = imageSignIn
  225. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  226. }
  227. }
  228. }
  229. } catch {}
  230. }
  231. }
  232. })
  233. Item.menus["Call"] = [
  234. Item(icon: UIImage(systemName: "message"), title: "Notification Message(s)".localized()),
  235. Item(icon: UIImage(systemName: "message"), title: "Notification Message(s) Group".localized()),
  236. Item(icon: UIImage(systemName: "iphone.homebutton.radiowaves.left.and.right"), title: "Vibrate Mode".localized()),
  237. Item(icon: UIImage(systemName: "photo.on.rectangle.angled"), title: "Save to Gallery".localized()),
  238. Item(icon: UIImage(systemName: "arrow.down.square"), title: "Auto Download".localized()),
  239. ]
  240. Item.menus["Version"] = [
  241. Item(icon: UIImage(systemName: "gear"), title: "Version".localized()),
  242. Item(icon: UIImage(named: "pb_powered_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), title: "Powered by Nexilis".localized()),
  243. ]
  244. }
  245. override public func viewWillAppear(_ animated: Bool) {
  246. self.navigationController?.navigationBar.topItem?.title = ""
  247. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
  248. let navBarAppearance = UINavigationBarAppearance()
  249. navBarAppearance.configureWithTransparentBackground()
  250. navigationController?.navigationBar.standardAppearance = navBarAppearance
  251. navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
  252. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.black]
  253. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  254. navigationController?.navigationBar.backgroundColor = .clear
  255. navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  256. navigationController?.navigationBar.shadowImage = UIImage()
  257. navigationController?.navigationBar.isTranslucent = true
  258. navigationController?.setNavigationBarHidden(false, animated: false)
  259. navigationController?.navigationBar.overrideUserInterfaceStyle = .light
  260. navigationController?.navigationBar.barStyle = .default
  261. navigationController?.navigationBar.tintColor = .black
  262. tabBarController?.navigationItem.leftBarButtonItem = nil
  263. tabBarController?.navigationItem.searchController = nil
  264. tabBarController?.navigationItem.rightBarButtonItem = nil
  265. backgroundImage.backgroundColor = .white
  266. backgroundImage.image = nil
  267. DispatchQueue.global().async {
  268. if let listBg = PrefsUtil.getBackground() {
  269. if listBg.isEmpty {
  270. return
  271. }
  272. var bgChoosen = ""
  273. let arrayBg = listBg.split(separator: ",")
  274. bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
  275. ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "/dashboardv2/uploads/background/" + bgChoosen)!) { data, response, error in
  276. guard let data = data, error == nil else { return }
  277. // always update the UI from the main thread
  278. DispatchQueue.main.async() { [self] in
  279. backgroundImage.image = UIImage(data: data)!
  280. }
  281. }
  282. }
  283. }
  284. makeMenu()
  285. tableView.reloadData()
  286. }
  287. // MARK: - Table view data source
  288. public func numberOfSections(in tableView: UITableView) -> Int {
  289. return Item.sections.count
  290. }
  291. public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  292. return 1
  293. }
  294. public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  295. return Item.menuFor(section: section).count
  296. }
  297. public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  298. let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
  299. let isChangeProfile = Utils.getSetProfile()
  300. if !isChangeProfile {
  301. separatorLogout.removeFromSuperview()
  302. } else {
  303. separatorLogin.removeFromSuperview()
  304. }
  305. cell.accessoryType = .none
  306. cell.indentationLevel = 0
  307. var content = cell.defaultContentConfiguration()
  308. content.textProperties.font = UIFont.systemFont(ofSize: 14)
  309. content.secondaryTextProperties.font = UIFont.systemFont(ofSize: 14)
  310. content.secondaryTextProperties.color = .gray
  311. content.prefersSideBySideTextAndSecondaryText = true
  312. let section = Item.sections[indexPath.section]
  313. if let arr = Item.menus[section] {
  314. let menu = arr[indexPath.row]
  315. content.image = menu.icon
  316. content.imageProperties.tintColor = .black
  317. content.imageProperties.maximumSize = CGSize(width: 24, height: 24)
  318. content.text = menu.title
  319. cell.accessoryView = nil
  320. switch menu.title {
  321. case "Personal Information".localized():
  322. cell.accessoryType = .disclosureIndicator
  323. case "Access Admin / Internal Features".localized():
  324. cell.accessoryType = .disclosureIndicator
  325. case "Sign-In to Web".localized():
  326. cell.accessoryType = .disclosureIndicator
  327. case "Sign-Up/Sign-In".localized():
  328. cell.accessoryType = .disclosureIndicator
  329. separatorLogin.removeFromSuperview()
  330. cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorLogin)
  331. case "Notification Message(s)".localized():
  332. cell.accessoryType = .disclosureIndicator
  333. separatorNotifPersonal.removeFromSuperview()
  334. cell.addTopBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorNotifPersonal)
  335. case "Backup & Restore".localized():
  336. cell.accessoryType = .disclosureIndicator
  337. case "Notification Message(s) Group".localized():
  338. cell.accessoryType = .disclosureIndicator
  339. // case "Logout".localized():
  340. case "Change Admin / Internal Password".localized():
  341. cell.accessoryType = .disclosureIndicator
  342. case "Change Language".localized():
  343. cell.accessoryType = .disclosureIndicator
  344. case "Set Internal Account".localized():
  345. cell.accessoryType = .disclosureIndicator
  346. case "Set CS Account".localized():
  347. cell.accessoryType = .disclosureIndicator
  348. case "Version".localized():
  349. let accessoryButton = UIButton(type: .custom)
  350. accessoryButton.setTitle(UIApplication.appVersion, for: .normal)
  351. accessoryButton.setTitleColor(.black, for: .normal)
  352. accessoryButton.contentHorizontalAlignment = .right;
  353. accessoryButton.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
  354. accessoryButton.contentMode = .scaleAspectFit
  355. cell.accessoryView = accessoryButton as UIView
  356. separatorVersion.removeFromSuperview()
  357. cell.addTopBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorVersion)
  358. case "Vibrate Mode".localized():
  359. cell.accessoryView = switchVibrateMode
  360. case "Save to Gallery".localized():
  361. cell.accessoryView = switchSaveToGallery
  362. case "Auto Download".localized():
  363. cell.accessoryView = switchAutoDownload
  364. separatorAutoDownload.removeFromSuperview()
  365. cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorAutoDownload)
  366. case "Sign-Out".localized():
  367. separatorLogout.removeFromSuperview()
  368. cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorLogout)
  369. default:
  370. content.secondaryText = nil
  371. }
  372. }
  373. cell.contentConfiguration = content
  374. return cell
  375. }
  376. public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  377. let item = Item.menuFor(section: indexPath.section)[indexPath.row]
  378. if item.title == "Personal Information".localized() {
  379. if(ViewController.checkIsChangePerson()){
  380. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
  381. controller.data = UserDefaults.standard.string(forKey: "me")!
  382. controller.flag = .me
  383. controller.dismissImage = { image, imageName in
  384. var dataImage: [AnyHashable : Any] = [:]
  385. dataImage["name"] = imageName
  386. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  387. self.makeMenu()
  388. self.tableView.reloadData()
  389. }
  390. navigationController?.show(controller, sender: nil)
  391. }
  392. } else if item.title == "Access Admin / Internal Features".localized() || item.title == "Change Admin / Internal Password".localized() {
  393. if(ViewController.checkIsChangePerson()){
  394. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  395. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  396. imageView.tintColor = .white
  397. 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)
  398. banner.show()
  399. return
  400. }
  401. let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
  402. if(item.title.contains("Change")){
  403. if let action = self.actionChangePassword(for: "admin", title: "Change Admin Password".localized()) {
  404. alertController.addAction(action)
  405. }
  406. if let action = self.actionChangePassword(for: "internal", title: "Change Internal Password".localized()) {
  407. alertController.addAction(action)
  408. }
  409. }
  410. else {
  411. if let action = self.actionLogin(for: "admin", title: "Access Admin Features".localized()) {
  412. alertController.addAction(action)
  413. }
  414. if let action = self.actionLogin(for: "internal", title: "Access Internal Features".localized()) {
  415. alertController.addAction(action)
  416. }
  417. }
  418. alertController.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  419. self.present(alertController, animated: true)
  420. }
  421. } else if item.title == "Change Language".localized() {
  422. let vc = UIViewController()
  423. vc.preferredContentSize = CGSize(width: UIScreen.main.bounds.width - 10, height: 150)
  424. let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 150))
  425. pickerView.dataSource = self
  426. pickerView.delegate = self
  427. let lang = UserDefaults.standard.string(forKey: "i18n_language")
  428. var index = 1
  429. if lang == "id" {
  430. index = 0
  431. }
  432. pickerView.selectRow(index, inComponent: 0, animated: false)
  433. vc.view.addSubview(pickerView)
  434. pickerView.translatesAutoresizingMaskIntoConstraints = false
  435. pickerView.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true
  436. pickerView.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true
  437. let alert = UIAlertController(title: "Select Language".localized(), message: "", preferredStyle: .actionSheet)
  438. alert.setValue(vc, forKey: "contentViewController")
  439. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { (UIAlertAction) in
  440. }))
  441. alert.addAction(UIAlertAction(title: "Select".localized(), style: .default, handler: { (UIAlertAction) in
  442. let selectedIndex = pickerView.selectedRow(inComponent: 0)
  443. let lang = self.language[selectedIndex].values.first
  444. UserDefaults.standard.set(lang, forKey: "i18n_language")
  445. self.navigationController?.navigationBar.topItem?.title = "Settings".localized();
  446. self.navigationController?.navigationBar.setNeedsLayout()
  447. self.makeMenu()
  448. self.tableView.reloadData()
  449. FirstTabViewController.forceRefresh = true
  450. ThirdTabViewController.forceRefresh = true
  451. FirstTabViewController.showModal = false
  452. ThirdTabViewController.showModal = false
  453. }))
  454. self.present(alert, animated: true, completion: nil)
  455. } else if item.title == "Sign-In".localized() {
  456. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
  457. controller.isDismiss = { newThumb in
  458. self.makeMenu(imageSignIn: newThumb)
  459. self.tableView.reloadData()
  460. }
  461. navigationController?.show(controller, sender: nil)
  462. } else if item.title == "Sign-Up/Sign-In".localized() {
  463. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
  464. controller.isDismiss = { newThumb in
  465. self.makeMenu(imageSignIn: newThumb)
  466. self.tableView.reloadData()
  467. FirstTabViewController.forceRefresh = true
  468. ThirdTabViewController.forceRefresh = true
  469. FirstTabViewController.showModal = false
  470. ThirdTabViewController.showModal = false
  471. }
  472. navigationController?.show(controller, sender: nil)
  473. } else if item.title == "Sign-Out".localized() {
  474. let alert = UIAlertController(title: "Sign-Out".localized(), message: "Are you sure want to logout?".localized(), preferredStyle: .alert)
  475. alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
  476. alert.addAction(UIAlertAction(title: "Yes".localized(), style: .destructive, handler: {(_) in
  477. var viewController = UIApplication.shared.windows.first!.rootViewController
  478. if !(viewController is ViewController) {
  479. viewController = self.parent
  480. }
  481. if let viewController = viewController as? ViewController {
  482. if !(viewController.selectedViewController is FourthTabViewController) {
  483. viewController.selectedIndex = (viewController.viewControllers?.firstIndex(of: viewController.fourthTab!))!
  484. }
  485. }
  486. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  487. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  488. imageView.tintColor = .white
  489. 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)
  490. banner.show()
  491. return
  492. }
  493. Nexilis.showLoader()
  494. DispatchQueue.global().async {
  495. let apiKey = Nexilis.sAPIKey
  496. var id = UIDevice.current.identifierForVendor?.uuidString ?? "UNK-DEVICE"
  497. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000) {
  498. id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
  499. if(!id.isEmpty){
  500. Nexilis.changeUser(f_pin: id)
  501. UserDefaults.standard.setValue(id, forKey: "me")
  502. Utils.setProfile(value: false)
  503. UserDefaults.standard.synchronize()
  504. if Utils.getForceAnonymous() {
  505. self.deleteAllRecordDatabase()
  506. UserDefaults.standard.removeObject(forKey: "device_id")
  507. Nexilis.destroyAll()
  508. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
  509. }
  510. DispatchQueue.main.async {
  511. Nexilis.hideLoader(completion: {
  512. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  513. imageView.tintColor = .white
  514. 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)
  515. banner.show()
  516. var dataImage: [AnyHashable : Any] = [:]
  517. dataImage["name"] = ""
  518. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
  519. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
  520. self.makeMenu()
  521. self.tableView.reloadData()
  522. FirstTabViewController.forceRefresh = true
  523. ThirdTabViewController.forceRefresh = true
  524. FirstTabViewController.showModal = false
  525. ThirdTabViewController.showModal = false
  526. })
  527. }
  528. if !Utils.getForceAnonymous() {
  529. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
  530. var viewController = UIApplication.shared.windows.first!.rootViewController
  531. if !(viewController is ViewController) {
  532. viewController = self.parent
  533. }
  534. if let viewController = viewController as? ViewController {
  535. viewController.viewWillAppear(false)
  536. }
  537. })
  538. }
  539. } else {
  540. Nexilis.hideLoader(completion: {
  541. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  542. imageView.tintColor = .white
  543. 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)
  544. banner.show()
  545. })
  546. }
  547. } else {
  548. DispatchQueue.main.async {
  549. Nexilis.hideLoader(completion: {
  550. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  551. imageView.tintColor = .white
  552. 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)
  553. banner.show()
  554. })
  555. }
  556. }
  557. }
  558. }))
  559. self.present(alert, animated: true, completion: nil)
  560. } else if item.title == "Sign-In to Web".localized() {
  561. var permissionCheck = -1
  562. if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
  563. permissionCheck = 1
  564. } else if AVCaptureDevice.authorizationStatus(for: .video) == .denied {
  565. permissionCheck = 0
  566. } else {
  567. AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) -> Void in
  568. if granted == true {
  569. permissionCheck = 1
  570. } else {
  571. permissionCheck = 0
  572. }
  573. })
  574. }
  575. while permissionCheck == -1 {
  576. sleep(1)
  577. }
  578. if permissionCheck == 0 {
  579. let alert = UIAlertController(title: "Attention!".localized(), message: "Please allow camera permission in your settings".localized(), preferredStyle: .alert)
  580. alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: { _ in
  581. if let url = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(url) {
  582. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  583. }
  584. }))
  585. if UIApplication.shared.visibleViewController?.navigationController != nil {
  586. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  587. } else {
  588. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  589. }
  590. return
  591. }
  592. let controller = ScannerViewController()
  593. let navigationController = UINavigationController(rootViewController: controller)
  594. navigationController.navigationBar.tintColor = .white
  595. navigationController.navigationBar.barTintColor = .mainColor
  596. navigationController.navigationBar.isTranslucent = false
  597. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
  598. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  599. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  600. navigationController.navigationBar.titleTextAttributes = textAttributes
  601. navigationController.view.backgroundColor = .mainColor
  602. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  603. navigationController.navigationBar.barStyle = .black
  604. navigationController.modalPresentationStyle = .custom
  605. self.present(navigationController, animated: true)
  606. } else if item.title == "Notification Message(s)".localized() || item.title == "Notification Message(s) Group".localized() {
  607. let controller = NotificationSound()
  608. if item.title != "Notification Message(s)".localized() {
  609. controller.isPersonal = false
  610. }
  611. let navigationController = UINavigationController(rootViewController: controller)
  612. navigationController.navigationBar.tintColor = .white
  613. navigationController.navigationBar.barTintColor = .mainColor
  614. navigationController.navigationBar.isTranslucent = false
  615. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  616. navigationController.navigationBar.barStyle = .black
  617. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
  618. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  619. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  620. navigationController.navigationBar.titleTextAttributes = textAttributes
  621. navigationController.view.backgroundColor = .mainColor
  622. self.present(navigationController, animated: true)
  623. } else if item.title == "Backup & Restore".localized() {
  624. let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "backupRestore") as! BackupRestoreView
  625. navigationController?.show(controller, sender: nil)
  626. } else if item.title == "Set Internal Account".localized() {
  627. let controller = SetInternalCSAccount()
  628. navigationController?.show(controller, sender: nil)
  629. } else if item.title == "Set CS Account".localized() {
  630. let controller = SetInternalCSAccount()
  631. controller.isSetCS = true
  632. navigationController?.show(controller, sender: nil)
  633. }
  634. }
  635. private func actionLogin(for type: String, title: String) -> UIAlertAction? {
  636. return UIAlertAction(title: title, style: .default) { _ in
  637. self.alert = UIAlertController(title:"Access Admin Features".localized(), message: nil, preferredStyle: .alert)
  638. if type == "internal" {
  639. self.alert = UIAlertController(title: "Access Internal Features".localized(), message: nil, preferredStyle: .alert)
  640. }
  641. self.textFields.removeAll()
  642. self.alert?.addTextField{ (texfield) in
  643. texfield.placeholder = "Password".localized()
  644. texfield.isSecureTextEntry = true
  645. texfield.addPadding(.right(40))
  646. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  647. let buttonHideUnhide = UIButton()
  648. buttonHideUnhide.tag = 0
  649. texfield.addSubview(buttonHideUnhide)
  650. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  651. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  652. buttonHideUnhide.tintColor = .black
  653. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  654. }
  655. let submitAction = UIAlertAction(title: "Sign-In".localized(), style: .default, handler: { (action) -> Void in
  656. let textField = self.alert?.textFields![0]
  657. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  658. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  659. imageView.tintColor = .white
  660. 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)
  661. banner.show()
  662. return
  663. }
  664. Nexilis.showLoader()
  665. if type == "admin" {
  666. self.signInAdmin(password: textField!.text!, completion: { result in
  667. if result {
  668. DispatchQueue.main.async {
  669. Nexilis.hideLoader {
  670. self.makeMenu()
  671. self.tableView.reloadData()
  672. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  673. imageView.tintColor = .white
  674. 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)
  675. banner.show()
  676. }
  677. }
  678. } else {
  679. DispatchQueue.main.async {
  680. Nexilis.hideLoader {}
  681. }
  682. }
  683. })
  684. } else {
  685. self.signInInternal(password: textField!.text!, completion: { result in
  686. if result {
  687. DispatchQueue.main.async {
  688. Nexilis.hideLoader {
  689. self.makeMenu()
  690. self.tableView.reloadData()
  691. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  692. imageView.tintColor = .white
  693. 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)
  694. banner.show()
  695. }
  696. }
  697. } else {
  698. DispatchQueue.main.async {
  699. Nexilis.hideLoader {}
  700. }
  701. }
  702. })
  703. }
  704. })
  705. submitAction.isEnabled = false
  706. self.alert?.addAction(submitAction)
  707. self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  708. self.present(self.alert!, animated: true, completion: nil)
  709. }
  710. }
  711. private func actionChangePassword(for type: String, title: String) -> UIAlertAction? {
  712. return UIAlertAction(title: title, style: .default) { _ in
  713. self.alert = UIAlertController(title: "Change Admin Password".localized(), message: nil, preferredStyle: .alert)
  714. if type == "internal" {
  715. self.alert = UIAlertController(title: "Change Internal Password".localized(), message: nil, preferredStyle: .alert)
  716. }
  717. self.textFields.removeAll()
  718. self.alert?.addTextField{ (texfield) in
  719. texfield.placeholder = "Old Password"
  720. texfield.isSecureTextEntry = true
  721. texfield.addPadding(.right(40))
  722. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  723. self.textFields.append(texfield)
  724. let buttonHideUnhide = UIButton()
  725. buttonHideUnhide.tag = 0
  726. texfield.addSubview(buttonHideUnhide)
  727. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  728. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  729. buttonHideUnhide.tintColor = .black
  730. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  731. }
  732. self.alert?.addTextField{ (texfield) in
  733. texfield.placeholder = "New Password"
  734. texfield.isSecureTextEntry = true
  735. texfield.addPadding(.right(40))
  736. texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
  737. self.textFields.append(texfield)
  738. let buttonHideUnhide = UIButton()
  739. buttonHideUnhide.tag = 1
  740. texfield.addSubview(buttonHideUnhide)
  741. buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
  742. buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  743. buttonHideUnhide.tintColor = .black
  744. buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
  745. }
  746. let submitAction = UIAlertAction(title: "Change Password".localized(), style: .default, handler: { (action) -> Void in
  747. let textFieldOld = self.alert?.textFields![0]
  748. let textFieldNew = self.alert?.textFields![1]
  749. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  750. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  751. imageView.tintColor = .white
  752. 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)
  753. banner.show()
  754. return
  755. }
  756. if type == "admin" {
  757. self.changePasswordAdmin(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
  758. if result {
  759. DispatchQueue.main.async {
  760. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  761. imageView.tintColor = .white
  762. 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)
  763. banner.show()
  764. }
  765. }
  766. })
  767. } else {
  768. self.changePasswordInternal(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
  769. if result {
  770. DispatchQueue.main.async {
  771. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  772. imageView.tintColor = .white
  773. 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)
  774. banner.show()
  775. }
  776. }
  777. })
  778. }
  779. })
  780. submitAction.isEnabled = false
  781. self.alert?.addAction(submitAction)
  782. self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
  783. self.present(self.alert!, animated: true, completion: nil)
  784. }
  785. }
  786. @objc func showPassword(_ sender:UIButton) {
  787. if alert!.textFields![sender.tag].isSecureTextEntry {
  788. alert!.textFields![sender.tag].isSecureTextEntry = false
  789. let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
  790. buttonImage.setImage(UIImage(systemName: "eye.fill"), for: .normal)
  791. } else {
  792. alert!.textFields![sender.tag].isSecureTextEntry = true
  793. let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
  794. buttonImage.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
  795. }
  796. }
  797. @objc func alertTextFieldDidChange(_ sender: UITextField) {
  798. if(!textFields.isEmpty){
  799. //print("text count 0: \(textFields[0].text!.count)")
  800. //print("text count 1: \(textFields[1].text!.count)")
  801. alert?.actions[0].isEnabled = textFields[0].text!.count > 0 && textFields[1].text!.count > 0
  802. }
  803. else {
  804. alert?.actions[0].isEnabled = sender.text!.count > 0
  805. }
  806. }
  807. private func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
  808. DispatchQueue.global().async {
  809. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  810. let p_password = password
  811. let md5Hex = p_password
  812. var result: Bool = false
  813. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
  814. if response.isOk() {
  815. result = true
  816. }
  817. DispatchQueue.main.async {
  818. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  819. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  820. imageView.tintColor = .white
  821. 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)
  822. banner.show()
  823. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  824. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  825. imageView.tintColor = .white
  826. 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)
  827. banner.show()
  828. }
  829. }
  830. } else {
  831. DispatchQueue.main.async {
  832. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  833. imageView.tintColor = .white
  834. 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)
  835. banner.show()
  836. }
  837. }
  838. completion(result)
  839. }
  840. }
  841. private func signInInternal(password: String, completion: @escaping (Bool) -> ()) {
  842. DispatchQueue.global().async {
  843. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  844. let p_password = password
  845. let md5Hex = p_password
  846. var result: Bool = false
  847. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiInternal(p_name: idMe!, p_password: md5Hex)) {
  848. if response.isOk() {
  849. result = true
  850. }
  851. DispatchQueue.main.async {
  852. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  853. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  854. imageView.tintColor = .white
  855. 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)
  856. banner.show()
  857. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  858. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  859. imageView.tintColor = .white
  860. 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)
  861. banner.show()
  862. }
  863. }
  864. } else {
  865. DispatchQueue.main.async {
  866. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  867. imageView.tintColor = .white
  868. 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)
  869. banner.show()
  870. }
  871. }
  872. completion(result)
  873. }
  874. }
  875. private func changePasswordAdmin(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
  876. DispatchQueue.global().async {
  877. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  878. let p_password = oldPassword
  879. let n_password = newPassword
  880. let md5Hex = p_password
  881. let md5HexNew = n_password
  882. var result: Bool = false
  883. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordAdmin(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
  884. if response.isOk() {
  885. result = true
  886. }
  887. DispatchQueue.main.async {
  888. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  889. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  890. imageView.tintColor = .white
  891. 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)
  892. banner.show()
  893. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  894. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  895. imageView.tintColor = .white
  896. 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)
  897. banner.show()
  898. }
  899. }
  900. } else {
  901. DispatchQueue.main.async {
  902. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  903. imageView.tintColor = .white
  904. 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)
  905. banner.show()
  906. }
  907. }
  908. completion(result)
  909. }
  910. }
  911. private func changePasswordInternal(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
  912. DispatchQueue.global().async {
  913. let idMe = UserDefaults.standard.string(forKey: "me") as String?
  914. let p_password = oldPassword
  915. let n_password = newPassword
  916. let md5Hex = p_password
  917. let md5HexNew = n_password
  918. var result: Bool = false
  919. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordInternal(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
  920. if response.isOk() {
  921. result = true
  922. }
  923. DispatchQueue.main.async {
  924. if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
  925. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  926. imageView.tintColor = .white
  927. 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)
  928. banner.show()
  929. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
  930. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  931. imageView.tintColor = .white
  932. 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)
  933. banner.show()
  934. }
  935. }
  936. } else {
  937. DispatchQueue.main.async {
  938. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  939. imageView.tintColor = .white
  940. 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)
  941. banner.show()
  942. }
  943. }
  944. completion(result)
  945. }
  946. }
  947. }
  948. // MARK: - Item
  949. struct Item: Hashable {
  950. static func == (lhs: Item, rhs: Item) -> Bool {
  951. return lhs.title == rhs.title
  952. }
  953. var icon: UIImage?
  954. var title = ""
  955. static var sections: [String] {
  956. return ["Personal", "Call", "Version"]
  957. }
  958. static var menus: [String: [Item]] = [:]
  959. static func menuFor(section: Int) -> [Item] {
  960. let sec = sections[section]
  961. if let arr = menus[sec] {
  962. return arr
  963. }
  964. return []
  965. }
  966. }
  967. extension FourthTabViewController: UIPickerViewDelegate, UIPickerViewDataSource {
  968. public func numberOfComponents(in pickerView: UIPickerView) -> Int {
  969. return 1
  970. }
  971. public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
  972. return language.count
  973. }
  974. public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
  975. return 60
  976. }
  977. public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
  978. let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 30))
  979. label.text = (language[row]).keys.first
  980. label.sizeToFit()
  981. return label
  982. }
  983. }