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.

182 lines
6.0 KiB

6 years ago
  1. //
  2. // PayoutViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Fm-user on 2/7/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class PayoutViewController: UIViewController {
  10. @IBOutlet weak var searchbar: UISearchBar!
  11. private var searchActive : Bool = false
  12. private var agentviewmodel = AgentViewModel()
  13. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  14. private var previousIndex: Int = 0
  15. private var agentNamesArray: [String] = [String] ()
  16. public var fromReward : Int?
  17. public static var payoutConnectionTimeOutCheck = 0
  18. @IBOutlet weak var tableViewAgent: UITableView!
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. setUpNavBar(id: 202, title: "GME Branches")
  22. setUpAnotherLoginListener(genericviewmodel: agentviewmodel)
  23. searchbar.delegate = self
  24. tableViewAgent.tableFooterView = UIView()
  25. hideKeyboardWhenTappedAround()
  26. tableViewAgent.delegate = self
  27. tableViewAgent.dataSource = self
  28. tableViewAgent.estimatedRowHeight = 119
  29. tableViewAgent.rowHeight = UITableViewAutomaticDimension
  30. tableViewAgent.sectionIndexColor = UIColor(hex: 0x4a4a4a)
  31. tableViewAgent.sectionIndexBackgroundColor = UIColor(hex: 0xe7edf2)
  32. showActivityIndicator(activityIndicator: activityIndicator)
  33. disableUserInteractions()
  34. agentviewmodel.agentConnectionTimeOut.value = nil
  35. /**
  36. connection timeout
  37. */
  38. agentviewmodel.agentConnectionTimeOut.bind { [unowned self] in
  39. guard $0 != nil else {
  40. return
  41. }
  42. self.enableUserInteractions()
  43. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  44. if PayoutViewController.payoutConnectionTimeOutCheck == 0{
  45. PayoutViewController.payoutConnectionTimeOutCheck = PayoutViewController.payoutConnectionTimeOutCheck+1
  46. self.popUpMessage(value: 20)
  47. }
  48. }
  49. agentviewmodel.internetConnection.bind { [unowned self] in
  50. guard $0 != nil else {
  51. return
  52. }
  53. self.enableUserInteractions()
  54. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  55. self.popUpMessage(value: 15)
  56. }
  57. agentviewmodel.fetchAgentLocation(countryId: "118", city: "")
  58. agentviewmodel.agentLocationAvailable.bind { [unowned self] in
  59. guard $0 != nil else {
  60. return
  61. }
  62. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  63. self.enableUserInteractions()
  64. guard $0! else {
  65. return
  66. }
  67. if self.agentviewmodel.getAgentCount() > 0 {
  68. for i in 0...self.agentviewmodel.getAgentCount()-1 {
  69. self.agentNamesArray.append(self.agentviewmodel.getAgentName(index: i))
  70. }
  71. self.tableViewAgent.reloadData()
  72. }
  73. }
  74. }
  75. override func didReceiveMemoryWarning() {
  76. super.didReceiveMemoryWarning()
  77. }
  78. }
  79. extension PayoutViewController: UITableViewDelegate, UITableViewDataSource {
  80. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  81. return agentviewmodel.getAgentCount()
  82. }
  83. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  84. let cell = tableView.dequeueReusableCell(withIdentifier: "payoutTableViewCell", for: indexPath) as! PayoutTableViewCell
  85. cell.labelPayoutName.text = agentviewmodel.getAgentName(index: indexPath.row)
  86. cell.labelPayoutAddress.text = agentviewmodel.getAgentAddress(index: indexPath.row)
  87. cell.buttonPhone.setTitle(agentviewmodel.getAgentPhone(index: indexPath.row), for: .normal)
  88. cell.layer.borderColor = UIColor(red:0.91, green:0.93, blue:0.95, alpha:1.0).cgColor
  89. cell.layer.borderWidth = 5
  90. cell.layer.cornerRadius = 10
  91. cell.clipsToBounds = true
  92. return cell
  93. }
  94. func sectionIndexTitles(for tableView: UITableView) -> [String]? {
  95. return ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#"]
  96. }
  97. func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
  98. let tappedIndex = self.agentNamesArray.index(where: {$0.prefix(1).uppercased() == title})
  99. if tappedIndex != nil {
  100. self.previousIndex = tappedIndex!
  101. tableView.scrollToRow(at: IndexPath(row: tappedIndex!, section: 0), at: UITableViewScrollPosition.top, animated: true)
  102. }
  103. return previousIndex
  104. }
  105. }
  106. extension PayoutViewController: UISearchBarDelegate {
  107. func createSearchBar() {
  108. searchbar.returnKeyType = UIReturnKeyType.done
  109. searchbar.becomeFirstResponder()
  110. }
  111. func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
  112. searchActive = true
  113. // searchbar.showsCancelButton = true
  114. }
  115. func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
  116. searchActive = false
  117. }
  118. func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
  119. searchActive = false
  120. searchbar.showsCancelButton = false
  121. searchBar.resignFirstResponder()
  122. }
  123. func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
  124. searchActive = false
  125. searchBar.resignFirstResponder()
  126. }
  127. func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
  128. if !(searchText.isEmpty){
  129. // print("after every text gets changed")
  130. } else {
  131. }
  132. }
  133. }