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.
 
 
 
 

896 lines
35 KiB

//
// MyStoryViewController.swift
// GMERemittance
//
// Created by FMI-12 on 1/30/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
class MyStoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MyStoryTableViewCellDelegate {
@IBOutlet weak var myStoryTableView: UITableView!
private var refreshControl: UIRefreshControl!
private var editablePostIndex: Int!
var statusUploadMode: Int?
var postStatus: String?
var selectedCell: Int?
var selectedImage: UIImage?
var socialfeedviewmodel: SocialFeedViewModel?
var cellStory: MyStoryTableViewCell?
var showNotificationParameter: Bool!
private var allowFetchRequest: Bool = true
private var arrayIndexPath = [IndexPath] ()
private var newFeedsWillBeAppended: Bool = false
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
public static var socialFeedConnectionTimeOutCheck = 0
// /*----------------------------
// -----> 0 = get #N social feeds
// -----> 1 = get all likes
// -----> 2 = like/ dislike feed
// -----> 3 = comment
// -----> 4 =
// ----------------------------*/
// private var feedDataIndex: Int = 0
private var tappedIndex: Int?
@IBOutlet weak var buttonMenuItem0: UIButton!
@IBOutlet weak var buttonMenuItem1: UIButton!
@IBOutlet weak var buttonMenuItem2: UIButton!
@IBOutlet weak var labelMenuItem0: UILabel!
@IBOutlet weak var labelMenuItem1: UILabel!
@IBOutlet weak var labelMenuItem2: UILabel!
private var menuIndexArray: [Int]!
private var collectionViewMenuIconArray: [Int: String] = [0: "send-money", 1: "mobile-recharge", 2: "rate-today", 3: "track-transfer", 4: "transaction-statement", 5: "wallet-transfer", 6: "show-more"]
private var collectionViewMenuNameArray: [Int: String] = [0: "Send Money", 1: "Mobile Recharge", 2: "Today's Rate", 3: "Track Your Transfer", 4: "Transaction Statement", 5: "Wallet to Wallet Transfer", 6: "More"]
@IBAction func showHomeScreen(_ sender: Any) {
showHomeScreen2()
}
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24)
setNavBar()
setActionBarIcons()
bindFeedsDataToUI()
setUpRefreshControl()
guard socialfeedviewmodel != nil else {
return
}
socialfeedviewmodel?.socialFeedConnectionTimeOut.value = nil
/**
connection timeout
*/
socialfeedviewmodel?.socialFeedConnectionTimeOut.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
if MyStoryViewController.socialFeedConnectionTimeOutCheck == 0{
MyStoryViewController.socialFeedConnectionTimeOutCheck = MyStoryViewController.socialFeedConnectionTimeOutCheck+1
self.popUpMessage(value: 28)
}
}
setUpNetworkListener()
setUpAnotherLoginListener(genericviewmodel: socialfeedviewmodel!)
socialfeedviewmodel!.resetFeedCount()
socialfeedviewmodel!.setAccessType(accessType: "private")
socialfeedviewmodel!.resetBeforeAfterFeedId()
if let menuArray = UserDefaults.standard.array(forKey: "com.gmeremit.collectionViewMenuIndexArray") as? [Int] {
menuIndexArray = menuArray
} else {
menuIndexArray = [0, 1, 2, 6, 4, 5, 3]
}
setUpMenuIcon()
socialfeedviewmodel!.setAccessType(accessType: "private")
myStoryTableView.reloadSections(NSIndexSet(index: 1) as IndexSet, with: .none)
if tappedIndex != nil {
self.myStoryTableView.scrollToRow(at: IndexPath(row: tappedIndex!, section: 1), at: UITableViewScrollPosition.bottom, animated: true)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
func setUpNetworkListener() {
socialfeedviewmodel!.internetConnection.value = nil
socialfeedviewmodel!.internetConnection.bind { [unowned self] in
guard $0 != nil else {
return
}
if self.activityIndicator.isAnimating {
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
}
self.enableUserInteractions()
self.popUpMessage(value: 15)
}
}
func setUpRefreshControl() {
refreshControl = UIRefreshControl()
refreshControl.backgroundColor = UIColor(white: 0.98, alpha: 1.0)
refreshControl.tintColor = UIColor.red
refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)
myStoryTableView.addSubview(refreshControl)
}
@objc func refresh(_ sender: AnyObject) {
newFeedsWillBeAppended = false
socialfeedviewmodel!.fetchSocialFeeds(isPublic: false, loadMore: false)
}
func setUpMenuIcon() {
buttonMenuItem0.setImage(UIImage(named: collectionViewMenuIconArray[menuIndexArray[0]]!), for: .normal)
buttonMenuItem0.tag = menuIndexArray[0]
buttonMenuItem1.setImage(UIImage(named: collectionViewMenuIconArray[menuIndexArray[1]]!), for: .normal)
buttonMenuItem1.tag = menuIndexArray[1]
buttonMenuItem2.setImage(UIImage(named: collectionViewMenuIconArray[menuIndexArray[2]]!), for: .normal)
buttonMenuItem2.tag = menuIndexArray[2]
labelMenuItem0.text = collectionViewMenuNameArray[menuIndexArray[0]]
labelMenuItem1.text = collectionViewMenuNameArray[menuIndexArray[1]]
labelMenuItem2.text = collectionViewMenuNameArray[menuIndexArray[2]]
buttonMenuItem0.addTarget(self, action: #selector(performRedirection(_:)), for: .touchUpInside)
buttonMenuItem1.addTarget(self, action: #selector(performRedirection(_:)), for: .touchUpInside)
buttonMenuItem2.addTarget(self, action: #selector(performRedirection(_:)), for: .touchUpInside)
}
@objc func performRedirection(_ sender: UIButton) {
switch sender.tag {
case 0:
if (UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as! Bool) {
self.performSegue(withIdentifier: "recipientList2", sender: nil)
} else {
self.popUpMessage(value: 13)
}
case 1:
if (UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as! Bool) {
self.performSegue(withIdentifier: "mobileRecharge2", sender: nil)
} else {
self.popUpMessage(value: 13)
}
case 2:
self.performSegue(withIdentifier: "todayRate2", sender: nil)
case 3:
self.performSegue(withIdentifier: "trackTransfer2", sender: nil)
case 4:
self.performSegue(withIdentifier: "transactionStatement2", sender: nil)
case 5:
if (UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as! Bool) {
self.performSegue(withIdentifier: "walletTransfer2", sender: nil)
} else {
self.popUpMessage(value: 13)
}
default:
return
}
}
//DATA BINDING
func bindFeedsDataToUI() {
socialfeedviewmodel!.socialFeedsRxValue.bind { [unowned self] in
guard $0 != nil else {
return
}
self.dismissActivityIndicator(activityIndicator: (self.activityIndicator))
guard $0 != 0 else {
self.socialfeedviewmodel!.socialFeedsRxValue.value = nil
return
}
switch $0 {
case socialWallCode.fetchPostsPrivate.rawValue?:
let count = self.socialfeedviewmodel!.getPrivateSocialFeedsCount()
if count > 0 {
if (self.newFeedsWillBeAppended) {
self.arrayIndexPath.removeAll()
self.myStoryTableView.beginUpdates()
let currentCount = self.socialfeedviewmodel!.getCurrentlyFetchedFeedCount()
for i in 0...currentCount-1 {
self.arrayIndexPath.append(IndexPath.init(row: count - currentCount + i, section: 1))
}
self.myStoryTableView.insertRows(at: (self.arrayIndexPath), with: .automatic)
self.myStoryTableView.endUpdates()
self.myStoryTableView.cellForRow(at: IndexPath(row: 0, section: 2))?.isHidden = false
} else {
if (self.refreshControl.isRefreshing) {
self.refreshControl.endRefreshing()
}
self.myStoryTableView.reloadSections(NSIndexSet(index: 1) as IndexSet, with: .none)
}
self.myStoryTableView.reloadSections(NSIndexSet(index: 2) as IndexSet, with: .none)
}
case socialWallCode.deletePost.rawValue?:
self.socialfeedviewmodel!.removeSocialFeed(atIndex: (self.tappedIndex)!)
self.myStoryTableView.deleteRows(at: [IndexPath(item: (self.tappedIndex)!, section: 1)], with: .automatic)
case socialWallCode.likeUnlikePost.rawValue?:
self.socialfeedviewmodel!.updateSocialFeedArrayLikeNumber(atIndex: (self.tappedIndex)!)
self.myStoryTableView.reloadRows(at: [IndexPath(item: (self.tappedIndex)!, section: 1)], with: UITableViewRowAnimation.automatic)
case socialWallCode.createUpdatePost.rawValue?:
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
let alert = UIAlertController(title:"", message:"This post is made public." , preferredStyle: .actionSheet)
self.present(alert, animated: true, completion: nil)
let when = DispatchTime.now() + 2
DispatchQueue.main.asyncAfter(deadline: when){
alert.dismiss(animated: true, completion: nil)
}
default:
return
}
self.socialfeedviewmodel!.socialFeedsRxValue.value = nil
}
}
func setNavBar() {
navigationItem.hidesBackButton = true
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 125, height: 30))
imageView.contentMode = .scaleAspectFit
let image = UIImage(named: "ic_gme_new")
imageView.image = image
navigationItem.titleView = imageView
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "ic_hamburger"), style: .plain, target: self, action: #selector(showSideMenu))
self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
}
func setActionBarIcons() {
let supportImage = UIImage(named: "ic_support")?.withRenderingMode(.alwaysOriginal)
let supportButton = UIBarButtonItem(image:supportImage, style: .plain, target: self, action: #selector(showSupport))
let notificationImage: UIImage!
if showNotificationParameter {
notificationImage = UIImage(named: "ic_notificationDot")?.withRenderingMode(.alwaysOriginal)
} else {
notificationImage = UIImage(named: "ic_notification")?.withRenderingMode(.alwaysOriginal)
}
let notificationButton = UIBarButtonItem(image: notificationImage, style: .plain, target: self, action: #selector(showNotification))
//self.tabBarController?.navigationItem.rightBarButtonItem.badge
self.navigationItem.rightBarButtonItems=[notificationButton,supportButton]
}
/**
@developer : Suraj Shrestha
@date : 2018/02/12
@des : Show support actions
*/
@objc func showSupport() {
let alert = UIAlertController(title:nil, message:"We are there to help you \n (Available time 10:00AM - 6:00PM)", preferredStyle: .actionSheet)
alert.view.subviews.last?.subviews.last?.backgroundColor = UIColor.darkGray
let liveChat = UIAlertAction(title: "Live Chat", style: .default) {
UIAlertAction in
}
let contactNumber = UIAlertAction(title: "1588 6864", style: .default) {
UIAlertAction in
self.startCall(contactNumber: "1588 6864")
}
let supportEmail = UIAlertAction(title: "support@gmeremit.com", style: .default) {
UIAlertAction in
let storyboard = UIStoryboard.init(name: "Home", bundle: Bundle.main)
if let messageViewController = storyboard.instantiateViewController(withIdentifier: "message") as? MessageComposeViewController {
messageViewController.supportIndex = 0
self.navigationController!.pushViewController(messageViewController, animated: true)
}
}
liveChat.setValue(UIImage(named:"ic_live_chat")?.withRenderingMode(.alwaysOriginal),forKey:"image")
contactNumber.setValue(UIImage(named:"ic_call")?.withRenderingMode(.alwaysOriginal),forKey:"image")
supportEmail.setValue(UIImage(named:"ic_email")?.withRenderingMode(.alwaysOriginal),forKey:"image")
// TODO: have to enable when zendesk is provided
// alert.addAction(liveChat)
alert.addAction(contactNumber)
alert.addAction(supportEmail)
alert.view.tintColor = UIColor.red
alert.view.subviews.last?.subviews.last?.layer.cornerRadius = 10
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
@objc func showNotification(){
performSegue(withIdentifier: "notification", sender: nil)
}
@objc func showSideMenu() {
performSegue(withIdentifier: "showSideMenu", sender: nil)
}
func startCall(contactNumber: String){
if let url = URL(string: "tel://\(contactNumber)"), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
}
@IBAction func buttonUploadStatus(_ sender: Any) {
statusUploadMode = 0
self.performSegue(withIdentifier: "statusUpdate2", sender: nil)
}
@IBAction func buttonUploadSocialImage(_ sender: Any) {
statusUploadMode = 1
self.performSegue(withIdentifier: "statusUpdate2", sender: nil)
}
@IBAction func buttomGmeFamilyTap(_ sender: Any) {
showHomeScreen()
}
// MARK: - TableView
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return 1
case 1:
if allowFetchRequest && self.socialfeedviewmodel!.getPrivateSocialFeedsCount() < 10 {
showActivityIndicator(activityIndicator: activityIndicator)
socialfeedviewmodel!.fetchSocialFeeds(isPublic: false, loadMore: false)
allowFetchRequest = false
return 0
}
return self.socialfeedviewmodel!.getPrivateSocialFeedsCount()
case 2:
return 1
default:
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cellStatus = tableView.dequeueReusableCell(withIdentifier: "statusCell", for: indexPath) as! MyStoryTableViewCell
cellStatus.labelInitial.isHidden = false
cellStatus.labelInitial.backgroundColor = UIColor(hex: 0x2e3192)
cellStatus.labelInitial.layer.cornerRadius = cellStatus.labelInitial.frame.height / 2
cellStatus.labelInitial.text = getFirstName().prefix(1).uppercased()
let userDpString = UserDefaults.standard.object(forKey: "com.gmeremit.dpUrl") as? String
if let userDpUrl = URL(string: userDpString!) {
cellStatus.imageViewUserStatus.isHidden = false
cellStatus.imageViewUserStatus.sd_setImage(with: userDpUrl, placeholderImage: nil, options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
cellStatus.imageViewUserStatus.layer.cornerRadius = cellStatus.imageViewUserStatus.frame.height/2
cellStatus.labelInitial.isHidden = true
}
return cellStatus
case 1:
socialfeedviewmodel!.setAccessType(accessType: "private")
let socialFeed = self.socialfeedviewmodel!.getSocialFeedAt(index:indexPath.row)
if socialFeed.blocked! {
return self.getTableViewCell(indexPath: indexPath, socialFeed: socialFeed, mode: 0)
} else {
if socialFeed.feedText != nil && socialFeed.feedText != "" {
if socialFeed.feedImageId != nil {
//CASE 3: text and image
return self.getTableViewCell(indexPath: indexPath, socialFeed: socialFeed, mode: 3)
} else {
//CASE 1: only text
return self.getTableViewCell(indexPath: indexPath, socialFeed: socialFeed, mode: 1)
}
} else {
//CASE 2: only image
return self.getTableViewCell(indexPath: indexPath, socialFeed: socialFeed, mode: 2)
}
}
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "loadMoreCell", for: indexPath) as! MyStoryTableViewCell
if socialfeedviewmodel!.loadMore() {
cell.buttonLoadMore.addTarget(self, action: #selector(loadMore(_:)), for: .touchUpInside)
cell.buttonLoadMore.isHidden = false
} else {
cell.buttonLoadMore.isHidden = true
}
cell.buttonLoadMore.addTarget(self, action: #selector(loadMore(_:)), for: .touchUpInside)
return cell
default:
return cellStory!
}
}
@objc func loadMore(_ sender: TableViewCell) {
showActivityIndicator(activityIndicator: activityIndicator)
newFeedsWillBeAppended = true
myStoryTableView.cellForRow(at: IndexPath(row: 0, section: 2))?.isHidden = true
socialfeedviewmodel!.fetchSocialFeeds(isPublic: false, loadMore: true)
}
//DISPLAY FEEDS ON THE GME WALL
func getTableViewCell(indexPath: IndexPath, socialFeed : SocialFeed, mode: Int) -> UITableViewCell {
let cell: MyStoryTableViewCell!
switch mode {
case 0:
cell = myStoryTableView.dequeueReusableCell(withIdentifier: "myStoryCellText", for: indexPath) as! MyStoryTableViewCell
cell.labelStatus.isHidden = true
cell.labelBlocked.alpha = 1
cell.imageViewBlocked.alpha = 1
cell.viewSocialAction.isHidden = true
return cell
case 1:
cell = myStoryTableView.dequeueReusableCell(withIdentifier: "myStoryCellText", for: indexPath) as! MyStoryTableViewCell
cell.labelStatus.isHidden = false
cell.labelBlocked.alpha = 0
cell.imageViewBlocked.alpha = 0
cell.viewSocialAction.isHidden = false
cell.labelStatus.text = socialFeed.feedText
cell.labelStatus.textColor = UIColor(red:0.29, green:0.29, blue:0.29, alpha:1.0)
case 2:
cell = myStoryTableView.dequeueReusableCell(withIdentifier: "myStoryCellImage", for: indexPath) as! MyStoryTableViewCell
cell.imageViewSocial.sd_setImage(with: URL(string: socialFeed.feedImage!)!, placeholderImage: nil, options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
cell.postImageHeight.constant = view.frame.width
case 3:
cell = myStoryTableView.dequeueReusableCell(withIdentifier: "myStoryCellTextImage", for: indexPath) as! MyStoryTableViewCell
cell.labelStatus.text = socialFeed.feedText
cell.labelStatus.textColor = UIColor(red:0.29, green:0.29, blue:0.29, alpha:1.0)
cell.imageViewSocial.sd_setImage(with: URL(string: socialFeed.feedImage!)!, placeholderImage: nil, options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
cell.postImageHeight.constant = view.frame.width
default:
cell = myStoryTableView.dequeueReusableCell(withIdentifier: "socialCellTextImage", for: indexPath) as! MyStoryTableViewCell
}
cell.layer.borderColor = UIColor(red:0.91, green:0.93, blue:0.95, alpha:1.0).cgColor
cell.layer.borderWidth = 2
cell.imageViewUserImage.layer.cornerRadius = cell.imageViewUserImage.frame.height / 2
cell.editPostButton?.addTarget(self, action:#selector(showPostOptions(_:)), for:.touchUpInside)
cell.heartButton?.addTarget(self, action:#selector(toggleLike(_:)), for:.touchUpInside)
cell.likeButton?.addTarget(self, action:#selector(showLikes(_:)), for:.touchUpInside)
if socialFeed.accessType == "public" {
cell.commentButton?.addTarget(self, action: #selector(showComments(_:)), for: .touchUpInside)
}
//Display USERNAME who has posted the feed
cell.labelSocialUsername.text = socialfeedviewmodel!.getFullName(feed: socialFeed)
cell.labelUserNameInitial.isHidden = false
cell.labelUserNameInitial.backgroundColor = UIColor(hex: 0x2e3192)
cell.labelUserNameInitial.layer.cornerRadius = cell.labelUserNameInitial.frame.height / 2
cell.labelUserNameInitial.text = socialFeed.firstName.prefix(1).uppercased()
if let userDpString = socialFeed.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
}
//Display timeStamp (ago date)
cell.labelTimeStamp.text = socialFeed.agoDate
//Display LIKE status
if socialFeed.liked {
cell.heartButton?.setImage(UIImage(named:"ic_heartfull"), for: UIControlState.normal)
} else {
cell.heartButton?.setImage(UIImage(named:"ic_heart"), for: UIControlState.normal)
}
//Display total number of LIKES
if socialFeed.totalLike > 1 {
cell.likeButton.setTitle("\(socialFeed.totalLike) Likes", for:UIControlState.normal)
} else {
cell.likeButton.setTitle("\(socialFeed.totalLike) Like", for:UIControlState.normal)
}
//Display total number of COMMENTS
if socialFeed.totalComment > 1 {
cell.commentButton.setTitle(" \(socialFeed.totalComment) Comments", for: UIControlState.normal)
} else {
cell.commentButton.setTitle(" \(socialFeed.totalComment) Comment", for: UIControlState.normal)
}
return cell
}
func populateTableViewCell(index:Int, privateFeed: SocialFeed){
cellStory?.imageViewUserImage.image = UIImage(named:"profile_img")
cellStory?.imageViewUserImage.layer.cornerRadius = (cellStory?.imageViewUserImage.frame.height)! / 2
cellStory?.editPostButton?.addTarget(self, action:#selector(showPostOptions(_:)), for:.touchUpInside)
cellStory?.heartButton?.addTarget(self, action:#selector(toggleLike(_:)), for:.touchUpInside)
cellStory?.commentButton?.addTarget(self, action: #selector(showComments(_:)), for: .touchUpInside)
cellStory?.labelStatus.text = privateFeed.feedText
//Display User Name
cellStory?.labelSocialUsername.text = socialfeedviewmodel?.getFullName(feed: privateFeed)
//Display User Image
if let userDpString = privateFeed.userDpUrl {
if let userDpUrl = URL(string: userDpString) {
cellStory?.imageViewUserImage.sd_setImage(with: userDpUrl, placeholderImage: #imageLiteral(resourceName: "gme-logo"), options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
}
}
//Display TIMES STAMP
cellStory?.labelTimeStamp.text = privateFeed.agoDate
if privateFeed.blocked! {
cellStory?.imageViewBlocked.isHidden = false
cellStory?.labelBlocked.isHidden = false
cellStory?.labelStatus.isHidden = true
cellStory?.imageViewSocial.isHidden = true
cellStory?.viewSocialAction.isHidden = true
cellStory?.constraintHeightViewSocial.constant = 0
} else {
cellStory?.imageViewBlocked.isHidden = true
cellStory?.labelBlocked.isHidden = true
//Display feed
cellStory?.labelStatus.text = privateFeed.feedText
//change like button color
if privateFeed.liked {
cellStory?.heartButton?.setImage(UIImage(named:"ic_heartfull"), for: UIControlState.normal)
}
else {
cellStory?.heartButton?.setImage(UIImage(named:"ic_heart"), for: UIControlState.normal)
}
//Display total number of likes
if privateFeed.totalLike > 1 {
cellStory?.likeButton.setTitle("\(privateFeed.totalLike) Likes", for:UIControlState.normal)
}
else {
cellStory?.likeButton.setTitle("\(privateFeed.totalLike) Like", for:UIControlState.normal)
}
//Display total number of comments
if privateFeed.totalComment > 1{
cellStory?.commentButton.setTitle(" \(privateFeed.totalComment) Comments", for: UIControlState.normal)
}
else{
cellStory?.commentButton.setTitle(" \(privateFeed.totalComment) Comment", for: UIControlState.normal)
}
//Display feed Image
if privateFeed.feedImage != nil {
let feedImageUrl = URL(string: (privateFeed.feedImage!))
// cellStory?.postImageHeight.constant = view.frame.width
cellStory?.imageViewSocial.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.width)
cellStory?.imageViewSocial.sd_setImage(with: feedImageUrl, placeholderImage: #imageLiteral(resourceName: "gme-logo"), options: [.progressiveDownload,.scaleDownLargeImages], completed: nil)
} else {
// cellStory?.postImageHeight.constant = 0
cellStory?.imageViewSocial.image = nil
}
}
}
@objc func toggleLike(_ sender: MyStoryTableViewCell) {
guard let clickedCell = sender.superview?.superview?.superview?.superview as? MyStoryTableViewCell else {
return
}
if let clickedCellIndexPath = myStoryTableView.indexPath(for: clickedCell) {
tappedIndex = clickedCellIndexPath.row
let tappedFeed = socialfeedviewmodel!.getSocialFeedAt(index: tappedIndex!)
socialfeedviewmodel!.likeDislikePost(feedId: tappedFeed.id, liked: tappedFeed.liked)
}
}
@objc func showComments(_ sender: MyStoryTableViewCell) {
guard let clickedCell = sender.superview?.superview?.superview?.superview as? MyStoryTableViewCell else {
return
}
if let clickedCellIndexPath = myStoryTableView.indexPath(for: clickedCell) {
tappedIndex = clickedCellIndexPath.row
guard Reachability.isConnectedToNetwork() else {
self.popUpMessage(value: 15)
return
}
self.performSegue(withIdentifier: "showCommentsBy2", sender: nil)
}
}
@objc func showLikes(_ sender: MyStoryTableViewCell) {
guard let clickedCell = sender.superview?.superview?.superview?.superview as? MyStoryTableViewCell else {
return
}
if let clickedCellIndexPath = myStoryTableView.indexPath(for: clickedCell) {
tappedIndex = clickedCellIndexPath.row
let tappedFeed = socialfeedviewmodel!.getSocialFeedAt(index: clickedCellIndexPath.row)
if tappedFeed.totalLike > 0 {
guard Reachability.isConnectedToNetwork() else {
self.popUpMessage(value: 15)
return
}
//socialfeedviewmodel.fetchAllLikesFor(feedId: tappedFeed.id)
self.performSegue(withIdentifier: "showLikedBy2", sender: nil)
}
}
}
@objc func showPostOptions(_ sender: MyStoryTableViewCell) {
guard let clickedCell = sender.superview?.superview?.superview as? MyStoryTableViewCell else {
return
}
if let clickedCellIndexPath = myStoryTableView.indexPath(for: clickedCell) {
enumeratePostOptions(index: clickedCellIndexPath.row)
}
}
func enumeratePostOptions(index: Int) {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let switchCategoryTitle: String!
if (socialfeedviewmodel?.isPostPrivate(postIndex: index))! {
switchCategoryTitle = "Show this post to GME Community"
} else {
switchCategoryTitle = "Hide this post from GME Community"
}
let show = UIAlertAction(title: switchCategoryTitle, style: .default) {
UIAlertAction in
let feedToEdit = self.socialfeedviewmodel!.getSocialFeedAt(index: index)
if let feedText = feedToEdit.feedText {
self.socialfeedviewmodel!.updateFeedText(text: feedText)
}
if let feedImageId = feedToEdit.feedImageId {
self.socialfeedviewmodel!.setFeedImageId(imageId: feedImageId)
}
self.showActivityIndicator(activityIndicator: self.activityIndicator)
self.socialfeedviewmodel!.updateSocialFeed(feed: feedToEdit, index: index, toggle: true)
}
let edit = UIAlertAction(title: "Edit this post", style: .default) {
UIAlertAction in
self.statusUploadMode = 2
self.editablePostIndex = index
self.performSegue(withIdentifier: "statusUpdate2", sender: nil)
}
let delete = UIAlertAction(title: "Delete this post", style: .default) {
UIAlertAction in
self.deleteConfirmation(postIndex: index)
}
let cancel = UIAlertAction(title: "Cancel", style: .destructive) {
UIAlertAction in
}
alert.addAction(show)
alert.addAction(edit)
alert.addAction(delete)
alert.addAction(cancel)
present(alert, animated: true, completion: nil)
}
func deleteConfirmation(postIndex: Int) {
let alert = UIAlertController(title:nil, message:"Are you sure you want to delete?", preferredStyle: .actionSheet)
let cancel = UIAlertAction(title: "No", style: .destructive) {
UIAlertAction in
}
let delete = UIAlertAction(title: "Yes", style: .destructive) {
UIAlertAction in
self.tappedIndex = postIndex
// self.feedDataIndex = 4
self.socialfeedviewmodel!.deleteSocialFeed(feedId: self.socialfeedviewmodel!.getSocialFeedAt(index: postIndex).id)
}
alert.addAction(cancel)
alert.addAction(delete)
present(alert, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case "statusUpdate2"?:
let statusUploadViewController = segue.destination as! StatusUploadViewController
statusUploadViewController.statusUploadMode = statusUploadMode
statusUploadViewController.editablePostIndex = editablePostIndex
statusUploadViewController.socialfeedviewmodel = socialfeedviewmodel
statusUploadViewController.showNotificationParameter = showNotificationParameter!
case "statusUpdate"?:
let vc = segue.destination as! StatusUploadViewController
if statusUploadMode == 0 {
vc.statusUploadMode = statusUploadMode
} else if statusUploadMode == 1 {
vc.statusUploadMode = statusUploadMode
} else if statusUploadMode == 2 {
vc.statusUploadMode = statusUploadMode
}
vc.showNotificationParameter = showNotificationParameter!
case "showLikedBy2"?:
let likesViewController = segue.destination as! LikesViewController
likesViewController.socialfeedviewmodel = self.socialfeedviewmodel
likesViewController.tappedIndex = self.tappedIndex
case "showCommentsBy2"?:
let commentsViewController = segue.destination as! CommentsViewController
commentsViewController.socialfeedviewmodel = socialfeedviewmodel
commentsViewController.tappedIndex = tappedIndex
case "showMoreOptions2"?:
let homeViewController = segue.destination as! HomeViewController
homeViewController.numberCellsInCollectionView = 6
homeViewController.showAllCollectionViewCells = true
default:
return
}
}
}