FourthTabViewController.swift 63 KB

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