FourthTabViewController.swift 66 KB

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