FourthTabViewController.swift 60 KB

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