Skip to content

Commit 1fa1b67

Browse files
committed
Add blogging prompts attribution to prompts dashboard card
See: #18558
1 parent 63f01a7 commit 1fa1b67

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

WordPress/Classes/Services/BloggingPromptsService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct BloggingPrompt {
8484
answered: false,
8585
answerCount: 5,
8686
displayAvatarURLs: [],
87-
attribution: ""
87+
attribution: "dayone"
8888
)
8989
}
9090

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
enum BloggingPromptsAttribution: String {
2+
case dayone
3+
4+
var attributedText: NSAttributedString {
5+
let baseText = String(format: Strings.fromTextFormat, source)
6+
let attributedText = NSMutableAttributedString(string: baseText, attributes: Constants.baseAttributes)
7+
guard let range = baseText.range(of: source) else {
8+
return attributedText
9+
}
10+
attributedText.addAttributes(Constants.sourceAttributes, range: NSRange(range, in: baseText))
11+
12+
return attributedText
13+
}
14+
15+
var source: String {
16+
switch self {
17+
case .dayone: return Strings.dayOne
18+
}
19+
}
20+
21+
var iconImage: UIImage? {
22+
switch self {
23+
case .dayone: return Constants.dayOneIcon
24+
}
25+
}
26+
27+
private struct Strings {
28+
static let fromTextFormat = NSLocalizedString("From %@", comment: "From string format for blogging prompts attribution")
29+
static let dayOne = "Day One"
30+
}
31+
32+
private struct Constants {
33+
static let baseAttributes: [NSAttributedString.Key: Any] = [
34+
.font: WPStyleGuide.fontForTextStyle(.caption1),
35+
.foregroundColor: UIColor.secondaryLabel,
36+
]
37+
static let sourceAttributes: [NSAttributedString.Key: Any] = [
38+
.font: WPStyleGuide.fontForTextStyle(.caption1, fontWeight: .medium),
39+
.foregroundColor: UIColor.text,
40+
]
41+
static let iconSize = CGSize(width: 18, height: 18)
42+
static let dayOneIcon = UIImage(named: "logo-dayone")?.resizedImage(Constants.iconSize, interpolationQuality: .default)
43+
}
44+
}

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Prompts/DashboardPromptsCardCell.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
8181
private lazy var containerStackView: UIStackView = {
8282
let stackView = UIStackView()
8383
stackView.axis = .vertical
84+
stackView.alignment = .center
8485
stackView.translatesAutoresizingMaskIntoConstraints = false
8586
stackView.spacing = Constants.spacing
8687
return stackView
@@ -188,6 +189,20 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
188189
return containerView
189190
}
190191

192+
private lazy var attributionIcon = UIImageView()
193+
194+
private lazy var attributionSourceLabel: UILabel = {
195+
let label = UILabel()
196+
label.adjustsFontForContentSizeCategory = true
197+
return label
198+
}()
199+
200+
private lazy var attributionStackView: UIStackView = {
201+
let stackView = UIStackView(arrangedSubviews: [attributionIcon, attributionSourceLabel])
202+
stackView.alignment = .center
203+
return stackView
204+
}()
205+
191206
// MARK: Bottom row views
192207

193208
private lazy var answerButton: UIButton = {
@@ -337,6 +352,13 @@ private extension DashboardPromptsCardCell {
337352
promptLabel.text = forExampleDisplay ? Strings.examplePrompt : prompt?.text.stringByDecodingXMLCharacters().trim()
338353
containerStackView.addArrangedSubview(promptTitleView)
339354

355+
if let promptAttribution = prompt?.attribution.lowercased(),
356+
let attribution = BloggingPromptsAttribution(rawValue: promptAttribution) {
357+
attributionIcon.image = attribution.iconImage
358+
attributionSourceLabel.attributedText = attribution.attributedText
359+
containerStackView.addArrangedSubview(attributionStackView)
360+
}
361+
340362
if answerCount > 0 {
341363
containerStackView.addArrangedSubview(answerInfoView)
342364
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "logo-dayone.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true
14+
}
15+
}
Binary file not shown.

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@
14121412
8370D10A11FA499A009D650F /* WPTableViewActivityCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8370D10911FA499A009D650F /* WPTableViewActivityCell.m */; };
14131413
839B150B2795DEE0009F5E77 /* UIView+Margins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B150A2795DEE0009F5E77 /* UIView+Margins.swift */; };
14141414
839B150C2795DEE0009F5E77 /* UIView+Margins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B150A2795DEE0009F5E77 /* UIView+Margins.swift */; };
1415+
83B1D037282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */; };
1416+
83B1D038282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */; };
14151417
83C972E0281C45AB0049E1FE /* Post+BloggingPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */; };
14161418
83C972E1281C45AB0049E1FE /* Post+BloggingPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */; };
14171419
83F3E26011275E07004CD686 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83F3E25F11275E07004CD686 /* MapKit.framework */; };
@@ -6196,6 +6198,7 @@
61966198
8370D10811FA499A009D650F /* WPTableViewActivityCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WPTableViewActivityCell.h; sourceTree = "<group>"; };
61976199
8370D10911FA499A009D650F /* WPTableViewActivityCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPTableViewActivityCell.m; sourceTree = "<group>"; };
61986200
839B150A2795DEE0009F5E77 /* UIView+Margins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Margins.swift"; sourceTree = "<group>"; };
6201+
83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BloggingPromptsAttribution.swift; sourceTree = "<group>"; };
61996202
83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Post+BloggingPrompts.swift"; sourceTree = "<group>"; };
62006203
83F3E25F11275E07004CD686 /* MapKit.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
62016204
83F3E2D211276371004CD686 /* CoreLocation.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
@@ -15240,8 +15243,9 @@
1524015243
FE18495627F5ACA400D26879 /* Prompts */ = {
1524115244
isa = PBXGroup;
1524215245
children = (
15243-
FE18495727F5ACBA00D26879 /* DashboardPromptsCardCell.swift */,
1524415246
FEAC916D28001FC4005026E7 /* AvatarTrainView.swift */,
15247+
83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */,
15248+
FE18495727F5ACBA00D26879 /* DashboardPromptsCardCell.swift */,
1524515249
);
1524615250
path = Prompts;
1524715251
sourceTree = "<group>";
@@ -18963,6 +18967,7 @@
1896318967
E125F1E41E8E595E00320B67 /* SharePost.swift in Sources */,
1896418968
B56FEB791CD8E13C00E621F9 /* RoleViewController.swift in Sources */,
1896518969
D82253DC2199411F0014D0E2 /* SiteAddressService.swift in Sources */,
18970+
83B1D037282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */,
1896618971
B5B56D3319AFB68800B4E29B /* WPStyleGuide+Notifications.swift in Sources */,
1896718972
FF8DDCDF1B5DB1C10098826F /* SettingTableViewCell.m in Sources */,
1896818973
9A3BDA0E22944F3500FBF510 /* CountriesMapView.swift in Sources */,
@@ -20306,6 +20311,7 @@
2030620311
8B45C12727B2B08900EA3257 /* DashboardStatsCardCell.swift in Sources */,
2030720312
FABB21E02602FC2C00C8785C /* SupportTableViewController.swift in Sources */,
2030820313
FABB21E12602FC2C00C8785C /* DetailDataCell.swift in Sources */,
20314+
83B1D038282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */,
2030920315
C7F7AC75261CF1F300CE547F /* JetpackLoginErrorViewController.swift in Sources */,
2031020316
FABB21E22602FC2C00C8785C /* PluginViewModel.swift in Sources */,
2031120317
FABB21E32602FC2C00C8785C /* NSCalendar+Helpers.swift in Sources */,

0 commit comments

Comments
 (0)