fix episode detail and add html labels
MODIFY
Podcast.xcodeproj/project.pbxproj
Podcast.xcodeproj/project.pbxproj
/* Begin PBXBuildFile section */
420BC2DE1E9C8E650096A9A0 /* EpisodeDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420BC2DD1E9C8E650096A9A0 /* EpisodeDetailViewController.swift */; };
- 420BC2E01E9D4B900096A9A0 /* EpisodeDetailHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderView.swift */; };
+ 420BC2E01E9D4B900096A9A0 /* EpisodeDetailHeaderViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderViewCell.swift */; };
421501271D9F5FE1002839D1 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421501261D9F5FE1002839D1 /* Player.swift */; };
422575171E9DEDE10071E419 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 422575161E9DEDE10071E419 /* Comment.swift */; };
422575191E9DF0260071E419 /* CommentsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 422575181E9DF0260071E419 /* CommentsTableViewCell.swift */; };
/* Begin PBXFileReference section */
420BC2DD1E9C8E650096A9A0 /* EpisodeDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EpisodeDetailViewController.swift; sourceTree = "<group>"; };
- 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EpisodeDetailHeaderView.swift; sourceTree = "<group>"; };
+ 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EpisodeDetailHeaderViewCell.swift; sourceTree = "<group>"; };
421501261D9F5FE1002839D1 /* Player.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = "<group>"; };
422575161E9DEDE10071E419 /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
422575181E9DF0260071E419 /* CommentsTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommentsTableViewCell.swift; sourceTree = "<group>"; };
D3B9A0591E861EB800B634FF /* ListeningHistoryTableViewCell.swift */,
44DA91CE1EA04D07001FE6AC /* PastSearchTableViewCell.swift */,
422575181E9DF0260071E419 /* CommentsTableViewCell.swift */,
+ 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderViewCell.swift */,
);
name = Cells;
sourceTree = "<group>";
FDE8D6EE1E6FC23000DF7548 /* InternalProfileHeaderView.swift */,
443ED30C1E745C5D001CFFF5 /* PlayButton.swift */,
D30D374A1E76082700E9260B /* TagTableViewHeader.swift */,
- 420BC2DF1E9D4B900096A9A0 /* EpisodeDetailHeaderView.swift */,
4225751A1E9E71630071E419 /* CommentsTableViewHeader.swift */,
);
name = Views;
443ED3051E6E3319001CFFF5 /* SearchPeopleTableViewCell.swift in Sources */,
443ED31B1E7D9BA0001CFFF5 /* SearchUsersEndpointRequest.swift in Sources */,
9522B0831E70ECE2009B5584 /* UIViewController+.swift in Sources */,
- 420BC2E01E9D4B900096A9A0 /* EpisodeDetailHeaderView.swift in Sources */,
+ 420BC2E01E9D4B900096A9A0 /* EpisodeDetailHeaderViewCell.swift in Sources */,
FD295FDD1E636A3D00520526 /* FillButton.swift in Sources */,
D3C31B4C1E6D28A00056E926 /* SubscriptionsViewController.swift in Sources */,
956D851C1E51942500D95F7A /* CMTime+.swift in Sources */,

MODIFY
Podcast/CommentsTableViewCell.swift
Podcast/CommentsTableViewCell.swift
@@ -14,7 +14,7 @@ protocol CommentsTableViewCellDelegate {
}
class CommentsTableViewCell: UITableViewCell {
- let minimumHeight: CGFloat = 200
+ static let minimumHeight: CGFloat = 95
let imageViewSize: CGSize = CGSize(width: 30, height: 30)
let marginSpacing: CGFloat = 18
let padding: CGFloat = 12
@@ -34,7 +34,8 @@ class CommentsTableViewCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = UIColor.colorFromCode(0xfcfcfe)
- frame.size.height = minimumHeight
+ selectionStyle = .none
+ frame.size.height = CommentsTableViewCell.minimumHeight
commenterImageView = UIImageView(frame: CGRect(origin: CGPoint.init(x: marginSpacing, y: marginSpacing), size: imageViewSize))
commenterImageView.layer.cornerRadius = imageViewSize.height/2

MODIFY
Podcast/CommentsTableViewHeader.swift
Podcast/CommentsTableViewHeader.swift
import UIKit
class CommentsTableViewHeader: UIView {
- let headerHeight: CGFloat = 48
+ static let headerHeight: CGFloat = 48
let commentsLabelXValue: CGFloat = 18
let commentsLabelYValue: CGFloat = 18
@@ -17,7 +17,7 @@ class CommentsTableViewHeader: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
- self.frame.size.height = headerHeight
+ self.frame.size.height = CommentsTableViewHeader.headerHeight
backgroundColor = UIColor.colorFromCode(0xf0f1f4)
commentsLabel = UILabel(frame: CGRect(x: commentsLabelXValue, y: commentsLabelYValue, width: 0, height: 0))

MODIFY
Podcast/Episode.swift
Podcast/Episode.swift
@@ -108,4 +108,15 @@ class Episode: NSObject {
return dateFormatter.string(from: dateCreated)
}
+ func attributedDescriptionString() -> NSAttributedString {
+ let modifiedFont = NSString(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 14\">%@</span>" as NSString, descriptionText) as String
+
+ let attrStr = try! NSAttributedString(
+ data: modifiedFont.data(using: .unicode, allowLossyConversion: true)!,
+ options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue],
+ documentAttributes: nil)
+
+ return attrStr
+ }
+
}

MODIFY
Podcast/EpisodeDetailViewController.swift
Podcast/EpisodeDetailViewController.swift
import UIKit
-class EpisodeDetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
- var scrollView: UIScrollView!
- var episodeDetailHeaderView: EpisodeDetailHeaderView!
+class EpisodeDetailViewController: UITableViewController, EpisodeDetailHeaderViewCellDelegate {
var episode: Episode?
- var commentsTableViewHeader: CommentsTableViewHeader!
- var commentsTableView: UITableView!
var comments: [Comment] = Array.init(repeating: Comment(episodeId: "", creator: "Mark Bryan", text: "Great point here!!", creationDate: "5 months ago", time: "5:13"), count: 10)
+ var episodeDetailViewHeaderHeight: CGFloat?
override func viewDidLoad() {
super.viewDidLoad()
- scrollView = UIScrollView(frame: view.frame)
- scrollView.backgroundColor = .white
- scrollView.contentSize = CGSize(width: view.frame.width, height: 0)
- view.addSubview(scrollView)
-
- episodeDetailHeaderView = EpisodeDetailHeaderView(frame: CGRect(x: 0, y: 0, width: scrollView.frame.width, height: 0))
- scrollView.addSubview(episodeDetailHeaderView)
-
- commentsTableViewHeader = CommentsTableViewHeader(frame: CGRect(x: 0, y: 0, width: scrollView.frame.width, height: 0))
- scrollView.addSubview(commentsTableViewHeader)
-
- commentsTableView = UITableView(frame: .zero)
- commentsTableView.dataSource = self
- commentsTableView.delegate = self
- commentsTableView.register(CommentsTableViewCell.self, forCellReuseIdentifier: "CommentsTableViewCellIdentifier")
- scrollView.addSubview(commentsTableView)
+ guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+ tableView.dataSource = self
+ tableView.delegate = self
+ tableView.register(CommentsTableViewCell.self, forCellReuseIdentifier: "CommentsTableViewCellIdentifier")
+ tableView.register(EpisodeDetailHeaderViewCell.self, forCellReuseIdentifier: "EpisodeDetailHeaderViewCellIdentifier")
+ tableView.contentInset = UIEdgeInsetsMake(0, 0, appDelegate.tabBarController.tabBarHeight, 0)
}
override func viewWillAppear(_ animated: Bool) {
- guard let episode = episode else { return }
- episodeDetailHeaderView.setupForEpisode(episode: episode)
- commentsTableViewHeader.frame.origin = CGPoint(x: 0, y: episodeDetailHeaderView.frame.maxY)
- commentsTableView.frame = CGRect(x: 0, y: commentsTableViewHeader.frame.maxY, width: scrollView.frame.width, height: 300)
- scrollView.contentSize.height = commentsTableView.frame.maxY
+ super.viewWillAppear(animated)
+ tableView.reloadData()
+ tableView.setNeedsLayout()
+ tableView.layoutIfNeeded()
+ tableView.reloadData()
}
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "CommentsTableViewCellIdentifier") as? CommentsTableViewCell else { return UITableViewCell() }
+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+ if indexPath.section == 0 {
+ if let cell = tableView.dequeueReusableCell(withIdentifier: "EpisodeDetailHeaderViewCellIdentifier") as? EpisodeDetailHeaderViewCell, let episode = episode {
+ cell.setupForEpisode(episode: episode)
+ cell.delegate = self
+ cell.layoutSubviews()
+ episodeDetailViewHeaderHeight = cell.frame.height
+ return cell
+ }
+ } else {
+ if let cell = tableView.dequeueReusableCell(withIdentifier: "CommentsTableViewCellIdentifier") as? CommentsTableViewCell {
cell.setupForComment(comment: comments[indexPath.row])
- commentsTableView.rowHeight = cell.frame.height
return cell
}
+ }
+ return UITableViewCell()
+ }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ if section == 0 {
+ return 1
+ }
return comments.count
}
+ override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+ if indexPath.section == 0 {
+ return episodeDetailViewHeaderHeight ?? 0
+ } else {
+ return CommentsTableViewCell.minimumHeight
+ }
+ }
+
+ override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+ if section == 1 {
+ return CommentsTableViewHeader(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: CommentsTableViewHeader.headerHeight))
+ }
+ return nil
+ }
+
+ override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
+ if section == 1 {
+ return CommentsTableViewHeader.headerHeight
+ }
+ return 0
+ }
+
+ override func numberOfSections(in tableView: UITableView) -> Int {
+ return 2
+ }
+
+ // EpisodeDetailHeaderViewCellDelegate methods
+
+ func episodeDetailHeaderDidPressRecommendButton(cell: EpisodeDetailHeaderViewCell) {
+
+ }
+
+ func episodeDetailHeaderDidPressMoreButton(cell: EpisodeDetailHeaderViewCell) {
+
+ }
+
+ func episodeDetailHeaderDidPressPlayButton(cell: EpisodeDetailHeaderViewCell) {
+ guard let episode = episode, let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+ cell.setPlaying(playing: true)
+ appDelegate.showPlayer(animated: true)
+ Player.sharedInstance.playEpisode(episode: episode)
+ }
+
+ func episodeDetailHeaderDidPressBookmarkButton(cell: EpisodeDetailHeaderViewCell) {
+
+ }
+
}

MODIFY
Podcast/PlayButton.swift
Podcast/PlayButton.swift
@@ -17,6 +17,7 @@ class PlayButton: UIButton {
setTitle(" Play", for: .normal)
setTitle(" Now Playing", for: .selected)
titleLabel?.font = .systemFont(ofSize: 12, weight: UIFontWeightRegular)
+ contentHorizontalAlignment = .left
setTitleColor(.podcastBlack, for: .normal)
setTitleColor(.podcastGreenBlue, for: .selected)
}

fix episode detail and add html labels