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.

138 lines
4.8 KiB

6 years ago
  1. //
  2. // LikesViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Fm-user on 1/16/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class LikesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  10. var likedByArray: [Like]!
  11. var socialfeedviewmodel: SocialFeedViewModel?
  12. var tappedIndex: Int?
  13. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  14. @IBOutlet weak var tableviewLikes: UITableView!
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17. setUpNavBar(id: 5, title: "")
  18. guard socialfeedviewmodel != nil else {
  19. return
  20. }
  21. setUpAnotherLoginListener(genericviewmodel: socialfeedviewmodel!)
  22. socialfeedviewmodel?.socialFeedConnectionTimeOut.value = nil
  23. /**
  24. connection timeout
  25. */
  26. socialfeedviewmodel?.socialFeedConnectionTimeOut.bind { [unowned self] in
  27. guard $0 != nil else {
  28. return
  29. }
  30. self.enableUserInteractions()
  31. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  32. self.popUpMessage(value: 20)
  33. }
  34. disableUserInteractions()
  35. showActivityIndicator(activityIndicator: activityIndicator)
  36. self.tableviewLikes.rowHeight = UITableViewAutomaticDimension
  37. self.tableviewLikes.estimatedRowHeight = 70
  38. self.tableviewLikes.tableFooterView = UIView()
  39. setUpListener()
  40. if tappedIndex != nil {
  41. let feed = socialfeedviewmodel!.getSocialFeedAt(index: tappedIndex!)
  42. socialfeedviewmodel!.fetchAllLikesFor(feedId: feed.id)
  43. } else {
  44. let feed = socialfeedviewmodel!.getParticularFeed()
  45. socialfeedviewmodel!.fetchAllLikesFor(feedId: feed.id)
  46. }
  47. }
  48. func setUpListener() {
  49. socialfeedviewmodel!.socialFeedsRxValue.bind { [weak self] in
  50. guard $0 != nil else {
  51. return
  52. }
  53. self?.enableUserInteractions()
  54. if self?.activityIndicator != nil {
  55. self?.dismissActivityIndicator(activityIndicator: (self?.activityIndicator)!)
  56. }
  57. guard $0 != 0 else {
  58. self?.popUpMessageError(value: 10, message: (self?.socialfeedviewmodel!.getErrorMessage())!)
  59. self?.socialfeedviewmodel!.socialFeedsRxValue.value = nil
  60. return
  61. }
  62. if $0 == socialWallCode.fetchLikes.rawValue {
  63. self?.likedByArray = self?.socialfeedviewmodel?.getAllLikes()
  64. self?.tableviewLikes.reloadData()
  65. }
  66. self?.socialfeedviewmodel!.socialFeedsRxValue.value = nil
  67. }
  68. }
  69. override func didReceiveMemoryWarning() {
  70. super.didReceiveMemoryWarning()
  71. }
  72. func numberOfSections(in tableView: UITableView) -> Int {
  73. return 1
  74. }
  75. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  76. if likedByArray != nil {
  77. return likedByArray.count
  78. }
  79. return 0
  80. }
  81. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  82. let cell = tableView.dequeueReusableCell(withIdentifier: "likeCell", for: indexPath) as! likesTableViewCell
  83. cell.imageViewUserImage.layer.cornerRadius = cell.imageViewUserImage.frame.height / 2
  84. cell.labelUsername.text = likedByArray[indexPath.row].userName
  85. cell.labelUserNameInitial.isHidden = false
  86. cell.labelUserNameInitial.backgroundColor = UIColor(hex: 0x2e3192)
  87. cell.labelUserNameInitial.layer.cornerRadius = cell.labelUserNameInitial.frame.height / 2
  88. cell.labelUserNameInitial.text = likedByArray[indexPath.row].userName.prefix(1).uppercased()
  89. if let userDpString = likedByArray[indexPath.row].userDpUrl {
  90. if let userDpUrl = URL(string: userDpString) {
  91. cell.imageViewUserImage.isHidden = false
  92. cell.imageViewUserImage.sd_setImage(with: userDpUrl, placeholderImage: nil, options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
  93. }
  94. cell.labelUserNameInitial.isHidden = true
  95. }
  96. // if let userDpString = likedByArray[indexPath.row].userDpUrl {
  97. // if let userDpUrl = URL(string: userDpString) {
  98. // cell.imageViewUserImage.sd_setImage(with: userDpUrl, placeholderImage: #imageLiteral(resourceName: "gme-logo"), options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
  99. // }
  100. // }
  101. return cell
  102. }
  103. }