From 77ba42f102031e2f2e68856ff2a82974c461bed9 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 30 Sep 2019 20:01:02 -0500 Subject: [PATCH] Add unread count to the timeline --- NetNewsWire.xcodeproj/project.pbxproj | 4 +++ .../Cell/MasterFeedUnreadCountView.swift | 23 +++++++----- .../MasterTimelineTitleView.swift | 1 + .../MasterTimelineTitleView.xib | 13 +++++-- .../MasterTimelineUnreadCountView.swift | 35 +++++++++++++++++++ .../MasterTimelineViewController.swift | 10 +++++- 6 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 iOS/MasterTimeline/MasterTimelineUnreadCountView.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index f3789f111..9b35dae91 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -217,6 +217,7 @@ 51FA73AB2332C2FD0090D516 /* ArticleExtractorConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FA73A92332C2FD0090D516 /* ArticleExtractorConfig.swift */; }; 51FA73B72332D5F70090D516 /* ArticleExtractorButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FA73B62332D5F70090D516 /* ArticleExtractorButton.swift */; }; 51FD40C72341555A00880194 /* UIImage-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FD40BD2341555600880194 /* UIImage-Extensions.swift */; }; + 51FD413B2342BD0500880194 /* MasterTimelineUnreadCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FD413A2342BD0500880194 /* MasterTimelineUnreadCountView.swift */; }; 55E15BCB229D65A900D6602A /* AccountsReaderAPI.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */; }; 55E15BCC229D65A900D6602A /* AccountsReaderAPIWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */; }; 5F323809231DF9F000706F6B /* NNWTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F323808231DF9F000706F6B /* NNWTableViewCell.swift */; }; @@ -897,6 +898,7 @@ 51FA73A92332C2FD0090D516 /* ArticleExtractorConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleExtractorConfig.swift; sourceTree = ""; }; 51FA73B62332D5F70090D516 /* ArticleExtractorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleExtractorButton.swift; sourceTree = ""; }; 51FD40BD2341555600880194 /* UIImage-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage-Extensions.swift"; sourceTree = ""; }; + 51FD413A2342BD0500880194 /* MasterTimelineUnreadCountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterTimelineUnreadCountView.swift; sourceTree = ""; }; 557EE1A522B6F4E1004206FA /* SettingsReaderAPIAccountView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsReaderAPIAccountView.swift; sourceTree = ""; }; 55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsReaderAPI.xib; sourceTree = ""; }; 55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsReaderAPIWindowController.swift; sourceTree = ""; }; @@ -1369,6 +1371,7 @@ 51D6A5BB23199C85001C27D8 /* MasterTimelineDataSource.swift */, 5148F4542336DB7000F8CD8B /* MasterTimelineTitleView.swift */, 5148F44A2336DB4700F8CD8B /* MasterTimelineTitleView.xib */, + 51FD413A2342BD0500880194 /* MasterTimelineUnreadCountView.swift */, 51C4526F2265091600C03939 /* Cell */, ); path = MasterTimeline; @@ -2791,6 +2794,7 @@ 517630232336657E00E15FFF /* ArticleViewControllerWebViewProvider.swift in Sources */, 51C4528F226509BD00C03939 /* UnreadFeed.swift in Sources */, 51AF460E232488C6001742EF /* Account-Extensions.swift in Sources */, + 51FD413B2342BD0500880194 /* MasterTimelineUnreadCountView.swift in Sources */, 5183CCDD226F1F5C0010922C /* NavigationProgressView.swift in Sources */, 51AF45E123246731001742EF /* SettingsAccountLabelView.swift in Sources */, 51D87EE12311D34700E63F03 /* ActivityType.swift in Sources */, diff --git a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift index fdddb629a..09b1d5d69 100644 --- a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift +++ b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift @@ -10,19 +10,26 @@ import UIKit class MasterFeedUnreadCountView : UIView { - private let padding = UIEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0) - private let cornerRadius = 8.0 - private let bgColor = UIColor.darkGray - private let textColor = UIColor.white - private var textAttributes: [NSAttributedString.Key: AnyObject] { + var padding: UIEdgeInsets { + return UIEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0) + } + + let cornerRadius = 8.0 + let bgColor = UIColor.darkGray + var textColor: UIColor { + return UIColor.white + } + + var textAttributes: [NSAttributedString.Key: AnyObject] { let textFont = UIFont.preferredFont(forTextStyle: .caption1) return [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] } - private var textSizeCache = [Int: CGSize]() + var textSizeCache = [Int: CGSize]() var unreadCount = 0 { didSet { contentSizeIsValid = false + invalidateIntrinsicContentSize() setNeedsDisplay() } } @@ -69,7 +76,7 @@ class MasterFeedUnreadCountView : UIView { return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric) } - private func textSize() -> CGSize { + func textSize() -> CGSize { if unreadCount < 1 { return CGSize.zero @@ -88,7 +95,7 @@ class MasterFeedUnreadCountView : UIView { } - private func textRect() -> CGRect { + func textRect() -> CGRect { let size = textSize() var r = CGRect.zero diff --git a/iOS/MasterTimeline/MasterTimelineTitleView.swift b/iOS/MasterTimeline/MasterTimelineTitleView.swift index 2861ce634..03e68a1af 100644 --- a/iOS/MasterTimeline/MasterTimelineTitleView.swift +++ b/iOS/MasterTimeline/MasterTimelineTitleView.swift @@ -20,5 +20,6 @@ class MasterTimelineTitleView: UIView { } @IBOutlet weak var label: UILabel! + @IBOutlet weak var unreadCountView: MasterTimelineUnreadCountView! } diff --git a/iOS/MasterTimeline/MasterTimelineTitleView.xib b/iOS/MasterTimeline/MasterTimelineTitleView.xib index 5abe26c5a..ad66ffdef 100644 --- a/iOS/MasterTimeline/MasterTimelineTitleView.xib +++ b/iOS/MasterTimeline/MasterTimelineTitleView.xib @@ -20,20 +20,26 @@ -