FourthTabViewController.swift 66 KB

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