-
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 #173 from pietrocaselani/search_viewstate_no_story…
…board Search module to ViewState and no storyboard
- Loading branch information
Showing
39 changed files
with
599 additions
and
1,185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extension UICollectionViewLayout { | ||
static var ctDefault: UICollectionViewLayout { | ||
let layout = UICollectionViewFlowLayout() | ||
layout.scrollDirection = .vertical | ||
layout.itemSize = CGSize(width: 100, height: 180) | ||
layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) | ||
layout.minimumInteritemSpacing = 5 | ||
layout.minimumLineSpacing = 5 | ||
return layout | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
CouchTrackerApp/Search/SearchCollectionViewDataSource.swift
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,45 @@ | ||
import CouchTrackerCore | ||
|
||
final class SearchCollectionViewDataSource: NSObject, SearchDataSource { | ||
private let interactor: PosterCellInteractor | ||
|
||
var entities = [SearchResultEntity]() | ||
|
||
init(interactor: PosterCellInteractor) { | ||
self.interactor = interactor | ||
} | ||
|
||
func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int { | ||
return entities.count | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
let identifier = PosterAndTitleCell.identifier | ||
|
||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) | ||
|
||
guard let posterCell = cell as? PosterAndTitleCell else { | ||
Swift.fatalError("cell should be an instance of PosterAndTitleCell") | ||
} | ||
|
||
let entity = entities[indexPath.row] | ||
let viewModel = mapEntityToViewModel(entity) | ||
|
||
let presenter = PosterCellDefaultPresenter(view: posterCell, interactor: interactor, viewModel: viewModel) | ||
|
||
posterCell.presenter = presenter | ||
|
||
return posterCell | ||
} | ||
} | ||
|
||
private func mapEntityToViewModel(_ entity: SearchResultEntity) -> PosterViewModel { | ||
switch entity.type { | ||
case let .movie(movie): | ||
let type = movie.ids.tmdb.map { PosterViewModelType.movie(tmdbMovieId: $0) } | ||
return PosterViewModel(title: movie.title ?? "", type: type) | ||
case let .show(show): | ||
let type = show.ids.tmdb.map { PosterViewModelType.show(tmdbShowId: $0) } | ||
return PosterViewModel(title: show.title ?? "", type: type) | ||
} | ||
} |
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,61 @@ | ||
import Cartography | ||
|
||
public final class SearchView: View { | ||
public let collectionView: UICollectionView | ||
public let emptyView = DefaultEmptyView() | ||
|
||
public let searchBar: UISearchBar = { | ||
let searchBar = UISearchBar(frame: CGRect.zero) | ||
searchBar.isUserInteractionEnabled = true | ||
searchBar.barTintColor = Colors.NavigationBar.barTintColor | ||
return searchBar | ||
}() | ||
|
||
private lazy var stackView: UIStackView = { | ||
let subviews = [searchBar, collectionView] | ||
let stackView = UIStackView(arrangedSubviews: subviews) | ||
|
||
stackView.axis = .vertical | ||
stackView.alignment = .fill | ||
stackView.distribution = .equalSpacing | ||
|
||
return stackView | ||
}() | ||
|
||
init(collectionViewLayout: UICollectionViewLayout = UICollectionViewLayout.ctDefault) { | ||
collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: collectionViewLayout) | ||
super.init() | ||
} | ||
|
||
public required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
public required convenience init() { | ||
self.init(collectionViewLayout: UICollectionViewLayout.ctDefault) | ||
} | ||
|
||
public override func initialize() { | ||
addSubview(stackView) | ||
addSubview(emptyView) | ||
} | ||
|
||
public override func installConstraints() { | ||
constrain(stackView, emptyView, searchBar) { stack, empty, search in | ||
/* | ||
CT-TODO Fix this + 43 | ||
Without this constant, the search bar appears behind the top bar | ||
*/ | ||
search.top == search.superview!.top + 43 | ||
search.width == search.superview!.width | ||
|
||
stack.size == stack.superview!.size | ||
stack.top == stack.superview!.top | ||
stack.bottom == stack.superview!.bottom | ||
stack.left == stack.superview!.left | ||
stack.right == stack.superview!.right | ||
|
||
empty.center == empty.superview!.center | ||
} | ||
} | ||
} |
Oops, something went wrong.