-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ActivityTableViewCell.swift
99 lines (75 loc) · 3.13 KB
/
ActivityTableViewCell.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import Foundation
import Gridicons
import WordPressShared.WPTableViewCell
open class ActivityTableViewCell: WPTableViewCell {
var actionButtonHandler: ((UIButton) -> Void)?
// MARK: - Overwritten Methods
open override func awakeFromNib() {
super.awakeFromNib()
assert(iconBackgroundImageView != nil)
assert(contentLabel != nil)
assert(summaryLabel != nil)
assert(actionButton != nil)
}
// MARK: - Public Methods
func configureCell(_ formattableActivity: FormattableActivity) {
activity = formattableActivity.activity
guard let activity = activity else {
return
}
summaryLabel.text = activity.summary
contentLabel.text = activity.text
summaryLabel.textColor = .textSubtle
contentLabel.textColor = .text
iconBackgroundImageView.backgroundColor = Style.getColorByActivityStatus(activity)
if let iconImage = Style.getIconForActivity(activity) {
iconImageView.image = iconImage.imageFlippedForRightToLeftLayoutDirection()
iconImageView.isHidden = false
} else {
iconImageView.isHidden = true
}
contentView.backgroundColor = Style.backgroundColor()
actionButtonContainer.isHidden = !activity.isRewindable
actionButton.setImage(actionGridicon, for: .normal)
actionButton.tintColor = .listIcon
actionButton.accessibilityIdentifier = "activity-cell-action-button"
}
@IBAction func didTapActionButton(_ sender: UIButton) {
actionButtonHandler?(sender)
}
typealias Style = WPStyleGuide.ActivityStyleGuide
// MARK: - Private Properties
fileprivate var activity: Activity?
fileprivate var actionGridicon: UIImage {
return UIImage.gridicon(.ellipsis)
}
// MARK: - IBOutlets
@IBOutlet fileprivate var iconBackgroundImageView: CircularImageView!
@IBOutlet fileprivate var iconImageView: UIImageView!
@IBOutlet fileprivate var contentLabel: UILabel!
@IBOutlet fileprivate var summaryLabel: UILabel!
@IBOutlet fileprivate var actionButtonContainer: UIView!
@IBOutlet fileprivate var actionButton: UIButton!
}
open class RewindStatusTableViewCell: ActivityTableViewCell {
@IBOutlet private var progressView: UIProgressView!
private(set) var title = ""
private(set) var summary = ""
private(set) var progress: Float = 0.0
open func configureCell(title: String,
summary: String,
progress: Float) {
self.title = title
self.summary = summary
self.progress = progress
contentLabel.text = title
summaryLabel.text = summary
iconBackgroundImageView.backgroundColor = .primary
iconImageView.image = UIImage.gridicon(.noticeOutline).imageWithTintColor(.white)
iconImageView.isHidden = false
actionButtonContainer.isHidden = true
progressView.progressTintColor = .primary
progressView.trackTintColor = UIColor(light: (.primary(.shade5)), dark: (.primary(.shade80)))
progressView.setProgress(progress, animated: true)
}
}