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.

697 lines
27 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
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
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // HomeViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 21/09/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import Crashlytics
  10. import Localize_Swift
  11. class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
  12. enum Sections: Int {
  13. case balance = 0
  14. case collection
  15. }
  16. struct Constants {
  17. static let verificationNoticeHeight: CGFloat = 100
  18. }
  19. struct StringConstants {
  20. let homeText = "home_text".localized()
  21. let registerProcessText = "complete_your_registration_text".localized()
  22. let registrationApprovalText = "verification_in_aproval_process_text".localized()
  23. let pennyTestPrimaryBankText = "complete_penny_test".localized()
  24. let verifyTitleText = "kyc_fill_text".localized()
  25. let continueRegistrationTitleText = "penny_test_pending_text".localized()
  26. let verificationInProcessTitleText = "kyc_verify_pending_text".localized()
  27. let soonToUseGmeServicesTitle = "verification_in_aproval_process_text".localized()
  28. }
  29. // MARK: IBOutlets
  30. @IBOutlet weak var tableView: UITableView!
  31. @IBOutlet weak var verificationNoticeHeightConstraint: NSLayoutConstraint!
  32. @IBOutlet var verificationNoticeView: UIView!
  33. @IBOutlet weak var verificationCloseButton: UIButton!
  34. @IBOutlet weak var verificationText: UILabel!
  35. @IBOutlet var tapGuesture: UITapGestureRecognizer!
  36. @IBOutlet weak var verificationTitleLabel: UILabel!
  37. @IBOutlet weak var verificationHeaderLeftImageview: UIImageView!
  38. @IBOutlet weak var verificationHeaderRightButton: UIButton!
  39. @IBOutlet weak var seperatorView: UIView!
  40. // title labels
  41. @IBOutlet weak var thankyouTitleLabel: UILabel!
  42. // MARK: Properties
  43. var refreshControl: UIRefreshControl?
  44. var presenter: HomeModuleInterface?
  45. var user: User? {
  46. didSet {
  47. // update
  48. self.save(user: user)
  49. self.showUnverifiedNotice()
  50. self.tableView.reloadData()
  51. updateBalance()
  52. self.update()
  53. }
  54. }
  55. var sections: [Sections] = [.balance, .collection]
  56. var menuHeight: CGFloat? {
  57. didSet {
  58. self.tableView.reloadData()
  59. }
  60. }
  61. // MARK: VC's Life cycle
  62. override func viewDidLoad() {
  63. super.viewDidLoad()
  64. // test()
  65. setupNavigationNotifications()
  66. self.setup()
  67. }
  68. func test() {
  69. let web = WkWebViewController()
  70. web.url = "http://gmeuat.gmeremit.com:5013/kftcCallback?code=b894944b-c500-4627-9cf9-9fc5fd3f2822&scope=login+inquiry+transfer&client_info=f6Qv6Xd44Q5hmkcYLNVH8w%3D%3D"
  71. // web.url = "http://gmeuat.gmeremit.com:5013/test.html"
  72. // self.present(web, animated: true, completion: nil)
  73. self.navigationController?.pushViewController(web, animated: true)
  74. }
  75. override func viewWillAppear(_ animated: Bool) {
  76. super.viewWillAppear(animated)
  77. configureViews()
  78. self.setActionBarIcons(showNotificationParameter: false) // set true if there is unread
  79. self.tableView.reloadData()
  80. self.setupTabItem()
  81. NotificationCenter.default.addObserver(self, selector: #selector(setupTabItem), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
  82. }
  83. override func viewWillDisappear(_ animated: Bool) {
  84. super.viewWillDisappear(animated)
  85. self.navigationItem.title = ""
  86. }
  87. // MARK: IBActions
  88. @IBAction func closeVerificationNotice(_ sender: UIButton) {
  89. return
  90. if #available(iOS 10.0, *) {
  91. let animator = UIViewPropertyAnimator(duration: 0.4, curve: .easeOut )
  92. animator.addAnimations {
  93. self.verificationNoticeView.alpha = 0
  94. }
  95. animator.addAnimations({
  96. self.verificationNoticeHeightConstraint.constant = 0
  97. self.view.layoutIfNeeded()
  98. }, delayFactor: 0.5)
  99. animator.startAnimation()
  100. }
  101. }
  102. // MARK: Other Functions
  103. private func setup() {
  104. // all setup should be done here
  105. setupDelegates()
  106. setupNotifications()
  107. configureLanguage()
  108. self.addRefreshControlTableView()
  109. self.presenter?.refreshData()
  110. NotificationCenter.default.addObserver(self, selector: #selector(self.showPennyTestFirstTime), name: NSNotification.Name.init("showPennyTestFirstTime"), object: nil)
  111. }
  112. @objc private func configureLanguage() {
  113. // self.barButtonItem.title = StringConstants().homeText
  114. }
  115. @objc private func showPennyTestFirstTime() {
  116. presenter?.showPennyTest()
  117. }
  118. private func update() {
  119. let platform = self.user?.platforms ?? []
  120. guard let ios = platform.filter({
  121. $0.os ?? "" == "IOS"
  122. }).first else {return}
  123. let critical = ios.critical ?? "N"
  124. UserDefaults.standard.set(critical, forKey: AppConstants.criticalUpdate)
  125. let version = Utility.getAppVersion() ?? ""
  126. let val = version.components(separatedBy: ".")
  127. let latestVersion = ios.version ?? "0"
  128. let latestVal = latestVersion.components(separatedBy: ".").last ?? "0"
  129. if val.count == 3 {
  130. if let build = val.last {
  131. if (Int(latestVal) ?? 0) > (Int(build) ?? 0) {
  132. self.presenter?.showAppUpdate()
  133. }
  134. }
  135. }
  136. }
  137. private func updateBalance() {
  138. let balance = user?.availableBalance ?? ""
  139. UserDefaults.standard.set(balance, forKey: UserKeys.availableBalance)
  140. let userInfo = [SideMenuNavigationNotifications.availableBalance : balance]
  141. NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo)
  142. self.tableView.reloadData()
  143. }
  144. private func setupNavigationNotifications() {
  145. NotificationCenter.default.addObserver(self, selector: #selector(self.showAutoDebit), name: self.getKftcAccountListNotificationName(), object: nil)
  146. NotificationCenter.default.addObserver(self, selector: #selector(self.showWithdraw), name: self.getWithdrawNotificationName(), object: nil)
  147. NotificationCenter.default.addObserver(self, selector: #selector(self.showSideMenuAboutGme), name: self.getAboutMeNotificationName(), object: nil)
  148. NotificationCenter.default.addObserver(self, selector: #selector(self.showSideMenuSupport), name: self.getSupportNotificationName(), object: nil)
  149. NotificationCenter.default.addObserver(self, selector: #selector(self.showSideMenuSetting), name: self.getSettingNotificationName(), object: nil)
  150. }
  151. private func getAboutMeNotificationName() -> Notification.Name {
  152. return Notification.Name.init(SideMenuNavigationNotifications.aboutGme)
  153. }
  154. private func getSupportNotificationName() -> Notification.Name {
  155. return Notification.Name.init(SideMenuNavigationNotifications.support)
  156. }
  157. private func getSettingNotificationName() -> Notification.Name {
  158. return Notification.Name.init(SideMenuNavigationNotifications.setting)
  159. }
  160. @objc private func showSideMenuAboutGme() {
  161. let vc = UIStoryboard.init(name: "_Home", bundle: nil).instantiateViewController(withIdentifier: "AboutGMEViewController") as! AboutGMEViewController
  162. self.navigationController?.pushViewController(vc, animated: true)
  163. }
  164. @objc private func showSideMenuSetting() {
  165. let vc = UIStoryboard.init(name: "Setting", bundle: nil).instantiateViewController(withIdentifier: "SettingViewController") as! SettingViewController
  166. self.navigationController?.pushViewController(vc, animated: true)
  167. }
  168. @objc private func showSideMenuSupport() {
  169. let vc = UIStoryboard.init(name: "_Home", bundle: nil).instantiateViewController(withIdentifier: "SupportViewController") as! SupportViewController
  170. self.navigationController?.pushViewController(vc, animated: true)
  171. }
  172. @objc private func showAutoDebit() {
  173. let wireframe = AutoDebitWireframe()
  174. if let navigation = self.navigationController {
  175. wireframe.pushMainView(in: navigation)
  176. }
  177. }
  178. @objc private func showWithdraw() {
  179. let vc = UIStoryboard.init(name: "autoRefund", bundle: nil).instantiateViewController(withIdentifier: "AutoRefundsViewController") as! AutoRefundsViewController
  180. self.navigationController?.pushViewController(vc, animated: true)
  181. }
  182. private func setupDelegates() {
  183. tableView.delegate = self
  184. tableView.dataSource = self
  185. self.tapGuesture.delegate = self
  186. }
  187. private func addRefreshControlTableView() {
  188. let colorOption = [NSAttributedStringKey.foregroundColor : AppConstants.themWhiteColor];
  189. let title = NSAttributedString(string: "pull to refresh", attributes: colorOption)
  190. let refreshControl = UIRefreshControl()
  191. refreshControl.attributedTitle = title
  192. refreshControl.backgroundColor = AppConstants.themeBlueColor
  193. refreshControl.tintColor = AppConstants.themWhiteColor
  194. refreshControl.addTarget(self, action: #selector(self.refresh), for: .valueChanged)
  195. self.refreshControl = refreshControl
  196. if #available(iOS 10.0, *) {
  197. tableView.refreshControl = self.refreshControl
  198. } else {
  199. if let control = self.refreshControl {
  200. tableView.addSubview(control)
  201. }
  202. }
  203. }
  204. @objc private func refresh() {
  205. presenter?.refreshData()
  206. }
  207. @objc func showNotification(){
  208. performSegue(withIdentifier: "notification", sender: nil)
  209. }
  210. @objc func showSupport() {
  211. let alert = UIAlertController(title:nil, message:"help_you_text".localized(), preferredStyle: .actionSheet)
  212. // alert.view.subviews.last?.subviews.last?.backgroundColor = UIColor.darkGray
  213. let liveChat = UIAlertAction(title: "Live Chat", style: .default) {
  214. UIAlertAction in
  215. }
  216. let contactNumber = UIAlertAction(title: "1588 6864", style: .default) {
  217. UIAlertAction in
  218. self.startCall(contactNumber: "1588 6864")
  219. }
  220. let supportEmail = UIAlertAction(title: "support@gmeremit.com", style: .default) {
  221. UIAlertAction in
  222. let storyboard = UIStoryboard.init(name: "MessageCompose", bundle: Bundle.main)
  223. if let messageViewController = storyboard.instantiateViewController(withIdentifier: "message") as? MessageComposeViewController {
  224. self.navigationController!.pushViewController(messageViewController, animated: true)
  225. }
  226. }
  227. liveChat.setValue(UIImage(named:"ic_live_chat")?.withRenderingMode(.alwaysOriginal),forKey:"image")
  228. contactNumber.setValue(UIImage(named:"ic_call")?.withRenderingMode(.alwaysOriginal),forKey:"image")
  229. supportEmail.setValue(UIImage(named:"ic_email")?.withRenderingMode(.alwaysOriginal),forKey:"image")
  230. // TODO: have to enable when zendesk is provided
  231. // alert.addAction(liveChat)
  232. alert.addAction(contactNumber)
  233. // alert.addAction(supportEmail)
  234. alert.view.tintColor = UIColor.darkGray
  235. // alert.view.subviews.last?.subviews.last?.layer.cornerRadius = 10
  236. alert.addAction(UIAlertAction(title: "cancel_text".localized(), style: UIAlertActionStyle.cancel, handler: nil))
  237. present(alert, animated: true, completion: nil)
  238. }
  239. func startCall(contactNumber: String){
  240. if let url = URL(string: "tel://\(contactNumber.removeWhitespacesInBetween())"), UIApplication.shared.canOpenURL(url) {
  241. if #available(iOS 10, *) {
  242. UIApplication.shared.open(url)
  243. } else {
  244. UIApplication.shared.openURL(url)
  245. }
  246. }
  247. }
  248. private func setupNotifications() {
  249. let center = NotificationCenter.default
  250. center.addObserver(self, selector: #selector(self.showSendMoney), name: self.getSendMoneyNotificationName(), object: nil)
  251. center.addObserver(self, selector: #selector(self.showMobileRecharge), name: self.getMobileRechargeNotificationName(), object: nil)
  252. center.addObserver(self, selector: #selector(self.showTodaysRate), name: self.getTodaysRateNotificationName(), object: nil)
  253. center.addObserver(self, selector: #selector(self.showTrackYourTransfer), name: self.getTrackYourTransferNotificationName(), object: nil)
  254. center.addObserver(self, selector: #selector(self.showTransactionStatement), name: self.getTransactionStatementNotificationName(), object: nil)
  255. center.addObserver(self, selector: #selector(self.showWalletToWallet), name: self.getWalletToWalletNotificationName(), object: nil)
  256. center.addObserver(self, selector: #selector(self.setupHeight(sender:)), name: self.getCollectionHeightNotificationName(), object: nil)
  257. center.addObserver(self, selector: #selector(self.showUnVerifiedMessage), name: self.getMainControllerNotificationName(), object: nil)
  258. }
  259. func setActionBarIcons(showNotificationParameter: Bool){
  260. let supportImage = UIImage(named: "ic_support")?.withRenderingMode(.alwaysOriginal)
  261. let supportButton = UIBarButtonItem(image:supportImage, style: .plain, target: self, action: #selector(showSupport))
  262. let notificationImage: UIImage!
  263. if showNotificationParameter {
  264. notificationImage = UIImage(named: "ic_notificationDot")?.withRenderingMode(.alwaysOriginal)
  265. } else {
  266. notificationImage = UIImage(named: "ic_notification")?.withRenderingMode(.alwaysOriginal)
  267. }
  268. let notificationButton = UIBarButtonItem(image: notificationImage, style: .plain, target: self, action: #selector(showNotification))
  269. // self.navigationItem.rightBarButtonItems=[notificationButton,supportButton]
  270. self.navigationItem.rightBarButtonItems = [supportButton]
  271. }
  272. private func showUnverifiedNotice() {
  273. setVerificationText()
  274. if shouldShowUnverifiedNotice() {
  275. UIView.animate(withDuration: 0.33) {
  276. self.verificationNoticeHeightConstraint.constant = Constants.verificationNoticeHeight
  277. self.verificationNoticeView.alpha = 1
  278. self.view.layoutIfNeeded()
  279. }
  280. }else {
  281. self.verificationNoticeHeightConstraint.constant = 0
  282. self.verificationNoticeView.alpha = 0
  283. self.view.layoutIfNeeded()
  284. }
  285. }
  286. private func setVerificationText() {
  287. // && Utility.didPennyTestNotInitiated()
  288. if didNotSubmitKycAndNotVerified() {
  289. verificationTitleLabel.text = StringConstants().verifyTitleText
  290. self.verificationText.text = StringConstants().registerProcessText
  291. self.verificationHeaderLeftImageview.image = UIImage.init(named: "ic_home_verified")
  292. let image = UIImage.init(named: "ic_home_payoutLocation")
  293. self.verificationHeaderRightButton.setImage(image, for: UIControlState.normal)
  294. }else if didSubmitKycAndNotVerified() && shouldShowPennyTestError() {
  295. verificationTitleLabel.text = StringConstants().continueRegistrationTitleText
  296. self.verificationText.text = StringConstants().pennyTestPrimaryBankText
  297. self.verificationHeaderLeftImageview.image = #imageLiteral(resourceName: "shield.png")
  298. self.verificationNoticeHeightConstraint.constant = Constants.verificationNoticeHeight
  299. self.verificationNoticeView.alpha = 1
  300. self.verificationHeaderRightButton.isHidden = true
  301. }
  302. else if didSubmitKycAndNotVerified() {
  303. verificationTitleLabel.text = StringConstants().verificationInProcessTitleText
  304. self.verificationText.text = StringConstants().soonToUseGmeServicesTitle
  305. self.verificationHeaderLeftImageview.image = #imageLiteral(resourceName: "ic_home_verified")
  306. self.verificationHeaderRightButton.setImage(#imageLiteral(resourceName: "ic_home_payoutLocation"), for: UIControlState.normal)
  307. }
  308. if didSubmitKycAndVerified() && !Utility.pennyTestVerified() {
  309. verificationTitleLabel.text = StringConstants().continueRegistrationTitleText
  310. self.verificationText.text = StringConstants().pennyTestPrimaryBankText
  311. self.verificationHeaderLeftImageview.image = #imageLiteral(resourceName: "shield.png")
  312. self.verificationNoticeHeightConstraint.constant = Constants.verificationNoticeHeight
  313. self.verificationNoticeView.alpha = 1
  314. self.verificationHeaderRightButton.isHidden = true
  315. }
  316. if didSubmitKycAndVerified() && Utility.pennyTestVerified() {
  317. self.verificationNoticeHeightConstraint.constant = 0
  318. self.verificationNoticeView.alpha = 0
  319. }
  320. }
  321. private func didSubmitKycAndNotVerified() -> Bool {
  322. return Utility.didSubmitKyc() && !Utility.isVerifiedUser()
  323. }
  324. private func didSubmitKycAndVerified() -> Bool {
  325. return Utility.didSubmitKyc() && Utility.isVerifiedUser()
  326. }
  327. private func didNotSubmitKycAndNotVerified() -> Bool {
  328. return !Utility.didSubmitKyc() && !Utility.isVerifiedUser()
  329. }
  330. private func shouldShowPennyTestError() -> Bool {
  331. return Utility.shouldShowPennyTestError()
  332. }
  333. @IBAction func showKyc(_ sender: UITapGestureRecognizer) {
  334. if self.didNotSubmitKycAndNotVerified() {
  335. self.presenter?.showKyc()
  336. }else if shouldShowPennyTestError() {
  337. if Utility.didPennyTestRequested() {
  338. presenter?.showPennyTestSubmit()
  339. }else {
  340. presenter?.showPennyTest()
  341. }
  342. }
  343. }
  344. private func shouldShowUnverifiedNotice() -> Bool {
  345. return !self.isUserVerified() || Utility.shouldShowPennyTestError()
  346. }
  347. private func configureViews() {
  348. self.verificationNoticeHeightConstraint.constant = 0
  349. showUnverifiedNotice()
  350. setNavBar()
  351. }
  352. func setNavBar() {
  353. let selector = #selector(self.showSideMenu)
  354. self.setupPicturedNavBar(sideMenuAction: selector)
  355. }
  356. @objc func showSideMenu() {
  357. sideMenuController?.showLeftViewAnimated()
  358. }
  359. private func isUserVerified() -> Bool {
  360. return Utility.isVerifiedUser()
  361. }
  362. @objc private func showSendMoney() {
  363. let kycSubmited = user?.kyc ?? false
  364. let pennyTestComplete = Utility.pennyTestVerified()
  365. if kycSubmited == true && pennyTestComplete == false {
  366. self.show(error: StringConstants().pennyTestPrimaryBankText)
  367. return
  368. }
  369. if isUserVerified() {
  370. // remaining of previous developer. I dont have much time. Later. TODO: refracor
  371. let viewcontroller = UIStoryboard.init(name:
  372. "RecipientListViewController", bundle: nil).instantiateViewController(withIdentifier: "RecipientListViewController") as! RecipientListViewController
  373. self.navigationController?.pushViewController(viewcontroller, animated: true)
  374. } else {
  375. self.showUnVerifiedMessage()
  376. }
  377. }
  378. @objc private func showMobileRecharge() {
  379. let kycSubmited = user?.kyc ?? false
  380. let pennyTestComplete = Utility.pennyTestVerified()
  381. if kycSubmited == true && pennyTestComplete == false {
  382. self.show(error: StringConstants().pennyTestPrimaryBankText)
  383. return
  384. }
  385. self.alert(message: "This feature is coming soon")
  386. return
  387. if isUserVerified() {
  388. return
  389. self.performSegue(withIdentifier: "mobileRecharge", sender: nil)
  390. }else {
  391. self.showUnVerifiedMessage()
  392. }
  393. }
  394. @objc private func showTodaysRate() {
  395. presenter?.openTodaysRate()
  396. }
  397. // Transaction Report
  398. @objc private func showTrackYourTransfer() {
  399. let kycSubmited = user?.kyc ?? false
  400. let pennyTestComplete = Utility.pennyTestVerified()
  401. if kycSubmited == true && pennyTestComplete == false {
  402. self.show(error: StringConstants().pennyTestPrimaryBankText)
  403. return
  404. }
  405. isUserVerified() ? (presenter?.openTrackYourTransfer()) : (self.showUnVerifiedMessage())
  406. }
  407. @objc private func showTransactionStatement() {
  408. let kycSubmited = user?.kyc ?? false
  409. let pennyTestComplete = Utility.pennyTestVerified()
  410. if kycSubmited == true && pennyTestComplete == false {
  411. self.show(error: StringConstants().pennyTestPrimaryBankText)
  412. return
  413. }
  414. isUserVerified() ? (presenter?.openTransactionHistory()) : (self.showUnVerifiedMessage())
  415. }
  416. @objc private func showUnVerifiedMessage() {
  417. if didNotSubmitKycAndNotVerified() {
  418. self.alert(message: StringConstants().registerProcessText)
  419. } else if Utility.didSubmitKyc() && !Utility.pennyTestVerified() {
  420. self.alert(message: StringConstants().pennyTestPrimaryBankText)
  421. }
  422. else
  423. if didSubmitKycAndNotVerified() {
  424. // verification_in_aproval_process_text
  425. // Your registration request is in approval process. You will soon be able to use GME services.
  426. self.alert(message: "verification_in_aproval_process_text".localized())
  427. }
  428. }
  429. // TODO:-
  430. @objc private func showUnVerifiedPennyTestMessage() {
  431. // complete_penny_test
  432. self.alert(message: "complete_penny_test".localized())
  433. }
  434. @objc private func showWalletToWallet() {
  435. self.alert(message: "This feature is coming soon")
  436. }
  437. @objc private func setupHeight(sender: Notification) {
  438. if let height = sender.userInfo?[MenuNotificationName.collectionHeight] as? CGFloat {
  439. self.menuHeight = height
  440. }
  441. }
  442. }
  443. // MARK: HomeViewInterface
  444. extension HomeViewController: HomeViewInterface {
  445. func show(model: User) {
  446. self.user = model
  447. }
  448. func show(error: String) {
  449. self.alert(message: error)
  450. }
  451. func show(panicError: String) {
  452. self.alert(message: panicError, title: "Warning") {
  453. self.presenter?.logout()
  454. }
  455. }
  456. func showLoading() {
  457. self.showProgressHud()
  458. }
  459. func hideLoading() {
  460. self.hideProgressHud()
  461. }
  462. func endRefreshing() {
  463. guard let control = self.tableView.refreshControl else {return}
  464. if control.isRefreshing == true {
  465. DispatchQueue.main.async {
  466. control.perform(#selector(control.endRefreshing), with: nil, afterDelay: 0.5)
  467. }
  468. }
  469. }
  470. }
  471. extension HomeViewController: UITableViewDelegate {
  472. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  473. guard let _section = Sections.init(rawValue: indexPath.section) else {return 0}
  474. switch _section {
  475. case .balance:
  476. return UITableViewAutomaticDimension
  477. case .collection:
  478. let totalHeight = view.frame.height
  479. let ramainingBalanceCellHeight: CGFloat = 100
  480. let finalHeight = totalHeight - ramainingBalanceCellHeight
  481. return finalHeight
  482. }
  483. }
  484. }
  485. extension HomeViewController: UITableViewDataSource {
  486. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  487. return 1
  488. }
  489. func numberOfSections(in tableView: UITableView) -> Int {
  490. return self.sections.count
  491. }
  492. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  493. guard let _section = Sections.init(rawValue: indexPath.section) else {return UITableViewCell()}
  494. switch _section {
  495. case .balance:
  496. return configureRemainingLimitCell(tableView: tableView, indexPath: indexPath)
  497. case .collection:
  498. return configureCollectionCell(tableView: tableView, indexPath: indexPath)
  499. }
  500. }
  501. func configureRemainingLimitCell(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
  502. let cell = tableView.dequeueReusableCell(withIdentifier: "HomeRemainingLimitTableViewCell") as! HomeRemainingLimitTableViewCell
  503. cell.user = self.user
  504. cell.setup()
  505. return cell
  506. }
  507. func configureCollectionCell(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
  508. let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCollectionTableViewCell") as! HomeCollectionTableViewCell
  509. cell.setup()
  510. return cell
  511. }
  512. override func setupTabItem() {
  513. let image = UIImage.init(named: "ic-home")
  514. self.tabBarItem = UITabBarItem(title: "home_text".localized(), image: image, selectedImage: nil)
  515. self.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: UI_USER_INTERFACE_IDIOM() == .pad ? 2 : -6)
  516. }
  517. }
  518. // notification Name
  519. extension HomeViewController {
  520. func getSendMoneyNotificationName() -> Notification.Name {
  521. return Notification.Name.init(rawValue: MenuNotificationName.sendMoney)
  522. }
  523. func getMobileRechargeNotificationName() -> Notification.Name {
  524. return Notification.Name.init(rawValue: MenuNotificationName.mobileRecharge)
  525. }
  526. func getTodaysRateNotificationName() -> Notification.Name {
  527. return Notification.Name.init(rawValue: MenuNotificationName.todaysRate)
  528. }
  529. func getTrackYourTransferNotificationName() -> Notification.Name {
  530. return Notification.Name.init(rawValue: MenuNotificationName.trackYourTransfer)
  531. }
  532. func getTransactionStatementNotificationName() -> Notification.Name {
  533. return Notification.Name.init(rawValue: MenuNotificationName.transactionStatement)
  534. }
  535. func getWalletToWalletNotificationName() -> Notification.Name {
  536. return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet)
  537. }
  538. func getCollectionHeightNotificationName() -> Notification.Name {
  539. return Notification.Name.init(rawValue: MenuNotificationName.collectionHeight)
  540. }
  541. func getAvailableBalanceNotificationName() -> Notification.Name {
  542. return Notification.Name.init(rawValue: SideMenuNavigationNotifications.availableBalance)
  543. }
  544. func getMainControllerNotificationName() -> Notification.Name {
  545. return Notification.Name.init(rawValue: AppConstants.MainWireFrameNotificationName)
  546. }
  547. func getWithdrawNotificationName() -> Notification.Name {
  548. return Notification.Name.init(SideMenuNavigationNotifications.withdraw)
  549. }
  550. func getKftcAccountListNotificationName() -> Notification.Name {
  551. return Notification.Name.init(SideMenuNavigationNotifications.KftcAccountList)
  552. }
  553. }
  554. extension HomeViewController: UIGestureRecognizerDelegate {
  555. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  556. return !Utility.didSubmitKyc() || Utility.shouldShowPennyTestError() || Utility.didPennyTestCancelled() || Utility.didPennyTestRequested() || Utility.didPennyTestNotInitiated()
  557. }
  558. }
  559. extension HomeViewController {
  560. private func save(value: Any?, forKey: String) {
  561. let defaults = UserDefaults.standard
  562. defaults.set(value, forKey: forKey)
  563. }
  564. func save(user: User?) {
  565. Utility.save(user: user)
  566. }
  567. }