123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- //
- // SettingTableViewController.swift
- // Qmera
- //
- // Created by Yayan Dwi on 16/09/21.
- //
- import UIKit
- import NotificationBannerSwift
- import nuSDKService
- import NexilisLite
- import Photos
- public class FourthTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UIGestureRecognizerDelegate {
-
- var language: [[String: String]] = [["Indonesia": "id"],["English": "en"]]
- var alert: UIAlertController?
- var textFields = [UITextField]()
-
- var switchVibrateMode = UISwitch()
- var switchSaveToGallery = UISwitch()
- var switchAutoDownload = UISwitch()
-
- let separatorLogout = UIView()
- let separatorNotifPersonal = UIView()
- let separatorAutoDownload = UIView()
- let separatorVersion = UIView()
- let separatorLogin = UIView()
-
- @IBOutlet weak var tableView: UITableView!
- @IBOutlet weak var backgroundImage: UIImageView!
-
- var notInTab = false
-
- public override func viewDidLoad() {
- super.viewDidLoad()
-
- tableView.delegate = self
- tableView.dataSource = self
- tableView.layoutMargins = .init(top: 0, left: 0, bottom: 0, right: 0)
- // tableView.separatorColor = .gray
- tableView.separatorStyle = .none
-
- if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
- tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 80, right: 0)
- }
-
- switchVibrateMode.tintColor = .gray
- switchSaveToGallery.tintColor = .gray
- switchAutoDownload.tintColor = .gray
- switchVibrateMode.onTintColor = .mainColor
- switchSaveToGallery.onTintColor = .mainColor
- switchAutoDownload.onTintColor = .mainColor
- let vibrateMode = UserDefaults.standard.bool(forKey: "vibrateMode")
- let saveGallery = UserDefaults.standard.bool(forKey: "saveToGallery")
- let autoDownload = UserDefaults.standard.bool(forKey: "autoDownload")
- if vibrateMode {
- switchVibrateMode.setOn(true, animated: false)
- }
- if saveGallery {
- switchSaveToGallery.setOn(true, animated: false)
- }
- if autoDownload {
- switchAutoDownload.setOn(true, animated: false)
- }
- switchVibrateMode.addTarget(self, action: #selector(vibrateModeSwitch), for: .valueChanged)
- switchSaveToGallery.addTarget(self, action: #selector(saveToGallerySwitch), for: .valueChanged)
- switchAutoDownload.addTarget(self, action: #selector(autoDownloadSwitch), for: .valueChanged)
-
- let tapGesture = UITapGestureRecognizer(target: self, action: #selector(collapseDocked))
- tapGesture.cancelsTouchesInView = false
- tapGesture.delegate = self
- self.view.addGestureRecognizer(tapGesture)
-
- // navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapCancel))
- }
-
- @objc func collapseDocked() {
- if ViewController.isExpandButton {
- ViewController.expandButton()
- }
- }
- public override func viewWillDisappear(_ animated: Bool) {
- separatorLogout.removeFromSuperview()
- separatorNotifPersonal.removeFromSuperview()
- separatorAutoDownload.removeFromSuperview()
- separatorVersion.removeFromSuperview()
- separatorLogin.removeFromSuperview()
- if ViewController.isExpandButton {
- ViewController.expandButton()
- }
- }
-
- public override func viewDidAppear(_ animated: Bool) {
- self.navigationController?.navigationBar.topItem?.title = "Settings".localized()
- self.navigationController?.navigationBar.setNeedsLayout()
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
- var viewController = UIApplication.shared.windows.first!.rootViewController
- if !(viewController is ViewController) {
- viewController = self.parent
- }
- if ViewController.middleButton.isHidden {
- ViewController.isExpandButton = false
- if let viewController = viewController as? ViewController {
- if viewController.tabBar.isHidden {
- viewController.tabBar.isHidden = false
- ViewController.alwaysHideButton = false
- ViewController.middleButton.isHidden = false
- }
- }
- } else if PrefsUtil.getCpaasMode() != PrefsUtil.CPAAS_MODE_DOCKED {
- DispatchQueue.main.async {
- if let viewController = viewController as? ViewController {
- if viewController.tabBar.isHidden {
- viewController.tabBar.isHidden = false
- ViewController.alwaysHideButton = false
- }
- }
- }
- }
- })
- }
-
- @objc func vibrateModeSwitch() {
- UserDefaults.standard.set(switchVibrateMode.isOn, forKey: "vibrateMode")
- }
-
- @objc func saveToGallerySwitch() {
- if switchSaveToGallery.isOn {
- PHPhotoLibrary.requestAuthorization({status in
- DispatchQueue.main.async {
- if status == .authorized {
- UserDefaults.standard.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
- } else {
- self.switchSaveToGallery.setOn(false, animated: true)
- }
- }
- })
- } else {
- UserDefaults.standard.set(self.switchSaveToGallery.isOn, forKey: "saveToGallery")
- }
- }
-
- @objc func autoDownloadSwitch() {
- UserDefaults.standard.set(switchAutoDownload.isOn, forKey: "autoDownload")
- }
-
- func makeMenu(imageSignIn: String = ""){
- let isChangeProfile = Utils.getSetProfile()
- Database.shared.database?.inTransaction({ fmdb, rollback in
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id, official_account FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
- 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) ?? "") {
- Item.menus["Personal"] = [
- Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
- Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
- Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
- Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
- Item(icon: UIImage(named: "ic_internal", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set Internal Account".localized()),
- Item(icon: UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set CS Account".localized()),
- ]
- } else if User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isCallCenter(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isVerified(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
- Item.menus["Personal"] = [
- Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
- Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
- Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
- ]
- } else {
- Item.menus["Personal"] = [
- Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
- Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
- Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
- ]
- }
- if !isChangeProfile {
- Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
- } else if isChangeProfile {
- Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.clockwise.icloud"), title: "Backup & Restore".localized()))
- Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "rectangle.portrait.and.arrow.right"), title: "Sign-Out".localized()))
- }
- let image = cursorUser.string(forColumnIndex: 1)
- if image != nil {
- if !image!.isEmpty {
- do {
- let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
- let file = documentDir.appendingPathComponent(image!)
- if FileManager().fileExists(atPath: file.path) {
- let image = UIImage(contentsOfFile: file.path)
- Item.menus["Personal"]?[0].icon = image?.circleMasked
- if !imageSignIn.isEmpty {
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageSignIn
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- }
- } else {
- Download().start(forKey: image!) { (name, progress) in
- guard progress == 100 else {
- return
- }
- DispatchQueue.main.async {
- let image = UIImage(contentsOfFile: file.path)
- Item.menus["Personal"]?[0].icon = image?.circleMasked
- self.tableView.reloadData()
- if !imageSignIn.isEmpty {
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageSignIn
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- }
- }
- }
- }
- } catch {}
- }
- }
- cursorUser.close()
- } else {
- Item.menus["Personal"] = [
- Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
- Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
- Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
- Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized())
- ]
- if !imageSignIn.isEmpty {
- do {
- let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
- let file = documentDir.appendingPathComponent(imageSignIn)
- if FileManager().fileExists(atPath: file.path) {
- let image = UIImage(contentsOfFile: file.path)
- Item.menus["Personal"]?[0].icon = image?.circleMasked
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageSignIn
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- } else {
- Download().start(forKey: imageSignIn) { (name, progress) in
- guard progress == 100 else {
- return
- }
- DispatchQueue.main.async {
- let image = UIImage(contentsOfFile: file.path)
- Item.menus["Personal"]?[0].icon = image?.circleMasked
- self.tableView.reloadData()
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageSignIn
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- }
- }
- }
- } catch {}
- }
- }
- })
-
- Item.menus["Call"] = [
- Item(icon: UIImage(systemName: "message"), title: "Notification Message(s)".localized()),
- Item(icon: UIImage(systemName: "message"), title: "Notification Message(s) Group".localized()),
- Item(icon: UIImage(systemName: "iphone.homebutton.radiowaves.left.and.right"), title: "Vibrate Mode".localized()),
- Item(icon: UIImage(systemName: "photo.on.rectangle.angled"), title: "Save to Gallery".localized()),
- Item(icon: UIImage(systemName: "arrow.down.square"), title: "Auto Download".localized()),
- ]
- Item.menus["Version"] = [
- Item(icon: UIImage(systemName: "gear"), title: "Version".localized()),
- Item(icon: UIImage(named: "pb_powered_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), title: "Powered by Nexilis".localized()),
- ]
- }
-
- override public func viewWillAppear(_ animated: Bool) {
- self.navigationController?.navigationBar.topItem?.title = ""
- self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
- let navBarAppearance = UINavigationBarAppearance()
- navBarAppearance.configureWithTransparentBackground()
- navigationController?.navigationBar.standardAppearance = navBarAppearance
- navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.black]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- navigationController?.navigationBar.backgroundColor = .clear
- navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
- navigationController?.navigationBar.shadowImage = UIImage()
- navigationController?.navigationBar.isTranslucent = true
- navigationController?.setNavigationBarHidden(false, animated: false)
- navigationController?.navigationBar.overrideUserInterfaceStyle = .light
- navigationController?.navigationBar.barStyle = .default
- navigationController?.navigationBar.tintColor = .black
- tabBarController?.navigationItem.leftBarButtonItem = nil
- tabBarController?.navigationItem.searchController = nil
- tabBarController?.navigationItem.rightBarButtonItem = nil
- backgroundImage.backgroundColor = .white
- backgroundImage.image = nil
- DispatchQueue.global().async {
- if let listBg = PrefsUtil.getBackground() {
- if listBg.isEmpty {
- return
- }
- var bgChoosen = ""
- let arrayBg = listBg.split(separator: ",")
- bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "/dashboardv2/uploads/background/" + bgChoosen)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() { [self] in
- backgroundImage.image = UIImage(data: data)!
- }
- }
- }
- }
- makeMenu()
- tableView.reloadData()
- }
-
- // MARK: - Table view data source
-
- public func numberOfSections(in tableView: UITableView) -> Int {
- return Item.sections.count
- }
-
- public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 1
- }
-
- public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return Item.menuFor(section: section).count
- }
-
- public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- separatorLogout.removeFromSuperview()
- } else {
- separatorLogin.removeFromSuperview()
- }
- cell.accessoryType = .none
- cell.indentationLevel = 0
- var content = cell.defaultContentConfiguration()
- content.textProperties.font = UIFont.systemFont(ofSize: 14)
- content.secondaryTextProperties.font = UIFont.systemFont(ofSize: 14)
- content.secondaryTextProperties.color = .gray
- content.prefersSideBySideTextAndSecondaryText = true
- let section = Item.sections[indexPath.section]
- if let arr = Item.menus[section] {
- let menu = arr[indexPath.row]
- content.image = menu.icon
- content.imageProperties.tintColor = .black
- content.imageProperties.maximumSize = CGSize(width: 24, height: 24)
- content.text = menu.title
- cell.accessoryView = nil
- switch menu.title {
- case "Personal Information".localized():
- cell.accessoryType = .disclosureIndicator
- case "Access Admin / Internal Features".localized():
- cell.accessoryType = .disclosureIndicator
- case "Sign-In to Web".localized():
- cell.accessoryType = .disclosureIndicator
- case "Sign-Up/Sign-In".localized():
- cell.accessoryType = .disclosureIndicator
- separatorLogin.removeFromSuperview()
- cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorLogin)
- case "Notification Message(s)".localized():
- cell.accessoryType = .disclosureIndicator
- separatorNotifPersonal.removeFromSuperview()
- cell.addTopBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorNotifPersonal)
- case "Backup & Restore".localized():
- cell.accessoryType = .disclosureIndicator
- case "Notification Message(s) Group".localized():
- cell.accessoryType = .disclosureIndicator
- // case "Logout".localized():
- case "Change Admin / Internal Password".localized():
- cell.accessoryType = .disclosureIndicator
- case "Change Language".localized():
- cell.accessoryType = .disclosureIndicator
- case "Set Internal Account".localized():
- cell.accessoryType = .disclosureIndicator
- case "Set CS Account".localized():
- cell.accessoryType = .disclosureIndicator
- case "Version".localized():
- let accessoryButton = UIButton(type: .custom)
- accessoryButton.setTitle(UIApplication.appVersion, for: .normal)
- accessoryButton.setTitleColor(.black, for: .normal)
- accessoryButton.contentHorizontalAlignment = .right;
- accessoryButton.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
- accessoryButton.contentMode = .scaleAspectFit
- cell.accessoryView = accessoryButton as UIView
- separatorVersion.removeFromSuperview()
- cell.addTopBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorVersion)
- case "Vibrate Mode".localized():
- cell.accessoryView = switchVibrateMode
- case "Save to Gallery".localized():
- cell.accessoryView = switchSaveToGallery
- case "Auto Download".localized():
- cell.accessoryView = switchAutoDownload
- separatorAutoDownload.removeFromSuperview()
- cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorAutoDownload)
- case "Sign-Out".localized():
- separatorLogout.removeFromSuperview()
- cell.addBottomBorder(with: .lightGray.withAlphaComponent(0.5), andWidth: 1, view: separatorLogout)
- default:
- content.secondaryText = nil
- }
- }
- cell.contentConfiguration = content
- return cell
- }
-
- public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let item = Item.menuFor(section: indexPath.section)[indexPath.row]
- if item.title == "Personal Information".localized() {
- if(ViewController.checkIsChangePerson()){
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "profileView") as! ProfileViewController
- controller.data = UserDefaults.standard.string(forKey: "me")!
- controller.flag = .me
- controller.dismissImage = { image, imageName in
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = imageName
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- self.makeMenu()
- self.tableView.reloadData()
- }
- navigationController?.show(controller, sender: nil)
- }
- } else if item.title == "Access Admin / Internal Features".localized() || item.title == "Change Admin / Internal Password".localized() {
- if(ViewController.checkIsChangePerson()){
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- if(item.title.contains("Change")){
- if let action = self.actionChangePassword(for: "admin", title: "Change Admin Password".localized()) {
- alertController.addAction(action)
- }
- if let action = self.actionChangePassword(for: "internal", title: "Change Internal Password".localized()) {
- alertController.addAction(action)
- }
- }
- else {
- if let action = self.actionLogin(for: "admin", title: "Access Admin Features".localized()) {
- alertController.addAction(action)
- }
- if let action = self.actionLogin(for: "internal", title: "Access Internal Features".localized()) {
- alertController.addAction(action)
- }
- }
- alertController.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
- self.present(alertController, animated: true)
- }
- } else if item.title == "Change Language".localized() {
- let vc = UIViewController()
- vc.preferredContentSize = CGSize(width: UIScreen.main.bounds.width - 10, height: 150)
- let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 150))
- pickerView.dataSource = self
- pickerView.delegate = self
-
- let lang = UserDefaults.standard.string(forKey: "i18n_language")
- var index = 1
- if lang == "id" {
- index = 0
- }
- pickerView.selectRow(index, inComponent: 0, animated: false)
-
- vc.view.addSubview(pickerView)
- pickerView.translatesAutoresizingMaskIntoConstraints = false
- pickerView.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true
- pickerView.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true
-
- let alert = UIAlertController(title: "Select Language".localized(), message: "", preferredStyle: .actionSheet)
-
- alert.setValue(vc, forKey: "contentViewController")
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { (UIAlertAction) in
- }))
-
- alert.addAction(UIAlertAction(title: "Select".localized(), style: .default, handler: { (UIAlertAction) in
- let selectedIndex = pickerView.selectedRow(inComponent: 0)
- let lang = self.language[selectedIndex].values.first
- UserDefaults.standard.set(lang, forKey: "i18n_language")
- self.navigationController?.navigationBar.topItem?.title = "Settings".localized();
- self.navigationController?.navigationBar.setNeedsLayout()
- self.makeMenu()
- self.tableView.reloadData()
- FirstTabViewController.forceRefresh = true
- ThirdTabViewController.forceRefresh = true
- FirstTabViewController.showModal = false
- ThirdTabViewController.showModal = false
- }))
- self.present(alert, animated: true, completion: nil)
- } else if item.title == "Sign-In".localized() {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
- controller.isDismiss = { newThumb in
- self.makeMenu(imageSignIn: newThumb)
- self.tableView.reloadData()
- }
- navigationController?.show(controller, sender: nil)
- } else if item.title == "Sign-Up/Sign-In".localized() {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
- controller.isDismiss = { newThumb in
- self.makeMenu(imageSignIn: newThumb)
- self.tableView.reloadData()
- FirstTabViewController.forceRefresh = true
- ThirdTabViewController.forceRefresh = true
- FirstTabViewController.showModal = false
- ThirdTabViewController.showModal = false
- }
- navigationController?.show(controller, sender: nil)
- } else if item.title == "Sign-Out".localized() {
- let alert = UIAlertController(title: "Sign-Out".localized(), message: "Are you sure want to logout?".localized(), preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
- alert.addAction(UIAlertAction(title: "Yes".localized(), style: .destructive, handler: {(_) in
- var viewController = UIApplication.shared.windows.first!.rootViewController
- if !(viewController is ViewController) {
- viewController = self.parent
- }
- if let viewController = viewController as? ViewController {
- if !(viewController.selectedViewController is FourthTabViewController) {
- viewController.selectedIndex = (viewController.viewControllers?.firstIndex(of: viewController.fourthTab!))!
- }
- }
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- Nexilis.showLoader()
- DispatchQueue.global().async {
- let apiKey = Nexilis.sAPIKey
- var id = UIDevice.current.identifierForVendor?.uuidString ?? "UNK-DEVICE"
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000) {
- id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
- if(!id.isEmpty){
- Nexilis.changeUser(f_pin: id)
- UserDefaults.standard.setValue(id, forKey: "me")
- Utils.setProfile(value: false)
- UserDefaults.standard.synchronize()
- if Utils.getForceAnonymous() {
- self.deleteAllRecordDatabase()
- UserDefaults.standard.removeObject(forKey: "device_id")
- Nexilis.destroyAll()
- _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
- }
- DispatchQueue.main.async {
- Nexilis.hideLoader(completion: {
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- var dataImage: [AnyHashable : Any] = [:]
- dataImage["name"] = ""
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
- self.makeMenu()
- self.tableView.reloadData()
- FirstTabViewController.forceRefresh = true
- ThirdTabViewController.forceRefresh = true
- FirstTabViewController.showModal = false
- ThirdTabViewController.showModal = false
- })
- }
- if !Utils.getForceAnonymous() {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
- var viewController = UIApplication.shared.windows.first!.rootViewController
- if !(viewController is ViewController) {
- viewController = self.parent
- }
- if let viewController = viewController as? ViewController {
- viewController.viewWillAppear(false)
- }
- })
- }
- } else {
- Nexilis.hideLoader(completion: {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- })
- }
- } else {
- DispatchQueue.main.async {
- Nexilis.hideLoader(completion: {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- })
- }
- }
- }
- }))
- self.present(alert, animated: true, completion: nil)
- } else if item.title == "Sign-In to Web".localized() {
- var permissionCheck = -1
- if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
- permissionCheck = 1
- } else if AVCaptureDevice.authorizationStatus(for: .video) == .denied {
- permissionCheck = 0
- } else {
- AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) -> Void in
- if granted == true {
- permissionCheck = 1
- } else {
- permissionCheck = 0
- }
- })
- }
-
- while permissionCheck == -1 {
- sleep(1)
- }
-
- if permissionCheck == 0 {
- let alert = UIAlertController(title: "Attention!".localized(), message: "Please allow camera permission in your settings".localized(), preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: { _ in
- if let url = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(url) {
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
- }
- }))
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
- }
- return
- }
- let controller = ScannerViewController()
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- navigationController.modalPresentationStyle = .custom
- self.present(navigationController, animated: true)
- } else if item.title == "Notification Message(s)".localized() || item.title == "Notification Message(s) Group".localized() {
- let controller = NotificationSound()
- if item.title != "Notification Message(s)".localized() {
- controller.isPersonal = false
- }
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- self.present(navigationController, animated: true)
- } else if item.title == "Backup & Restore".localized() {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "backupRestore") as! BackupRestoreView
- navigationController?.show(controller, sender: nil)
- } else if item.title == "Set Internal Account".localized() {
- let controller = SetInternalCSAccount()
- navigationController?.show(controller, sender: nil)
- } else if item.title == "Set CS Account".localized() {
- let controller = SetInternalCSAccount()
- controller.isSetCS = true
- navigationController?.show(controller, sender: nil)
- }
- }
-
- private func actionLogin(for type: String, title: String) -> UIAlertAction? {
- return UIAlertAction(title: title, style: .default) { _ in
- self.alert = UIAlertController(title:"Access Admin Features".localized(), message: nil, preferredStyle: .alert)
- if type == "internal" {
- self.alert = UIAlertController(title: "Access Internal Features".localized(), message: nil, preferredStyle: .alert)
- }
- self.textFields.removeAll()
- self.alert?.addTextField{ (texfield) in
- texfield.placeholder = "Password".localized()
- texfield.isSecureTextEntry = true
- texfield.addPadding(.right(40))
- texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
-
- let buttonHideUnhide = UIButton()
- buttonHideUnhide.tag = 0
- texfield.addSubview(buttonHideUnhide)
- buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
- buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
- buttonHideUnhide.tintColor = .black
- buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
- }
- let submitAction = UIAlertAction(title: "Sign-In".localized(), style: .default, handler: { (action) -> Void in
- let textField = self.alert?.textFields![0]
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- Nexilis.showLoader()
- if type == "admin" {
- self.signInAdmin(password: textField!.text!, completion: { result in
- if result {
- DispatchQueue.main.async {
- Nexilis.hideLoader {
- self.makeMenu()
- self.tableView.reloadData()
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- Nexilis.hideLoader {}
- }
- }
- })
- } else {
- self.signInInternal(password: textField!.text!, completion: { result in
- if result {
- DispatchQueue.main.async {
- Nexilis.hideLoader {
- self.makeMenu()
- self.tableView.reloadData()
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- Nexilis.hideLoader {}
- }
- }
- })
- }
- })
- submitAction.isEnabled = false
- self.alert?.addAction(submitAction)
- self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
-
- self.present(self.alert!, animated: true, completion: nil)
- }
- }
-
- private func actionChangePassword(for type: String, title: String) -> UIAlertAction? {
- return UIAlertAction(title: title, style: .default) { _ in
- self.alert = UIAlertController(title: "Change Admin Password".localized(), message: nil, preferredStyle: .alert)
- if type == "internal" {
- self.alert = UIAlertController(title: "Change Internal Password".localized(), message: nil, preferredStyle: .alert)
- }
- self.textFields.removeAll()
- self.alert?.addTextField{ (texfield) in
- texfield.placeholder = "Old Password"
- texfield.isSecureTextEntry = true
- texfield.addPadding(.right(40))
- texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
- self.textFields.append(texfield)
-
- let buttonHideUnhide = UIButton()
- buttonHideUnhide.tag = 0
- texfield.addSubview(buttonHideUnhide)
- buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
- buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
- buttonHideUnhide.tintColor = .black
- buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
- }
- self.alert?.addTextField{ (texfield) in
- texfield.placeholder = "New Password"
- texfield.isSecureTextEntry = true
- texfield.addPadding(.right(40))
- texfield.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
- self.textFields.append(texfield)
-
- let buttonHideUnhide = UIButton()
- buttonHideUnhide.tag = 1
- texfield.addSubview(buttonHideUnhide)
- buttonHideUnhide.anchor(top: texfield.topAnchor, right: texfield.rightAnchor, paddingTop: -7, width: 30, height: 30)
- buttonHideUnhide.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
- buttonHideUnhide.tintColor = .black
- buttonHideUnhide.addTarget(self, action: #selector(self.showPassword), for: .touchUpInside)
- }
- let submitAction = UIAlertAction(title: "Change Password".localized(), style: .default, handler: { (action) -> Void in
- let textFieldOld = self.alert?.textFields![0]
- let textFieldNew = self.alert?.textFields![1]
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- return
- }
- if type == "admin" {
- self.changePasswordAdmin(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
- if result {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- })
- } else {
- self.changePasswordInternal(oldPassword: textFieldOld!.text!, newPassword: textFieldNew!.text!, completion: { result in
- if result {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- })
- }
- })
- submitAction.isEnabled = false
- self.alert?.addAction(submitAction)
- self.alert?.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
-
- self.present(self.alert!, animated: true, completion: nil)
- }
- }
-
- @objc func showPassword(_ sender:UIButton) {
- if alert!.textFields![sender.tag].isSecureTextEntry {
- alert!.textFields![sender.tag].isSecureTextEntry = false
- let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
- buttonImage.setImage(UIImage(systemName: "eye.fill"), for: .normal)
- } else {
- alert!.textFields![sender.tag].isSecureTextEntry = true
- let buttonImage = alert!.textFields![sender.tag].subviews[0] as! UIButton
- buttonImage.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
- }
- }
-
- @objc func alertTextFieldDidChange(_ sender: UITextField) {
- if(!textFields.isEmpty){
- //print("text count 0: \(textFields[0].text!.count)")
- //print("text count 1: \(textFields[1].text!.count)")
- alert?.actions[0].isEnabled = textFields[0].text!.count > 0 && textFields[1].text!.count > 0
- }
- else {
- alert?.actions[0].isEnabled = sender.text!.count > 0
- }
- }
-
- private func signInAdmin(password: String, completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- let p_password = password
- let md5Hex = p_password
- var result: Bool = false
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiAdmin(p_name: idMe!, p_password: md5Hex)) {
- if response.isOk() {
- result = true
- }
- DispatchQueue.main.async {
- if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- completion(result)
- }
- }
-
- private func signInInternal(password: String, completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- let p_password = password
- let md5Hex = p_password
- var result: Bool = false
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignInApiInternal(p_name: idMe!, p_password: md5Hex)) {
- if response.isOk() {
- result = true
- }
- DispatchQueue.main.async {
- if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- completion(result)
- }
- }
-
- private func changePasswordAdmin(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- let p_password = oldPassword
- let n_password = newPassword
- let md5Hex = p_password
- let md5HexNew = n_password
- var result: Bool = false
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordAdmin(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
- if response.isOk() {
- result = true
- }
- DispatchQueue.main.async {
- if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- completion(result)
- }
- }
-
- private func changePasswordInternal(oldPassword: String, newPassword: String, completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
- let p_password = oldPassword
- let n_password = newPassword
- let md5Hex = p_password
- let md5HexNew = n_password
- var result: Bool = false
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangePasswordInternal(p_f_pin: idMe!, pwd_en: md5HexNew, pwd_old: md5Hex)) {
- if response.isOk() {
- result = true
- }
- DispatchQueue.main.async {
- if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "20" {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- } else {
- DispatchQueue.main.async {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- 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)
- banner.show()
- }
- }
- completion(result)
- }
- }
- }
- // MARK: - Item
- struct Item: Hashable {
-
- static func == (lhs: Item, rhs: Item) -> Bool {
- return lhs.title == rhs.title
- }
-
- var icon: UIImage?
- var title = ""
-
- static var sections: [String] {
- return ["Personal", "Call", "Version"]
- }
-
- static var menus: [String: [Item]] = [:]
-
- static func menuFor(section: Int) -> [Item] {
- let sec = sections[section]
- if let arr = menus[sec] {
- return arr
- }
- return []
- }
-
- }
- extension FourthTabViewController: UIPickerViewDelegate, UIPickerViewDataSource {
- public func numberOfComponents(in pickerView: UIPickerView) -> Int {
- return 1
- }
-
- public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
- return language.count
- }
-
- public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
- return 60
- }
-
- public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
- let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 10, height: 30))
- label.text = (language[row]).keys.first
- label.sizeToFit()
- return label
- }
- }
|