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.

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