You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
34 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // UIExtension.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/11/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. import MBProgressHUD
  11. // ccr
  12. // MARK: Alerts
  13. extension UIViewController {
  14. func setupPicturedNavBar(sideMenuAction: Selector? = nil) {
  15. self.navigationController?.isNavigationBarHidden = false
  16. self.navigationController?.navigationBar.isTranslucent = false
  17. if let selector = sideMenuAction {
  18. let leftButton = UIBarButtonItem(image: UIImage(named: "ic_hamburger"), style: .plain, target: self, action: selector)
  19. self.navigationController?.navigationBar.tintColor = AppConstants.themeRedColor
  20. self.navigationItem.leftBarButtonItem = leftButton
  21. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  22. }
  23. self.navigationController?.navigationBar.tintColor = .white
  24. // self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24)
  25. self.navigationController?.navigationBar.barTintColor = AppConstants.themeRedColor
  26. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 125, height: 30))
  27. imageView.contentMode = .scaleAspectFit
  28. let image = UIImage(named: "ic_gme_new")
  29. imageView.image = image
  30. self.navigationItem.titleView = imageView
  31. }
  32. func setupNormalNavigation() {
  33. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  34. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  35. self.navigationController?.navigationBar.tintColor = .black
  36. self.navigationController?.navigationBar.barTintColor = .white
  37. }
  38. }
  39. extension UIViewController {
  40. func confirmationAlert(title: String, message: String, confirmTitle: String, style: UIAlertActionStyle = .destructive, confirmAction: @escaping () -> Void) {
  41. let deleteActionSheetController = UIAlertController(title: title, message: message, preferredStyle: .alert)
  42. let deleteAction = UIAlertAction(title: confirmTitle, style: style) {
  43. action -> Void in
  44. confirmAction()
  45. }
  46. let cancelAction = UIAlertAction(title: "cancel_text".localized(), style: .cancel) { action -> Void in
  47. }
  48. deleteActionSheetController.addAction(deleteAction)
  49. deleteActionSheetController.addAction(cancelAction)
  50. self.present(deleteActionSheetController, animated: true, completion: nil)
  51. }
  52. func alert(message: String?, title: String? = "alert_text".localized(), okAction: (()->())? = nil) {
  53. let alertController = getAlert(message: message, title: title)
  54. alertController.addAction(title: "ok_text".localized(), handler: okAction)
  55. self.present(alertController, animated: true, completion: nil)
  56. }
  57. func alertWithOkCancel(message: String?, title: String? = "Error", okTitle: String? = "ok_text".localized(), style: UIAlertControllerStyle? = .alert, cancelTitle: String? = "cancel_text".localized(), OkStyle: UIAlertActionStyle = .default, cancelStyle: UIAlertActionStyle = .default, okAction: (()->())? = nil, cancelAction: (()->())? = nil) {
  58. let alertController = getAlert(message: message, title: title, style: style)
  59. alertController.addAction(title: okTitle,style: OkStyle, handler: okAction)
  60. alertController.addAction(title: cancelTitle, style: cancelStyle, handler: cancelAction)
  61. self.present(alertController, animated: true, completion: nil)
  62. }
  63. func alertWithOk(message: String?, title: String? = "Error", okTitle: String? = "ok_text".localized(), style: UIAlertControllerStyle? = .alert, OkStyle: UIAlertActionStyle = .default, okAction: (()->())? = nil) {
  64. let alertController = getAlert(message: message, title: title, style: style)
  65. alertController.addAction(title: okTitle,style: OkStyle, handler: okAction)
  66. self.present(alertController, animated: true, completion: nil)
  67. }
  68. private func getAlert(message: String?, title: String?, style: UIAlertControllerStyle? = .alert) -> UIAlertController {
  69. return UIAlertController(title: title, message: message, preferredStyle: style ?? .alert)
  70. }
  71. func present(_ alert: UIAlertController, asActionsheetInSourceView sourceView: Any) {
  72. if UI_USER_INTERFACE_IDIOM() == .pad {
  73. alert.modalPresentationStyle = .popover
  74. if let presenter = alert.popoverPresentationController {
  75. if sourceView is UIBarButtonItem {
  76. presenter.barButtonItem = sourceView as? UIBarButtonItem
  77. }else if sourceView is UIView {
  78. let view = sourceView as! UIView
  79. presenter.sourceView = view
  80. presenter.sourceRect = view.bounds
  81. }
  82. }
  83. }
  84. self.present(alert, animated: true, completion: nil)
  85. }
  86. }
  87. extension UIAlertController {
  88. func addAction(title: String?, style: UIAlertActionStyle = .default, handler: (()->())? = nil) {
  89. let action = UIAlertAction(title: title, style: style, handler: {_ in
  90. handler?()
  91. })
  92. self.addAction(action)
  93. }
  94. }
  95. struct Associate {
  96. static var hud: UInt8 = 0
  97. }
  98. // MARK: HUD
  99. extension UIViewController {
  100. private func setProgressHud() -> MBProgressHUD {
  101. let progressHud: MBProgressHUD = MBProgressHUD.showAdded(to: self.view, animated: true)
  102. progressHud.tintColor = UIColor.darkGray
  103. progressHud.removeFromSuperViewOnHide = true
  104. objc_setAssociatedObject(self, &Associate.hud, progressHud, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
  105. return progressHud
  106. }
  107. var progressHud: MBProgressHUD {
  108. if let progressHud = objc_getAssociatedObject(self, &Associate.hud) as? MBProgressHUD {
  109. progressHud.isUserInteractionEnabled = true
  110. return progressHud
  111. }
  112. return setProgressHud()
  113. }
  114. var progressHudIsShowing: Bool {
  115. return self.progressHud.isHidden
  116. }
  117. func showProgressHud() {
  118. self.progressHud.show(animated: false)
  119. }
  120. func hideProgressHud() {
  121. self.progressHud.label.text = ""
  122. self.progressHud.completionBlock = {
  123. objc_setAssociatedObject(self, &Associate.hud, nil, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
  124. }
  125. self.progressHud.hide(animated: false)
  126. }
  127. }
  128. // ccr
  129. extension UIViewController {
  130. func prepareAlert(title: String, message: String) -> UIAlertController {
  131. let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
  132. alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
  133. return alert
  134. }
  135. func showActivityIndicator(activityIndicator: UIActivityIndicatorView) {
  136. activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
  137. activityIndicator.center = view.center
  138. activityIndicator.hidesWhenStopped = true
  139. view.addSubview(activityIndicator)
  140. activityIndicator.startAnimating()
  141. }
  142. func dismissActivityIndicator(activityIndicator: UIActivityIndicatorView) {
  143. activityIndicator.stopAnimating()
  144. }
  145. func hideKeyboardWhenTappedAround() {
  146. let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
  147. tap.cancelsTouchesInView = false
  148. view.addGestureRecognizer(tap)
  149. }
  150. @objc func dismissKeyboard() {
  151. view.endEditing(true)
  152. }
  153. func setUpNavBar(id: Int, title:String) {
  154. switch id {
  155. case 99: //Settings Screen
  156. self.navigationController?.navigationBar.barTintColor = UIColor.white
  157. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  158. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  159. case 201:
  160. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  161. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  162. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  163. self.navigationController?.navigationBar.barTintColor = UIColor.white
  164. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  165. self.navigationItem.title = title
  166. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  167. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  168. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  169. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  170. case 202:
  171. self.navigationItem.hidesBackButton = true
  172. self.navigationController?.navigationBar.barTintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  173. let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
  174. self.navigationController?.navigationBar.titleTextAttributes = textAttributes
  175. self.navigationItem.title = title
  176. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  177. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  178. case 203:
  179. self.navigationItem.hidesBackButton = true
  180. self.navigationController?.navigationBar.barTintColor = UIColor.white
  181. self.navigationItem.title = title
  182. case 300:
  183. // self.navigationItem.hidesBackButton = true
  184. self.navigationController?.navigationBar.barTintColor = UIColor(hex: 0xec1c24)
  185. self.navigationItem.title = title
  186. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  187. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  188. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  189. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  190. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
  191. //TRACK TO SEND MONEY
  192. case 204:
  193. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style:.plain, target:nil, action:nil)
  194. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  195. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  196. self.navigationController?.navigationBar.barTintColor = UIColor.white
  197. self.navigationItem.title = title
  198. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  199. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  200. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  201. case 205:
  202. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  203. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  204. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  205. self.navigationController?.navigationBar.barTintColor = UIColor.white
  206. self.navigationItem.title = title
  207. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  208. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  209. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  210. case 206:
  211. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  212. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  213. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  214. self.navigationController?.navigationBar.barTintColor = UIColor.white
  215. self.navigationItem.title = title
  216. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  217. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  218. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  219. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  220. /// to handle back after redirection from push notification
  221. case 207 :
  222. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  223. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  224. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  225. self.navigationController?.navigationBar.barTintColor = UIColor.white
  226. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  227. self.navigationItem.title = title
  228. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  229. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  230. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  231. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  232. // push notification for no cancel bottom
  233. case 208:
  234. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style:.plain, target:nil, action:nil)
  235. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  236. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  237. self.navigationController?.navigationBar.barTintColor = UIColor.white
  238. self.navigationItem.title = title
  239. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  240. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  241. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  242. case 0:
  243. self.navigationController?.navigationBar.barTintColor = UIColor(hex: 0xec1c24)
  244. self.navigationController?.navigationBar.isTranslucent = false
  245. self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  246. self.navigationController?.navigationBar.shadowImage = UIImage()
  247. //added for autop login cottection
  248. self.navigationItem.hidesBackButton = true
  249. /**
  250. used for recipient form
  251. while clicking cancel button redirect to back view
  252. */
  253. case 1:
  254. self.navigationItem.title = "Send Money"
  255. self.navigationController?.navigationBar.barTintColor = UIColor.white
  256. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  257. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  258. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  259. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  260. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(self.handleBack))
  261. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  262. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  263. /**
  264. used for send Money
  265. while clicking back button redirect to home view during both fron tabbar and menu botton
  266. */
  267. case 2:
  268. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil)
  269. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.goToHomeScreen))
  270. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black
  271. self.navigationController?.navigationBar.barTintColor = UIColor.white
  272. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  273. self.navigationItem.title = title
  274. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  275. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  276. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  277. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
  278. case 3:
  279. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  280. self.navigationItem.title = "Exchange Rate"
  281. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  282. case 4:
  283. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  284. self.navigationItem.title = "Wallet to Wallet Transfer"
  285. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  286. /*
  287. for social page navigation
  288. */
  289. case 5:
  290. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  291. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  292. self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack")
  293. self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack")
  294. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
  295. case 6:
  296. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen))
  297. self.navigationItem.title = "Agent"
  298. self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  299. case 200:
  300. let height: CGFloat = 516 //whatever height you want to add to the existing height
  301. let bounds = self.navigationController!.navigationBar.bounds
  302. self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
  303. //CASE 100 is for before KYC screen where back should not be enabled
  304. case 100:
  305. self.navigationItem.hidesBackButton = true
  306. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 125, height: 30))
  307. imageView.contentMode = .scaleAspectFit
  308. let image = UIImage(named: "ic_gme_new")
  309. imageView.image = image
  310. self.navigationItem.titleView = imageView
  311. case 101:
  312. self.navigationItem.hidesBackButton = true
  313. self.navigationController?.navigationBar.isTranslucent = true
  314. //self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  315. //self.navigationController?.navigationBar.shadowImage = UIImage()
  316. case 102:
  317. self.navigationItem.hidesBackButton = true
  318. self.navigationController?.navigationBar.isTranslucent = true
  319. self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default)
  320. self.navigationController?.navigationBar.shadowImage = UIImage()
  321. self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xed1c24)
  322. self.navigationController?.navigationBar.isTranslucent = false
  323. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30))
  324. imageView.contentMode = .scaleAspectFit
  325. let image = UIImage(named: "ic_gme")
  326. imageView.image = image
  327. navigationItem.titleView = imageView
  328. case 103:
  329. self.navigationItem.hidesBackButton = true
  330. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  331. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  332. self.navigationController?.navigationBar.isTranslucent = true
  333. self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default)
  334. self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24)
  335. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30))
  336. imageView.contentMode = .scaleAspectFit
  337. let image = UIImage(named: "ic_gme")
  338. imageView.image = image
  339. navigationItem.titleView = imageView
  340. case 104:
  341. self.navigationItem.hidesBackButton = true
  342. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack))
  343. self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
  344. self.navigationController?.navigationBar.isTranslucent = true
  345. self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default)
  346. self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24)
  347. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30))
  348. imageView.contentMode = .scaleAspectFit
  349. let image = UIImage(named: "ic_gme")
  350. imageView.image = image
  351. navigationItem.titleView = imageView
  352. case 105:
  353. self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
  354. self.navigationController?.navigationBar.barTintColor = UIColor.white
  355. self.navigationController?.navigationBar.isTranslucent = false
  356. default:
  357. return
  358. }
  359. }
  360. @objc func goToHomeScreen() {
  361. showHomeScreen()
  362. }
  363. func showHomeScreen() {
  364. let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
  365. if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController {
  366. self.navigationController?.pushViewController(tabViewController, animated: false)
  367. }
  368. }
  369. func showHomeScreen2() {
  370. let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
  371. if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController {
  372. let destinationViewController = tabViewController.viewControllers![0] as! _HomeViewController
  373. // destinationViewController.numberCellsInCollectionView = 6
  374. // destinationViewController.showAllCollectionViewCells = true
  375. destinationViewController.hidesBottomBarWhenPushed = false
  376. // self.navigationController!.pushViewController(destinationViewController, animated: false)
  377. self.navigationController?.pushViewController(tabViewController, animated: false)
  378. }
  379. }
  380. func enableUserInteractions() {
  381. self.view.isUserInteractionEnabled = true
  382. self.navigationController?.navigationBar.isUserInteractionEnabled = true
  383. self.navigationController?.view.isUserInteractionEnabled = true
  384. }
  385. func disableUserInteractions() {
  386. self.view.isUserInteractionEnabled = false
  387. self.navigationController?.navigationBar.isUserInteractionEnabled = false
  388. self.navigationController?.view.isUserInteractionEnabled = false
  389. }
  390. func unixTimeStampToDate(unixTimeStamp: String) -> String {
  391. let date = Date(timeIntervalSince1970: TimeInterval(unixTimeStamp)!)
  392. let dateFormatter = DateFormatter()
  393. dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want
  394. dateFormatter.locale = NSLocale.current
  395. dateFormatter.dateFormat = "dd/MM/yyyy" //Specify your format that you want
  396. return dateFormatter.string(from: date)
  397. }
  398. func firstWord(text: String) -> String{
  399. let word = text
  400. var firstWord = ""
  401. if let index = word.range(of: " ")?.lowerBound {
  402. let substring = word[..<index]
  403. firstWord = String(substring)
  404. }
  405. return firstWord
  406. }
  407. /// no internet connection and popup message
  408. func popUpMessage(value: Int){
  409. guard let navController = self.navigationController else { return }
  410. let popUpViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popUpInfo") as! PopUpGeneralInfo
  411. popUpViewController.indexValue = value
  412. navController.addChildViewController(popUpViewController)
  413. popUpViewController.view.frame = navController.view.bounds
  414. navController.view.addSubview(popUpViewController.view)
  415. popUpViewController.didMove(toParentViewController: navController)
  416. }
  417. /// for error and validation error message
  418. func popUpMessageError(value: Int, message: String){
  419. guard let navController = self.navigationController else { return }
  420. let popUpViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popUpInfo") as! PopUpGeneralInfo
  421. popUpViewController.indexValue = value
  422. popUpViewController.message = message
  423. navController.addChildViewController(popUpViewController)
  424. popUpViewController.view.frame = navController.view.bounds
  425. navController.view.addSubview(popUpViewController.view)
  426. popUpViewController.didMove(toParentViewController: navController)
  427. }
  428. func popUpMessageInfo(value: Int, title: String, message: String){
  429. guard let navController = self.navigationController else { return }
  430. let popUpViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popUpInfo") as! PopUpGeneralInfo
  431. popUpViewController.indexValue = value
  432. popUpViewController.message = message
  433. popUpViewController.titleInfo = title
  434. navController.addChildViewController(popUpViewController)
  435. popUpViewController.view.frame = navController.view.bounds
  436. navController.view.addSubview(popUpViewController.view)
  437. popUpViewController.didMove(toParentViewController: navController)
  438. }
  439. func getUserName() -> String {
  440. if let userId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String {
  441. return userId
  442. }
  443. return ""
  444. }
  445. // func getFullName() -> String {
  446. // if let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as? String {
  447. // return fullName
  448. // }
  449. // return ""
  450. // }
  451. // func getNickNameOrFirstName() -> String {
  452. // let nickName = UserDefaults.standard.object(forKey: "com.gmeremit.nickName") as! String
  453. // if nickName != "" {
  454. // return nickName
  455. // }
  456. // let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as! String
  457. // return fullName.components(separatedBy: " ").first!
  458. // }
  459. func getFirstName() -> String {
  460. let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as! String
  461. return fullName.components(separatedBy: " ").first!
  462. }
  463. func getFullName() -> String {
  464. if let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as? String {
  465. return fullName
  466. }
  467. return ""
  468. }
  469. func isVerified() -> Bool {
  470. if let verified = UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as? Bool {
  471. return verified
  472. }
  473. return false
  474. }
  475. func isKYCSubmitted() -> Bool {
  476. if let verified = UserDefaults.standard.object(forKey: "com.gmeremit.isKYCSubmitted") as? Bool {
  477. return verified
  478. }
  479. return false
  480. }
  481. // func setupKeyboardNotification() {
  482. // NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
  483. // NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
  484. // }
  485. //
  486. // @objc func keyboardWillShow(notification: NSNotification) {
  487. // if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
  488. // if self.view.frame.origin.y == 0{
  489. // self.view.frame.origin.y -= keyboardSize.height
  490. // }
  491. // }
  492. // }
  493. // @objc func keyboardWillShow(notification: NSNotification) {
  494. // //self.scrollView.isScrollEnabled = true
  495. // var info = notification.userInfo!
  496. // let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
  497. // let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize!.height, 0.0)
  498. //
  499. // self.scrollView.contentInset = contentInsets
  500. // self.scrollView.scrollIndicatorInsets = contentInsets
  501. //
  502. // var aRect : CGRect = self.view.frame
  503. // aRect.size.height -= keyboardSize!.height
  504. // if let activeField = self.activeField {
  505. // if (!aRect.contains(activeField.frame.origin)){
  506. // self.scrollView.scrollRectToVisible(activeField.frame, animated: true)
  507. // }
  508. // }
  509. // }
  510. //
  511. // @objc func keyboardWillHide(notification: NSNotification) {
  512. // if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
  513. // if self.view.frame.origin.y != 0{
  514. // self.view.frame.origin.y += keyboardSize.height
  515. // }
  516. // }
  517. // }
  518. @objc func handleBack(){
  519. self.navigationController?.popViewController(animated: true)
  520. }
  521. func getCommaAddedAmountString(amountString: String) -> String {
  522. let separatorString = " "
  523. let numberFormatter = NumberFormatter()
  524. numberFormatter.numberStyle = NumberFormatter.Style.decimal
  525. if amountString.contains(separatorString) {
  526. let splittedArray = amountString.split(separator: " ")
  527. let number = Double(splittedArray[0])!
  528. let formattedNumber = numberFormatter.string(from: NSNumber(value:number))
  529. return formattedNumber! + " " + splittedArray[1]
  530. } else {
  531. let formattedNumber = numberFormatter.string(from: NSNumber(value: Double(amountString)!))
  532. return formattedNumber!
  533. }
  534. }
  535. func setUpAnotherLoginListener(genericviewmodel: ModelExtension) {
  536. }
  537. }