Skip to content

Commit d4bbdf3

Browse files
authored
Merge pull request #477 from woocommerce/issue/19-ratings
Notifications: Adds star rating to product review cell/detail
2 parents 55198e8 + 666d85d commit d4bbdf3

File tree

11 files changed

+436
-116
lines changed

11 files changed

+436
-116
lines changed

Podfile.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ PODS:
1414
- CocoaLumberjack/Default (3.4.2)
1515
- CocoaLumberjack/Extensions (3.4.2):
1616
- CocoaLumberjack/Default
17-
- Crashlytics (3.11.1):
18-
- Fabric (~> 1.8.1)
19-
- Fabric (1.8.2)
17+
- Crashlytics (3.12.0):
18+
- Fabric (~> 1.9.0)
19+
- Fabric (1.9.0)
2020
- FormatterKit/Resources (1.8.2)
2121
- FormatterKit/TimeIntervalFormatter (1.8.2):
2222
- FormatterKit/Resources
@@ -39,7 +39,7 @@ PODS:
3939
- Reachability (3.2)
4040
- SVProgressHUD (2.2.5)
4141
- UIDeviceIdentifier (0.5.0)
42-
- WordPressAuthenticator (1.1.5):
42+
- WordPressAuthenticator (1.1.6):
4343
- 1PasswordExtension (= 1.8.5)
4444
- Alamofire (= 4.7.3)
4545
- CocoaLumberjack (= 3.4.2)
@@ -60,7 +60,7 @@ PODS:
6060
- UIDeviceIdentifier (~> 0.4)
6161
- WordPressShared (~> 1.4)
6262
- wpxmlrpc (= 0.8.3)
63-
- WordPressShared (1.5.1):
63+
- WordPressShared (1.6.0):
6464
- CocoaLumberjack (~> 3.4)
6565
- FormatterKit/TimeIntervalFormatter (= 1.8.2)
6666
- WordPressUI (1.1.1)
@@ -133,8 +133,8 @@ SPEC CHECKSUMS:
133133
Automattic-Tracks-iOS: 93f967b0ca5d7cba176366847e0f29debc339a04
134134
Charts: f122fb70b19847fa5817d018b77d6c5a2296ab25
135135
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
136-
Crashlytics: ca7ab4bc304aa216bdc2e4c1a96389ee77252203
137-
Fabric: d2b22f443ba195d8a7cc204da230977c72733b40
136+
Crashlytics: 07fb167b1694128c1c9a5a5cc319b0e9c3ca0933
137+
Fabric: f988e33c97f08930a413e08123064d2e5f68d655
138138
FormatterKit: 4b8f29acc9b872d5d12a63efb560661e8f2e1b98
139139
GoogleSignInRepacked: d357702618c555f38923576924661325eb1ef22b
140140
GoogleToolboxForMac: 91c824d21e85b31c2aae9bb011c5027c9b4e738f
@@ -146,9 +146,9 @@ SPEC CHECKSUMS:
146146
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
147147
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
148148
UIDeviceIdentifier: a959a6d4f51036b4180dd31fb26483a820f1cc46
149-
WordPressAuthenticator: 0e60d89e1637212bc841a0cf66fc5ef8cac01e52
149+
WordPressAuthenticator: 83f495cce863d3f65bb440f6dea57161af401729
150150
WordPressKit: 46fe8a4fa2ff4195f73a992f0f6f3a1eb2972b70
151-
WordPressShared: 2a2d74bbe0ee4c31452f8c33aafe255278dc56f6
151+
WordPressShared: a2fc2db66c210a05d317ae9678b5823dd6a4d708
152152
WordPressUI: 3c69543f0170e011226e48910b8c3071e5d400af
153153
wpxmlrpc: bfc572f62ce7ee897f6f38b098d2ba08732ecef4
154154
XLPagerTabStrip: 22d4c58200d7c105e0e407ab6bfd01a5d85014be

WooCommerce/Classes/Model/Note+Woo.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,27 @@ extension Note {
2121

2222
return snippet
2323
}
24+
25+
/// Returns the number of stars for a review (or nil if the Note is not a review)
26+
///
27+
var starRating: Int? {
28+
guard subkind == .storeReview else {
29+
return nil
30+
}
31+
guard let block = body.first(ofKind: .text) else {
32+
return nil
33+
}
34+
35+
return block.text?.filter({ Constants.filledInStar.contains($0) }).count
36+
}
37+
}
38+
39+
40+
// MARK: - Constants!
41+
//
42+
private extension Note {
43+
enum Constants {
44+
static let filledInStar = "\u{2605}" // Unicode Black Star ★
45+
static let emptyStar = "\u{2606}" // Unicode White Star ☆
46+
}
2447
}

WooCommerce/Classes/Styles/Style.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protocol Style {
3737
var statusSuccessColor: UIColor { get }
3838
var statusSuccessBoldColor: UIColor { get }
3939
var tableViewBackgroundColor: UIColor { get }
40+
var goldStarColor: UIColor { get }
4041
var wooCommerceBrandColor: UIColor { get }
4142
var wooAccent: UIColor { get }
4243
var wooGreyLight: UIColor { get }
@@ -85,6 +86,7 @@ class DefaultStyle: Style {
8586
let sectionBackgroundColor = HandbookColors.wooGreyLight
8687
let sectionTitleColor = HandbookColors.wooSecondary
8788
let tableViewBackgroundColor = HandbookColors.wooGreyLight
89+
let goldStarColor = UIColor(red: 238.0/255.0, green: 180.0/255.0, blue: 34.0/255.0, alpha: 1.0)
8890

8991
let statusDangerColor = HandbookColors.statusRedDimmed
9092
let statusDangerBoldColor = HandbookColors.statusRed
@@ -266,6 +268,10 @@ class StyleManager {
266268
return active.statusSuccessBoldColor
267269
}
268270

271+
static var goldStarColor: UIColor {
272+
return active.goldStarColor
273+
}
274+
269275
static var tableViewBackgroundColor: UIColor {
270276
return active.tableViewBackgroundColor
271277
}

WooCommerce/Classes/ViewRelated/Notifications/Cells/NoteDetailsCommentTableViewCell.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class NoteDetailsCommentTableViewCell: UITableViewCell {
3636
///
3737
@IBOutlet private var approvalButton: UIButton!
3838

39+
/// Custom UIView: Rating star view
40+
///
41+
@IBOutlet private var starRatingView: RatingView!
42+
3943
/// Closure to be executed whenever the Spam Button is pressed.
4044
///
4145
var onSpam: (() -> Void)?
@@ -132,6 +136,20 @@ class NoteDetailsCommentTableViewCell: UITableViewCell {
132136
}
133137
}
134138

139+
/// Star rating value (if nil, star rating view will be hidden)
140+
///
141+
var starRating: Int? {
142+
didSet {
143+
guard let starRating = starRating else {
144+
starRatingView.isHidden = true
145+
return
146+
}
147+
148+
starRatingView.rating = CGFloat(starRating)
149+
starRatingView.isHidden = false
150+
}
151+
}
152+
135153
/// Downloads the Gravatar Image at the specified URL (if any!).
136154
///
137155
func downloadGravatar(with url: URL?) {
@@ -145,6 +163,7 @@ class NoteDetailsCommentTableViewCell: UITableViewCell {
145163
override func awakeFromNib() {
146164
super.awakeFromNib()
147165
configureActionButtons()
166+
configureStarView()
148167
configureDefaultAppearance()
149168
}
150169
}
@@ -187,6 +206,14 @@ private extension NoteDetailsCommentTableViewCell {
187206
}
188207
}
189208

209+
/// Setup: Star rating view
210+
///
211+
func configureStarView() {
212+
starRatingView.starImage = Star.filledImage
213+
starRatingView.emptyStarImage = Star.emptyImage
214+
starRatingView.isHidden = (starRating == nil)
215+
}
216+
190217
/// Setup: Button Appearance
191218
///
192219
func refreshAppearance(button: UIButton) {
@@ -262,3 +289,12 @@ private struct Approve {
262289
static let normalLabel = NSLocalizedString("Approves the comment", comment: "Approves a comment. Spoken Hint.")
263290
static let selectedLabel = NSLocalizedString("Unapproves the comment", comment: "Unapproves a comment. Spoken Hint.")
264291
}
292+
293+
294+
// MARK: - Star View: Defaults
295+
//
296+
private struct Star {
297+
static let size = Double(18)
298+
static let filledImage = Gridicon.iconOfType(.star, withSize: CGSize(width: Star.size, height: Star.size)).imageWithTintColor(StyleManager.goldStarColor)
299+
static let emptyImage = Gridicon.iconOfType(.star, withSize: CGSize(width: Star.size, height: Star.size)).imageWithTintColor(StyleManager.wooGreyLight)
300+
}

0 commit comments

Comments
 (0)