Skip to content

Commit

Permalink
Merge pull request #181 from pietrocaselani/showsprogress_viewcode_no…
Browse files Browse the repository at this point in the history
…_storyboard

ShowsProgress to ViewCode and no storyboard
  • Loading branch information
pietrocaselani authored Jan 13, 2019
2 parents 19ae76e + f7c4315 commit 3328820
Show file tree
Hide file tree
Showing 46 changed files with 899 additions and 1,164 deletions.
140 changes: 24 additions & 116 deletions CouchTracker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions CouchTrackerApp/Core/CollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
open class CollectionViewCell: UICollectionViewCell {
public override init(frame: CGRect) {
super.init(frame: frame)
initialize()
installConstraints()
setup()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

private func setup() {
initialize()
installConstraints()
}
Expand Down
3 changes: 2 additions & 1 deletion CouchTrackerApp/Core/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum Colors {
}

public enum Cell {
public static let backgroundColor = UIColor.ctconcord
public static let foregroundColor = UIColor.ctconcord
public static let backgroundColor = UIColor.ctdarkerBunker
}

public enum Text {
Expand Down
20 changes: 20 additions & 0 deletions CouchTrackerApp/Core/TableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
open class TableViewCell: UITableViewCell {
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

private func setup() {
initialize()
installConstraints()
}

open func initialize() {}

open func installConstraints() {}
}
2 changes: 1 addition & 1 deletion CouchTrackerApp/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class Environment {

debug = true

plugins.append(NetworkLoggerPlugin(verbose: false))
// plugins.append(NetworkLoggerPlugin(verbose: false))
#else
debug = false
#endif
Expand Down
1 change: 1 addition & 0 deletions CouchTrackerApp/Show/Episode/ShowEpisodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ShowEpisodeView: View {
imageView.contentMode = UIView.ContentMode.scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapOnPreview)))
imageView.clipsToBounds = true
return imageView
}()

Expand Down
37 changes: 0 additions & 37 deletions CouchTrackerApp/Shows/Progress/Cell/ShowProgressCell.swift

This file was deleted.

107 changes: 107 additions & 0 deletions CouchTrackerApp/Shows/Progress/ShowProgressCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import Cartography
import CouchTrackerCore
import RxSwift

final class ShowProgressCell: TableViewCell {
static let identifier = "ShowProgressCell"
private var disposable: Disposable?

var presenter: ShowProgressCellPresenter? {
didSet {
disposable = presenter?.observeViewState().subscribe(onNext: { [weak self] viewState in
self?.handleViewState(viewState)
})

presenter?.viewWillAppear()
}
}

override func prepareForReuse() {
super.prepareForReuse()

posterImageView.image = nil
disposable = nil
}

private func handleViewState(_ viewState: ShowProgressCellViewState) {
switch viewState {
case let .viewModel(viewModel):
show(viewModel: viewModel)
case let .viewModelAndPosterURL(viewModel, url):
show(viewModel: viewModel)
showPosterImage(with: url)
}
}

private func show(viewModel: WatchedShowViewModel) {
showTitleLabel.text = viewModel.title
episodeTitleLabel.text = viewModel.nextEpisode
statusAndDateLabel.text = viewModel.nextEpisodeDate
remainingAndNetworkLabel.text = viewModel.status
}

private func showPosterImage(with url: URL) {
posterImageView.kf.setImage(with: url)
}

let posterImageView = UIImageView()

let showTitleLabel: UILabel = {
let label = UILabel()
label.textColor = Colors.Text.primaryTextColor
label.font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
return label
}()

let episodeTitleLabel: UILabel = {
let label = UILabel()
label.textColor = Colors.Text.primaryTextColor
label.font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
return label
}()

let remainingAndNetworkLabel: UILabel = {
let label = UILabel()
label.textColor = Colors.Text.secondaryTextColor
label.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)
return label
}()

let statusAndDateLabel: UILabel = {
let label = UILabel()
label.textColor = Colors.Text.secondaryTextColor
label.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)
return label
}()

private lazy var labelsStackView: UIStackView = {
let subviews = [remainingAndNetworkLabel, showTitleLabel, episodeTitleLabel, statusAndDateLabel]
let stack = UIStackView(arrangedSubviews: subviews)
stack.axis = .vertical
stack.distribution = .fillProportionally
return stack
}()

override func initialize() {
addSubview(labelsStackView)
addSubview(posterImageView)
backgroundColor = Colors.Cell.backgroundColor
}

override func installConstraints() {
constrain(labelsStackView, posterImageView) { stack, poster in
let margin: CGFloat = 5

poster.height == poster.superview!.height - (margin * 2)
poster.width == poster.height * 0.75
poster.left == poster.superview!.left + margin
poster.top == poster.superview!.top + margin
poster.bottom == poster.superview!.bottom - margin

stack.left == poster.right + margin
stack.top == poster.top
stack.bottom == poster.bottom
stack.right == stack.superview!.right
}
}
}
Loading

0 comments on commit 3328820

Please sign in to comment.