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.

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