forked from NikantVohra/HackerNewsClient-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentCell.swift
More file actions
91 lines (70 loc) · 2.85 KB
/
CommentCell.swift
File metadata and controls
91 lines (70 loc) · 2.85 KB
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
86
87
88
89
90
91
//
// CommentCell.swift
// HackerNews
//
// Created by Vohra, Nikant on 30/03/15.
// Copyright (c) 2015 Vohra, Nikant. All rights reserved.
//
import UIKit
class CommentCell: UITableViewCell {
@IBOutlet weak var avatarImageView: AsyncImageView!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var authorLabel: UILabel!{
didSet {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("authorLabelTapped:"))
tapGestureRecognizer.numberOfTapsRequired = 1;
authorLabel.addGestureRecognizer(tapGestureRecognizer)
authorLabel.userInteractionEnabled = true
}
}
@IBOutlet weak var upvoreButton: SpringButton!
@IBOutlet weak var commentTextView: AutoTextView!
@IBOutlet weak var replyButton: SpringButton!
@IBOutlet weak var indentView: UIView!
@IBOutlet weak var avatarLeftConstraint: NSLayoutConstraint!
weak var delegate: CommentTableViewCellDelegate?
func authorLabelTapped(sender: AnyObject) {
delegate?.commentTableViewCellDidTouchAuthorLabel(self)
}
func configureWithComment(comment: HNComment?) {
let userDisplayName = comment!.Username
let createdAt = comment!.TimeCreatedString
let bodyHTML = comment!.Text
authorLabel.text = userDisplayName
timeLabel.text = createdAt
commentTextView.text = bodyHTML
let depth = comment!.Level > 4 ? 4 : comment!.Level
if depth > 0 {
avatarLeftConstraint.constant = CGFloat(depth) * 20 + 25
separatorInset = UIEdgeInsets(top: 0, left: CGFloat(depth) * 20 + 15, bottom: 0, right: 0)
indentView.hidden = false
} else {
avatarLeftConstraint.constant = 10
separatorInset = UIEdgeInsets(top: 0, left: 35, bottom: 0, right: 0)
indentView.hidden = true
}
if (HNManager.sharedManager().hasVotedOnObject(comment)) {
upvoreButton.imageView?.image = UIImage(named: "icon-upvote-active")
}
else {
upvoreButton.imageView?.image = UIImage(named: "icon-upvote")
}
}
@IBAction func didTouchUpvoteButton(sender: AnyObject) {
delegate?.commentTableViewCellDidTouchUpvote(self)
upvoreButton.animation = "pop"
upvoreButton.force = 3
upvoreButton.animate()
}
@IBAction func didTouchReplyButton(sender: AnyObject) {
delegate?.commentTableViewCellDidTouchComment(self)
replyButton.animation = "pop"
replyButton.force = 3
replyButton.animate()
}
}
protocol CommentTableViewCellDelegate: class {
func commentTableViewCellDidTouchUpvote(cell: CommentCell)
func commentTableViewCellDidTouchComment(cell: CommentCell)
func commentTableViewCellDidTouchAuthorLabel(cell: CommentCell)
}