@@ -71,7 +71,9 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
7171 private let activityIndicator = UIActivityIndicatorView ( style: . medium)
7272
7373 /// The actual header
74- private lazy var header = ReaderDetailHeaderHostingView ( )
74+ private lazy var header = ReaderPostHeaderView ( )
75+ private var cachedExcerpt : String ?
76+ private var cachedReadingTime : String ?
7577
7678 /// Bottom toolbar helper
7779 private lazy var toolbar = ReaderDetailToolbar ( )
@@ -251,7 +253,9 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
251253
252254 toolbar. configure ( for: post, in: self )
253255 updateToolbarItems ( )
254- header. configure ( for: post)
256+ cachedExcerpt = post. getUserProvidedExcerpt ( )
257+ cachedReadingTime = Self . readingTimeString ( for: post)
258+ configureHeaderView ( with: post)
255259 fetchLikes ( )
256260 fetchComments ( )
257261 checkTranslationAvailability ( )
@@ -401,7 +405,8 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
401405 }
402406
403407 func updateHeader( ) {
404- header. refreshFollowButton ( )
408+ guard let post else { return }
409+ header. subscribeButton. isHidden = post. isFollowing
405410 }
406411
407412 func updateLikesView( with viewModel: ReaderDetailLikesViewModel ) {
@@ -490,7 +495,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
490495 headerContainerView. backgroundColor = displaySetting. color. background
491496
492497 // Header view
493- header. displaySetting = displaySetting
498+ header. apply ( displaySetting)
494499 }
495500
496501 // Update Reader Post web view
@@ -549,14 +554,39 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
549554 }
550555
551556 private func configureHeader( ) {
552- header. displaySetting = displaySetting
557+ header. apply ( displaySetting)
553558 header. delegate = coordinator
559+ header. translatesAutoresizingMaskIntoConstraints = false
554560 headerContainerView. addSubview ( header)
555- headerContainerView. translatesAutoresizingMaskIntoConstraints = false
556-
557561 headerContainerView. pinSubviewToAllEdges ( header)
558562 }
559563
564+ private func configureHeaderView( with post: ReaderPost , customTitle: String ? = nil ) {
565+ let featuredImageURL : URL ? = post. contentIncludesFeaturedImage ( ) ? nil : post. featuredImageURLForDisplay ( )
566+ header. configure ( with: ReaderPostHeaderView . ViewModel (
567+ siteName: post. blogNameForDisplay ( ) ,
568+ postTitle: customTitle ?? post. titleForDisplay ( ) ,
569+ authorName: post. authorForDisplay ( ) ?? " " ,
570+ authorAvatarURL: post. avatarURLForDisplay ( ) ,
571+ dateString: post. dateForDisplay ( ) ? . toMediumString ( ) ?? " " ,
572+ featuredImageURL: featuredImageURL,
573+ excerpt: cachedExcerpt,
574+ readingTime: cachedReadingTime ?? " "
575+ ) )
576+ header. subscribeButton. isHidden = post. isFollowing
577+ }
578+
579+ private static func readingTimeString( for post: ReaderPost ) -> String {
580+ String . localizedStringWithFormat (
581+ NSLocalizedString (
582+ " reader.detail.header.readingTime " ,
583+ value: " %1$d min read " ,
584+ comment: " Estimated reading time for the post. %1$d is the number of minutes. "
585+ ) ,
586+ max ( 1 , post. getEstimatedReadingTime ( ) )
587+ )
588+ }
589+
560590 private func fetchLikes( ) {
561591 guard let post else {
562592 return
@@ -687,7 +717,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
687717 blurView. removeFromSuperview ( )
688718 }
689719
690- header . configure ( for : post, title : translationResults [ 0 ] )
720+ configureHeaderView ( with : post, customTitle : translationResults [ 0 ] )
691721 do {
692722 try await webView. setBodyHTML ( translationResults [ 1 ] )
693723 } catch {
@@ -897,7 +927,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
897927 let refreshed = notification. userInfo ? [ NSRefreshedObjectsKey] as? Set < NSManagedObject > ?? Set ( )
898928
899929 if updated. contains ( post) || refreshed. contains ( post) {
900- header . configure ( for : post)
930+ configureHeaderView ( with : post)
901931 }
902932 }
903933}
0 commit comments