-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from pietrocaselani/showsprogress_viewcode_no…
…_storyboard ShowsProgress to ViewCode and no storyboard
- Loading branch information
Showing
46 changed files
with
899 additions
and
1,164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
CouchTrackerApp/Shows/Progress/Cell/ShowProgressCell.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.