-
Notifications
You must be signed in to change notification settings - Fork 0
/
TweetCellTableViewCell.swift
85 lines (69 loc) · 2.4 KB
/
TweetCellTableViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// TweetCellTableViewCell.swift
// Twitter
//
// Created by Navid Chowdhury on 10/7/21.
// Copyright © 2021 Dan. All rights reserved.
//
import UIKit
class TweetCellTableViewCell: UITableViewCell {
@IBOutlet weak var profileImageView: UIImageView!
@IBOutlet weak var userNameLabel: UILabel!
@IBOutlet weak var tweetContent: UILabel!
@IBOutlet weak var retweetButton: UIButton!
@IBOutlet weak var favbutton: UIButton!
var favorited: Bool = false
var tweetId: Int = -1
//var retweeted:Bool = false
@IBAction func favoriteTweet(_ sender: Any) {
let toBeFavorited = !favorited
if(toBeFavorited){
TwitterAPICaller.client?.favoriteTweet(tweetId: tweetId, success: {
self.setFavorite(true)
}, failure: { (error) in
print("Favorite did not succeed: \(error)")
})
}
else{
TwitterAPICaller.client?.unfavoriteTweet(tweetId: tweetId, success: {
self.setFavorite(false)
}, failure: { (error) in
print("Unfavorite did not succeed \(error)")
})
}
}
@IBAction func retweet(_ sender: Any) {
TwitterAPICaller.client?.retweet(tweetId: tweetId, success: {
self.setRetweeted(true)
}, failure: { (error) in
print("Error in retweeting \(error)")
})
}
func setRetweeted(_ isRetweeted:Bool){
if(isRetweeted){
retweetButton.setImage(UIImage(named: "retweet-icon-green"), for: UIControl.State.normal)
retweetButton.isEnabled = false
}
else{
retweetButton.setImage(UIImage(named: "retweet-icon"), for: UIControl.State.normal)
retweetButton.isEnabled = true
}
}
func setFavorite(_ isFavorited: Bool){
favorited = isFavorited
if(favorited){
favbutton.setImage(UIImage(named:"favor-icon-red"), for: UIControl.State.normal)
}
else{
favbutton.setImage(UIImage(named:"favor-icon"), for: UIControl.State.normal)
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}