Skip to content

Commit 5f4e769

Browse files
authored
Merge pull request #18513 from wordpress-mobile/feature/18502-prompt_table_cell
Blogging Prompts List: prompt table cell
2 parents 59f951a + 27a7de9 commit 5f4e769

File tree

5 files changed

+205
-5
lines changed

5 files changed

+205
-5
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
class BloggingPromptTableViewCell: UITableViewCell, NibReusable {
2+
3+
// MARK: - Properties
4+
5+
@IBOutlet private weak var titleLabel: UILabel!
6+
@IBOutlet private weak var dateLabel: UILabel!
7+
@IBOutlet private weak var dateToAnswersSeparatorDot: UILabel!
8+
@IBOutlet private weak var answerCountLabel: UILabel!
9+
10+
@IBOutlet private weak var answeredStateView: UIView!
11+
@IBOutlet private weak var answersToStateSeparatorDot: UILabel!
12+
@IBOutlet private weak var answeredStateLabel: UILabel!
13+
14+
private var prompt: BloggingPrompt?
15+
16+
private let dateFormatter: DateFormatter = {
17+
let formatter = DateFormatter()
18+
formatter.setLocalizedDateFormatFromTemplate("MMM d, yyyy")
19+
return formatter
20+
}()
21+
22+
23+
// MARK: Init
24+
25+
override func awakeFromNib() {
26+
super.awakeFromNib()
27+
configureView()
28+
}
29+
30+
// TODO: remove answered param. Add BloggingPrompt, configure with its properties.
31+
func configure(answered: Bool) {
32+
titleLabel.text = "Cast the movie of your life."
33+
dateLabel.text = dateFormatter.string(from: Date())
34+
answerCountLabel.text = answerInfoText
35+
answeredStateView.isHidden = !answered
36+
}
37+
}
38+
39+
private extension BloggingPromptTableViewCell {
40+
41+
func configureView() {
42+
titleLabel.textColor = .text
43+
titleLabel.font = WPStyleGuide.notoBoldFontForTextStyle(.headline)
44+
45+
dateLabel.textColor = .text
46+
dateToAnswersSeparatorDot.textColor = .text
47+
answerCountLabel.textColor = .text
48+
answersToStateSeparatorDot.textColor = .text
49+
50+
answeredStateLabel.text = Strings.answeredLabel
51+
answeredStateLabel.textColor = WPStyleGuide.BloggingPrompts.answeredLabelColor
52+
}
53+
54+
var answerInfoText: String {
55+
// TODO: remove when we have a prompt.
56+
guard let answerCount = prompt?.answerCount else {
57+
return "99 answers"
58+
}
59+
60+
let stringFormat = (answerCount == 1 ? Strings.answerInfoSingularFormat : Strings.answerInfoPluralFormat)
61+
return String(format: stringFormat, answerCount)
62+
}
63+
64+
enum Strings {
65+
static let answeredLabel = NSLocalizedString("✓ Answered", comment: "Label that indicates a blogging prompt has been answered.")
66+
static let answerInfoSingularFormat = NSLocalizedString("%1$d answer", comment: "Singular format string for displaying the number of users that answered the blogging prompt.")
67+
static let answerInfoPluralFormat = NSLocalizedString("%1$d answers", comment: "Plural format string for displaying the number of users that answered the blogging prompt.")
68+
}
69+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
7+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<objects>
11+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
12+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13+
<tableViewCell contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="BloggingPromptTableViewCell" customModule="WordPress" customModuleProvider="target">
14+
<rect key="frame" x="0.0" y="0.0" width="368" height="67"/>
15+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
17+
<rect key="frame" x="0.0" y="0.0" width="368" height="67"/>
18+
<autoresizingMask key="autoresizingMask"/>
19+
<subviews>
20+
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9EJ-O9-rUs" userLabel="Title Label">
21+
<rect key="frame" x="16" y="10" width="336" height="17"/>
22+
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
23+
<nil key="highlightedColor"/>
24+
</label>
25+
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="NgJ-e1-8mj" userLabel="Prompt Information Stack View">
26+
<rect key="frame" x="16" y="29" width="336" height="28"/>
27+
<subviews>
28+
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Date" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ing-nT-4vc" userLabel="Date Label">
29+
<rect key="frame" x="0.0" y="0.0" width="26.5" height="28"/>
30+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
31+
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
32+
<nil key="highlightedColor"/>
33+
</label>
34+
<label userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="·" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hFE-3l-xA6" userLabel="Separator Dot">
35+
<rect key="frame" x="32.5" y="0.0" width="4" height="28"/>
36+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
37+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
38+
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
39+
<nil key="highlightedColor"/>
40+
</label>
41+
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="99 answers" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZmC-VB-tZs" userLabel="Answer Count Label">
42+
<rect key="frame" x="42.5" y="0.0" width="65.5" height="28"/>
43+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
44+
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
45+
<nil key="highlightedColor"/>
46+
</label>
47+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hLQ-2r-lrL" userLabel="Answered State View">
48+
<rect key="frame" x="114" y="0.0" width="222" height="28"/>
49+
<subviews>
50+
<label userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="·" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jxn-g5-OtR" userLabel="Separator Dot">
51+
<rect key="frame" x="0.0" y="7" width="4" height="14.5"/>
52+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
53+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
54+
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
55+
<nil key="highlightedColor"/>
56+
</label>
57+
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Answered" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MGq-ZW-fgb" userLabel="Answered State Label">
58+
<rect key="frame" x="10" y="0.0" width="212" height="28"/>
59+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
60+
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
61+
<nil key="highlightedColor"/>
62+
</label>
63+
</subviews>
64+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
65+
<constraints>
66+
<constraint firstAttribute="trailing" secondItem="MGq-ZW-fgb" secondAttribute="trailing" id="68Y-Hc-DBg"/>
67+
<constraint firstItem="Jxn-g5-OtR" firstAttribute="leading" secondItem="hLQ-2r-lrL" secondAttribute="leading" id="Lmu-jA-SLi"/>
68+
<constraint firstItem="Jxn-g5-OtR" firstAttribute="centerY" secondItem="hLQ-2r-lrL" secondAttribute="centerY" id="MLC-DG-Tty"/>
69+
<constraint firstAttribute="bottom" secondItem="MGq-ZW-fgb" secondAttribute="bottom" id="RCv-zG-krh"/>
70+
<constraint firstItem="MGq-ZW-fgb" firstAttribute="leading" secondItem="Jxn-g5-OtR" secondAttribute="trailing" constant="6" id="bmL-rU-ENh"/>
71+
<constraint firstItem="MGq-ZW-fgb" firstAttribute="top" secondItem="hLQ-2r-lrL" secondAttribute="top" id="i79-0y-a1t"/>
72+
</constraints>
73+
</view>
74+
</subviews>
75+
</stackView>
76+
</subviews>
77+
<constraints>
78+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="NgJ-e1-8mj" secondAttribute="trailing" constant="16" id="NLC-oa-eTa"/>
79+
<constraint firstAttribute="bottom" secondItem="NgJ-e1-8mj" secondAttribute="bottom" constant="10" id="XDv-Bx-crE"/>
80+
<constraint firstAttribute="trailing" secondItem="9EJ-O9-rUs" secondAttribute="trailing" constant="16" id="adH-Dv-Kxj"/>
81+
<constraint firstItem="9EJ-O9-rUs" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="mxH-wp-psh"/>
82+
<constraint firstItem="NgJ-e1-8mj" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="rC4-OZ-GzD"/>
83+
<constraint firstItem="NgJ-e1-8mj" firstAttribute="top" secondItem="9EJ-O9-rUs" secondAttribute="bottom" constant="2" id="rJj-cx-ri9"/>
84+
<constraint firstItem="9EJ-O9-rUs" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="xlc-gR-Yni"/>
85+
</constraints>
86+
</tableViewCellContentView>
87+
<connections>
88+
<outlet property="answerCountLabel" destination="ZmC-VB-tZs" id="ES1-HG-7ps"/>
89+
<outlet property="answeredStateLabel" destination="MGq-ZW-fgb" id="IMd-4Q-u2x"/>
90+
<outlet property="answeredStateView" destination="hLQ-2r-lrL" id="tbz-zi-842"/>
91+
<outlet property="answersToStateSeparatorDot" destination="Jxn-g5-OtR" id="bzX-TR-0Yy"/>
92+
<outlet property="dateLabel" destination="ing-nT-4vc" id="V1i-lL-LCF"/>
93+
<outlet property="dateToAnswersSeparatorDot" destination="hFE-3l-xA6" id="cbF-I5-1OK"/>
94+
<outlet property="titleLabel" destination="9EJ-O9-rUs" id="FHY-7V-WNQ"/>
95+
</connections>
96+
<point key="canvasLocation" x="198.55072463768118" y="133.59375"/>
97+
</tableViewCell>
98+
</objects>
99+
<resources>
100+
<systemColor name="systemBackgroundColor">
101+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
102+
</systemColor>
103+
</resources>
104+
</document>

WordPress/Classes/ViewRelated/Blog/Blogging Prompts/BloggingPromptsViewController.storyboard

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
<constraint firstAttribute="height" constant="46" id="mN2-YL-PRM"/>
2828
</constraints>
2929
</view>
30-
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="7aR-Vp-g6a">
30+
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="7aR-Vp-g6a">
3131
<rect key="frame" x="0.0" y="46" width="375" height="621"/>
3232
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
33+
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
3334
<connections>
3435
<outlet property="dataSource" destination="cBt-Sc-5RS" id="ACo-bR-be2"/>
3536
<outlet property="delegate" destination="cBt-Sc-5RS" id="hKz-4a-sNu"/>

WordPress/Classes/ViewRelated/Blog/Blogging Prompts/BloggingPromptsViewController.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ class BloggingPromptsViewController: UIViewController {
2929
super.viewDidLoad()
3030
title = Strings.viewTitle
3131
configureFilterTabBar()
32+
configureTableView()
3233
}
3334

3435
}
3536

36-
// MARK: - Private Helpers
37+
// MARK: - Private Methods
3738

3839
private extension BloggingPromptsViewController {
3940

41+
func configureTableView() {
42+
tableView.register(BloggingPromptTableViewCell.defaultNib,
43+
forCellReuseIdentifier: BloggingPromptTableViewCell.defaultReuseID)
44+
45+
tableView.accessibilityIdentifier = "Blogging Prompts List"
46+
WPStyleGuide.configureAutomaticHeightRows(for: tableView)
47+
WPStyleGuide.configureColors(view: view, tableView: tableView)
48+
}
49+
4050
enum Strings {
4151
static let viewTitle = NSLocalizedString("Prompts", comment: "View title for Blogging Prompts list.")
42-
4352
}
4453

4554
}
@@ -54,8 +63,13 @@ extension BloggingPromptsViewController: UITableViewDataSource, UITableViewDeleg
5463
}
5564

5665
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
57-
// TODO: use custom prompt cell.
58-
return UITableViewCell()
66+
guard let cell = tableView.dequeueReusableCell(withIdentifier: BloggingPromptTableViewCell.defaultReuseID) as? BloggingPromptTableViewCell else {
67+
return UITableViewCell()
68+
}
69+
70+
// TODO: replace answered with BloggingPrompt.
71+
cell.configure(answered: indexPath.row > 4)
72+
return cell
5973
}
6074

6175
}

0 commit comments

Comments
 (0)