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
138 lines
4.8 KiB
//
|
|
// LikesViewController.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by Fm-user on 1/16/18.
|
|
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class LikesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
|
|
|
var likedByArray: [Like]!
|
|
var socialfeedviewmodel: SocialFeedViewModel?
|
|
var tappedIndex: Int?
|
|
|
|
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
|
|
|
|
@IBOutlet weak var tableviewLikes: UITableView!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
setUpNavBar(id: 5, title: "")
|
|
|
|
guard socialfeedviewmodel != nil else {
|
|
return
|
|
}
|
|
|
|
setUpAnotherLoginListener(genericviewmodel: socialfeedviewmodel!)
|
|
|
|
socialfeedviewmodel?.socialFeedConnectionTimeOut.value = nil
|
|
/**
|
|
connection timeout
|
|
*/
|
|
socialfeedviewmodel?.socialFeedConnectionTimeOut.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.enableUserInteractions()
|
|
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
|
|
self.popUpMessage(value: 20)
|
|
}
|
|
|
|
|
|
disableUserInteractions()
|
|
showActivityIndicator(activityIndicator: activityIndicator)
|
|
|
|
self.tableviewLikes.rowHeight = UITableViewAutomaticDimension
|
|
self.tableviewLikes.estimatedRowHeight = 70
|
|
self.tableviewLikes.tableFooterView = UIView()
|
|
setUpListener()
|
|
|
|
|
|
if tappedIndex != nil {
|
|
let feed = socialfeedviewmodel!.getSocialFeedAt(index: tappedIndex!)
|
|
socialfeedviewmodel!.fetchAllLikesFor(feedId: feed.id)
|
|
} else {
|
|
let feed = socialfeedviewmodel!.getParticularFeed()
|
|
socialfeedviewmodel!.fetchAllLikesFor(feedId: feed.id)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
func setUpListener() {
|
|
|
|
socialfeedviewmodel!.socialFeedsRxValue.bind { [weak self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
|
|
self?.enableUserInteractions()
|
|
|
|
if self?.activityIndicator != nil {
|
|
self?.dismissActivityIndicator(activityIndicator: (self?.activityIndicator)!)
|
|
}
|
|
|
|
guard $0 != 0 else {
|
|
self?.popUpMessageError(value: 10, message: (self?.socialfeedviewmodel!.getErrorMessage())!)
|
|
self?.socialfeedviewmodel!.socialFeedsRxValue.value = nil
|
|
return
|
|
}
|
|
|
|
if $0 == socialWallCode.fetchLikes.rawValue {
|
|
self?.likedByArray = self?.socialfeedviewmodel?.getAllLikes()
|
|
self?.tableviewLikes.reloadData()
|
|
}
|
|
self?.socialfeedviewmodel!.socialFeedsRxValue.value = nil
|
|
}
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
}
|
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
return 1
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
if likedByArray != nil {
|
|
return likedByArray.count
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "likeCell", for: indexPath) as! likesTableViewCell
|
|
cell.imageViewUserImage.layer.cornerRadius = cell.imageViewUserImage.frame.height / 2
|
|
|
|
cell.labelUsername.text = likedByArray[indexPath.row].userName
|
|
|
|
cell.labelUserNameInitial.isHidden = false
|
|
cell.labelUserNameInitial.backgroundColor = UIColor(hex: 0x2e3192)
|
|
cell.labelUserNameInitial.layer.cornerRadius = cell.labelUserNameInitial.frame.height / 2
|
|
cell.labelUserNameInitial.text = likedByArray[indexPath.row].userName.prefix(1).uppercased()
|
|
|
|
if let userDpString = likedByArray[indexPath.row].userDpUrl {
|
|
if let userDpUrl = URL(string: userDpString) {
|
|
cell.imageViewUserImage.isHidden = false
|
|
|
|
cell.imageViewUserImage.sd_setImage(with: userDpUrl, placeholderImage: nil, options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
|
|
}
|
|
cell.labelUserNameInitial.isHidden = true
|
|
}
|
|
|
|
|
|
// if let userDpString = likedByArray[indexPath.row].userDpUrl {
|
|
// if let userDpUrl = URL(string: userDpString) {
|
|
// cell.imageViewUserImage.sd_setImage(with: userDpUrl, placeholderImage: #imageLiteral(resourceName: "gme-logo"), options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
|
|
// }
|
|
// }
|
|
|
|
return cell
|
|
}
|
|
}
|