Skip to content

Commit 436f005

Browse files
authored
Merge pull request #18574 from wordpress-mobile/feature/18558-prompt-attribution-dashboard-card
Blogging Prompts: Add blogging prompts attribution to prompts dashboard card
2 parents 5a389ff + 760e576 commit 436f005

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
@@ -96,7 +96,7 @@ struct BloggingPrompt {
9696
answered: false,
9797
answerCount: 5,
9898
displayAvatarURLs: [],
99-
attribution: ""
99+
attribution: "dayone"
100100
)
101101
}
102102

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 %1$@", comment: "Format for blogging prompts attribution. %1$@ is the attribution source.")
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
@@ -1415,6 +1415,8 @@
14151415
8370D10A11FA499A009D650F /* WPTableViewActivityCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8370D10911FA499A009D650F /* WPTableViewActivityCell.m */; };
14161416
839B150B2795DEE0009F5E77 /* UIView+Margins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B150A2795DEE0009F5E77 /* UIView+Margins.swift */; };
14171417
839B150C2795DEE0009F5E77 /* UIView+Margins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B150A2795DEE0009F5E77 /* UIView+Margins.swift */; };
1418+
83B1D037282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */; };
1419+
83B1D038282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */; };
14181420
83C972E0281C45AB0049E1FE /* Post+BloggingPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */; };
14191421
83C972E1281C45AB0049E1FE /* Post+BloggingPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */; };
14201422
83F3E26011275E07004CD686 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83F3E25F11275E07004CD686 /* MapKit.framework */; };
@@ -6200,6 +6202,7 @@
62006202
8370D10811FA499A009D650F /* WPTableViewActivityCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WPTableViewActivityCell.h; sourceTree = "<group>"; };
62016203
8370D10911FA499A009D650F /* WPTableViewActivityCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPTableViewActivityCell.m; sourceTree = "<group>"; };
62026204
839B150A2795DEE0009F5E77 /* UIView+Margins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Margins.swift"; sourceTree = "<group>"; };
6205+
83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BloggingPromptsAttribution.swift; sourceTree = "<group>"; };
62036206
83C972DF281C45AB0049E1FE /* Post+BloggingPrompts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Post+BloggingPrompts.swift"; sourceTree = "<group>"; };
62046207
83F3E25F11275E07004CD686 /* MapKit.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
62056208
83F3E2D211276371004CD686 /* CoreLocation.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
@@ -15242,8 +15245,9 @@
1524215245
FE18495627F5ACA400D26879 /* Prompts */ = {
1524315246
isa = PBXGroup;
1524415247
children = (
15245-
FE18495727F5ACBA00D26879 /* DashboardPromptsCardCell.swift */,
1524615248
FEAC916D28001FC4005026E7 /* AvatarTrainView.swift */,
15249+
83B1D036282C62620061D911 /* BloggingPromptsAttribution.swift */,
15250+
FE18495727F5ACBA00D26879 /* DashboardPromptsCardCell.swift */,
1524715251
);
1524815252
path = Prompts;
1524915253
sourceTree = "<group>";
@@ -18967,6 +18971,7 @@
1896718971
E125F1E41E8E595E00320B67 /* SharePost.swift in Sources */,
1896818972
B56FEB791CD8E13C00E621F9 /* RoleViewController.swift in Sources */,
1896918973
D82253DC2199411F0014D0E2 /* SiteAddressService.swift in Sources */,
18974+
83B1D037282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */,
1897018975
B5B56D3319AFB68800B4E29B /* WPStyleGuide+Notifications.swift in Sources */,
1897118976
FF8DDCDF1B5DB1C10098826F /* SettingTableViewCell.m in Sources */,
1897218977
9A3BDA0E22944F3500FBF510 /* CountriesMapView.swift in Sources */,
@@ -20309,6 +20314,7 @@
2030920314
8B45C12727B2B08900EA3257 /* DashboardStatsCardCell.swift in Sources */,
2031020315
FABB21E02602FC2C00C8785C /* SupportTableViewController.swift in Sources */,
2031120316
FABB21E12602FC2C00C8785C /* DetailDataCell.swift in Sources */,
20317+
83B1D038282C62620061D911 /* BloggingPromptsAttribution.swift in Sources */,
2031220318
C7F7AC75261CF1F300CE547F /* JetpackLoginErrorViewController.swift in Sources */,
2031320319
FABB21E22602FC2C00C8785C /* PluginViewModel.swift in Sources */,
2031420320
FABB21E32602FC2C00C8785C /* NSCalendar+Helpers.swift in Sources */,

0 commit comments

Comments
 (0)