Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
chkpnt committed Apr 12, 2019
1 parent d22601d commit 429a8d0
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 180 deletions.
44 changes: 22 additions & 22 deletions MaultaschenApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
54BA8A882250C3ED00DB5632 /* About.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 54BA89C92250B09200DB5632 /* About.xcassets */; };
54BA8A892250C55700DB5632 /* MealDetailsAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA899E2250B09200DB5632 /* MealDetailsAssembly.swift */; };
54BA8A8B2250C55700DB5632 /* MealDetailsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA899D2250B09200DB5632 /* MealDetailsPresenter.swift */; };
54BA8A8C2250C55700DB5632 /* MealDetailsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89A02250B09200DB5632 /* MealDetailsRouter.swift */; };
54BA8A8C2250C55700DB5632 /* MealDetailsRouterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89A02250B09200DB5632 /* MealDetailsRouterProtocol.swift */; };
54BA8A8D2250C55700DB5632 /* MealDetailsWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89A12250B09200DB5632 /* MealDetailsWireframe.swift */; };
54BA8A8E2250C55700DB5632 /* MealDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89A22250B09200DB5632 /* MealDetailsViewController.swift */; };
54BA8A8F2250C55700DB5632 /* MealDetails.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 54BA899F2250B09200DB5632 /* MealDetails.xcassets */; };
Expand All @@ -105,7 +105,7 @@
54BA8A9B2250C7D600DB5632 /* SimpleFilter.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 54BA89952250B09200DB5632 /* SimpleFilter.storyboard */; };
54BA8A9C2250C7D600DB5632 /* SimpleFilterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA899A2250B09200DB5632 /* SimpleFilterViewController.swift */; };
54BA8A9D2250C7D600DB5632 /* SimpleFilterPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89982250B09200DB5632 /* SimpleFilterPresenter.swift */; };
54BA8A9E2250C7D600DB5632 /* SimpleFilterRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89992250B09200DB5632 /* SimpleFilterRouter.swift */; };
54BA8A9E2250C7D600DB5632 /* SimpleFilterRouterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89992250B09200DB5632 /* SimpleFilterRouterProtocol.swift */; };
54BA8A9F2250C7E900DB5632 /* NearbyVenuesAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89CC2250B09200DB5632 /* NearbyVenuesAssembly.swift */; };
54BA8AA12250C7E900DB5632 /* NearbyVenuesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89CE2250B09200DB5632 /* NearbyVenuesViewController.swift */; };
54BA8AA22250C7E900DB5632 /* NearbyVenuesPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BA89CF2250B09200DB5632 /* NearbyVenuesPresenter.swift */; };
Expand Down Expand Up @@ -287,13 +287,13 @@
54BA89962250B09200DB5632 /* SimpleFilterAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterAssembly.swift; sourceTree = "<group>"; };
54BA89972250B09200DB5632 /* SimpleFilterWireframe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterWireframe.swift; sourceTree = "<group>"; };
54BA89982250B09200DB5632 /* SimpleFilterPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterPresenter.swift; sourceTree = "<group>"; };
54BA89992250B09200DB5632 /* SimpleFilterRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterRouter.swift; sourceTree = "<group>"; };
54BA89992250B09200DB5632 /* SimpleFilterRouterProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterRouterProtocol.swift; sourceTree = "<group>"; };
54BA899A2250B09200DB5632 /* SimpleFilterViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleFilterViewController.swift; sourceTree = "<group>"; };
54BA899C2250B09200DB5632 /* MealDetailsInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsInteractor.swift; sourceTree = "<group>"; };
54BA899D2250B09200DB5632 /* MealDetailsPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsPresenter.swift; sourceTree = "<group>"; };
54BA899E2250B09200DB5632 /* MealDetailsAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsAssembly.swift; sourceTree = "<group>"; };
54BA899F2250B09200DB5632 /* MealDetails.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = MealDetails.xcassets; sourceTree = "<group>"; };
54BA89A02250B09200DB5632 /* MealDetailsRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsRouter.swift; sourceTree = "<group>"; };
54BA89A02250B09200DB5632 /* MealDetailsRouterProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsRouterProtocol.swift; sourceTree = "<group>"; };
54BA89A12250B09200DB5632 /* MealDetailsWireframe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsWireframe.swift; sourceTree = "<group>"; };
54BA89A22250B09200DB5632 /* MealDetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MealDetailsViewController.swift; sourceTree = "<group>"; };
54BA89A52250B09200DB5632 /* UIViewController+deinit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+deinit.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -555,11 +555,11 @@
54BA89A42250B09200DB5632 /* commons */,
54BA89DE2250B09200DB5632 /* Main */,
54BA89D62250B09200DB5632 /* Overview */,
54BA89942250B09200DB5632 /* SimpleFilter */,
54BA89B32250B09200DB5632 /* NearbyMeals */,
54BA89CA2250B09200DB5632 /* NearbyVenues */,
54BA899B2250B09200DB5632 /* MealDetails */,
54BA89C02250B09200DB5632 /* About */,
54BA89942250B09200DB5632 /* SimpleFilter */,
54BA8A6C2250C2F300DB5632 /* TextViewPopup */,
);
path = Wireframes;
Expand All @@ -569,11 +569,11 @@
isa = PBXGroup;
children = (
54BA89962250B09200DB5632 /* SimpleFilterAssembly.swift */,
54BA89972250B09200DB5632 /* SimpleFilterWireframe.swift */,
54BA89952250B09200DB5632 /* SimpleFilter.storyboard */,
54BA899A2250B09200DB5632 /* SimpleFilterViewController.swift */,
54BA89982250B09200DB5632 /* SimpleFilterPresenter.swift */,
54BA89992250B09200DB5632 /* SimpleFilterRouter.swift */,
54BA899A2250B09200DB5632 /* SimpleFilterViewController.swift */,
54BA89952250B09200DB5632 /* SimpleFilter.storyboard */,
54BA89992250B09200DB5632 /* SimpleFilterRouterProtocol.swift */,
54BA89972250B09200DB5632 /* SimpleFilterWireframe.swift */,
);
path = SimpleFilter;
sourceTree = "<group>";
Expand All @@ -583,9 +583,9 @@
children = (
54BA899E2250B09200DB5632 /* MealDetailsAssembly.swift */,
54BA899D2250B09200DB5632 /* MealDetailsPresenter.swift */,
54BA89A02250B09200DB5632 /* MealDetailsRouter.swift */,
54BA89A12250B09200DB5632 /* MealDetailsWireframe.swift */,
54BA89A22250B09200DB5632 /* MealDetailsViewController.swift */,
54BA89A02250B09200DB5632 /* MealDetailsRouterProtocol.swift */,
54BA89A12250B09200DB5632 /* MealDetailsWireframe.swift */,
54BA899F2250B09200DB5632 /* MealDetails.xcassets */,
547E95822252B15F0027AA44 /* MealDetails.strings */,
);
Expand Down Expand Up @@ -666,11 +666,11 @@
children = (
54BA89C12250B09200DB5632 /* AboutAssembly.swift */,
54BA89C22250B09200DB5632 /* AboutPresenter.swift */,
54BA89C32250B09200DB5632 /* AboutRouterProtocol.swift */,
54BA89C42250B09200DB5632 /* AboutViewModel.swift */,
54BA89C62250B09200DB5632 /* AboutWireframe.swift */,
54BA89C72250B09200DB5632 /* About.storyboard */,
54BA89C82250B09200DB5632 /* AboutViewController.swift */,
54BA89C72250B09200DB5632 /* About.storyboard */,
54BA89C32250B09200DB5632 /* AboutRouterProtocol.swift */,
54BA89C62250B09200DB5632 /* AboutWireframe.swift */,
547E95852252B1640027AA44 /* About.strings */,
54BA89C92250B09200DB5632 /* About.xcassets */,
);
Expand All @@ -682,8 +682,8 @@
children = (
54BA89D02250B09200DB5632 /* VenueCollectionViewCell */,
54BA89CC2250B09200DB5632 /* NearbyVenuesAssembly.swift */,
54BA89CE2250B09200DB5632 /* NearbyVenuesViewController.swift */,
54BA89CF2250B09200DB5632 /* NearbyVenuesPresenter.swift */,
54BA89CE2250B09200DB5632 /* NearbyVenuesViewController.swift */,
54BA89D42250B09200DB5632 /* NearbyVenuesRouterProtocol.swift */,
54BA89D52250B09200DB5632 /* NearbyVenuesWireframe.swift */,
54BA89CD2250B09200DB5632 /* NearbyVenues.xcassets */,
Expand All @@ -705,10 +705,10 @@
isa = PBXGroup;
children = (
54BA89D82250B09200DB5632 /* OverviewAssembly.swift */,
54BA89DD2250B09200DB5632 /* OverviewPresenter.swift */,
54BA89DC2250B09200DB5632 /* OverviewViewController.swift */,
54BA89D92250B09200DB5632 /* OverviewRouterProtocol.swift */,
54BA89DA2250B09200DB5632 /* OverviewWireframe.swift */,
54BA89DC2250B09200DB5632 /* OverviewViewController.swift */,
54BA89DD2250B09200DB5632 /* OverviewPresenter.swift */,
547E95A8225651D50027AA44 /* OverviewStrings.swift */,
54BA89D72250B09200DB5632 /* Overview.xcassets */,
);
Expand Down Expand Up @@ -801,13 +801,13 @@
isa = PBXGroup;
children = (
54BA8A732250C2F300DB5632 /* TextViewPopupAssembly.swift */,
54BA8A6D2250C2F300DB5632 /* TextViewPopupRouterProtocol.swift */,
54BA8A742250C2F300DB5632 /* TextViewPopupPresenter.swift */,
54BA8A6E2250C2F300DB5632 /* TextViewPopupViewModel.swift */,
54BA8A722250C2F300DB5632 /* TextViewPopupViewController.swift */,
54BA8A6F2250C2F300DB5632 /* TextViewPopup.storyboard */,
54BA8A6D2250C2F300DB5632 /* TextViewPopupRouterProtocol.swift */,
54BA8A702250C2F300DB5632 /* TextViewPopupWireframe.swift */,
54BA8A712250C2F300DB5632 /* TextViewPopupModel.swift */,
54BA8A722250C2F300DB5632 /* TextViewPopupViewController.swift */,
54BA8A742250C2F300DB5632 /* TextViewPopupPresenter.swift */,
);
path = TextViewPopup;
sourceTree = "<group>";
Expand Down Expand Up @@ -1389,8 +1389,8 @@
54BA8A002250B09200DB5632 /* WithStaticReuseIdentifier.swift in Sources */,
54BA8A832250C3ED00DB5632 /* AboutViewModel.swift in Sources */,
54BA8A272250B09200DB5632 /* MainWireframe.swift in Sources */,
54BA8A8C2250C55700DB5632 /* MealDetailsRouter.swift in Sources */,
54BA8A9E2250C7D600DB5632 /* SimpleFilterRouter.swift in Sources */,
54BA8A8C2250C55700DB5632 /* MealDetailsRouterProtocol.swift in Sources */,
54BA8A9E2250C7D600DB5632 /* SimpleFilterRouterProtocol.swift in Sources */,
54BA89FF2250B09200DB5632 /* Observable.swift in Sources */,
54BA8A762250C2F300DB5632 /* TextViewPopupViewModel.swift in Sources */,
547E95A9225651D50027AA44 /* OverviewStrings.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion MaultaschenApp/Application/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Environment {
private let assembler: Assembler

private init() {
self.assembler = Assembler()
self.assembler = Assembler(parentAssembler: nil, defaultObjectScope: .transient, behaviors: [])
}

private var mainWireframe: MainWireframeProtocol?
Expand Down
9 changes: 8 additions & 1 deletion MaultaschenApp/R.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct R: Rswift.Validatable {
try intern.validate()
}

/// This `R.image` struct is generated, and contains static references to 6 images.
/// This `R.image` struct is generated, and contains static references to 7 images.
struct image {
/// Image `aboutTabBarIcon`.
static let aboutTabBarIcon = Rswift.ImageResource(bundle: R.hostingBundle, name: "aboutTabBarIcon")
Expand All @@ -28,6 +28,8 @@ struct R: Rswift.Validatable {
static let nearbyVenuesTabBarIcon = Rswift.ImageResource(bundle: R.hostingBundle, name: "nearbyVenuesTabBarIcon")
/// Image `no_image`.
static let no_image = Rswift.ImageResource(bundle: R.hostingBundle, name: "no_image")
/// Image `overviewTabBarIco`.
static let overviewTabBarIco = Rswift.ImageResource(bundle: R.hostingBundle, name: "overviewTabBarIco")
/// Image `overviewTabBarIcon`.
static let overviewTabBarIcon = Rswift.ImageResource(bundle: R.hostingBundle, name: "overviewTabBarIcon")

Expand Down Expand Up @@ -56,6 +58,11 @@ struct R: Rswift.Validatable {
return UIKit.UIImage(resource: R.image.no_image, compatibleWith: traitCollection)
}

/// `UIImage(named: "overviewTabBarIco", bundle: ..., traitCollection: ...)`
static func overviewTabBarIco(compatibleWith traitCollection: UIKit.UITraitCollection? = nil) -> UIKit.UIImage? {
return UIKit.UIImage(resource: R.image.overviewTabBarIco, compatibleWith: traitCollection)
}

/// `UIImage(named: "overviewTabBarIcon", bundle: ..., traitCollection: ...)`
static func overviewTabBarIcon(compatibleWith traitCollection: UIKit.UITraitCollection? = nil) -> UIKit.UIImage? {
return UIKit.UIImage(resource: R.image.overviewTabBarIcon, compatibleWith: traitCollection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class NearbyMealsAssembly: Assembly {

let presenter = NearbyMealsPresenter(interactor: interactor)
let viewController = NearbyMealsViewController(presenter: presenter)

presenter.set(view: viewController)
presenter.set(router: router)
interactor.set(delegate: presenter)

return NearbyMealsWireframe(viewController: viewController, presenter: presenter)
}.inObjectScope(.transient)
}
}

}
29 changes: 18 additions & 11 deletions MaultaschenApp/Wireframes/NearbyMeals/NearbyMealsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import MaultaschenDomain

//sourcery: AutoMockable
protocol NearbyMealsPresenterProtocol: AnyObject {
func viewDidLoad()
func findMeals()
func didTap(meal: MealCollectionViewCellModel)
func filterMeals(by name: String)
Expand All @@ -24,6 +23,7 @@ class NearbyMealsPresenter: NearbyMealsPresenterProtocol {
private weak var view: NearbyMealsViewProtocol?

private var currentViewModels: [MealCollectionViewCellModel] = []
private var currentActiveFilter: String = ""

init(interactor: NearbyMealsInteractorProtocol) {
self.interactor = interactor
Expand All @@ -37,31 +37,38 @@ class NearbyMealsPresenter: NearbyMealsPresenterProtocol {
self.view = view
}

func viewDidLoad() {
findMeals()
}

func findMeals() {
let meals = interactor.findMeals()
.map { m in MealCollectionViewCellModel(meal: m.meal, image: m.image) }
currentViewModels = meals
view?.show(meals: meals)
interactor.findMeals()
}

func didTap(meal: MealCollectionViewCellModel) {
router?.showDetails(for: meal.meal)
}

func filterMeals(by name: String) {
guard !name.isEmpty else {
currentActiveFilter = name
updateView()
}

private func updateView() {
guard !currentActiveFilter.isEmpty else {
view?.show(meals: currentViewModels)
return
}

let filteredViewModels = currentViewModels.filter {
$0.title.localizedCaseInsensitiveContains(name) || $0.venue.localizedCaseInsensitiveContains(name)
$0.title.localizedCaseInsensitiveContains(currentActiveFilter) || $0.venue.localizedCaseInsensitiveContains(currentActiveFilter)
}
view?.show(meals: filteredViewModels)
}

}

extension NearbyMealsPresenter: NearbyMealsInteractorDelegate {

func didFind(_ data: [(meal: Meal, image: UIImage)]) {
currentViewModels = data.map { MealCollectionViewCellModel(meal: $0.meal, image: $0.image) }
updateView()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ protocol NearbyMealsViewProtocol: AnyObject {
func show(meals: [MealCollectionViewCellModel])
}

// I have NO converns writing this extension "above" the ViewController.
// Pro point: The protocol implementation is THE important thing
// from the presenter's perspective, the ViewController itself
// is a detail. And its mostly reasonable to put the most important
// stuff above.
extension NearbyMealsViewController: NearbyMealsViewProtocol {

func show(meals: [MealCollectionViewCellModel]) {
self.meals = meals
collectionView.reloadData()
}

}

class NearbyMealsViewController: UICollectionViewController {

private let presenter: NearbyMealsPresenterProtocol
Expand All @@ -37,8 +51,6 @@ class NearbyMealsViewController: UICollectionViewController {
#else
collectionView.register(UINib(nibName: "MealCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "MealCollectionViewCell")
#endif

presenter.viewDidLoad()
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -49,6 +61,11 @@ class NearbyMealsViewController: UICollectionViewController {
.forEach { $0?.shrink() }
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
presenter.findMeals()
}

override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
Expand Down Expand Up @@ -80,22 +97,10 @@ class NearbyMealsViewController: UICollectionViewController {

}

extension NearbyMealsViewController: NearbyMealsViewProtocol {

func show(meals: [MealCollectionViewCellModel]) {
self.meals = meals
collectionView.reloadData()
}

}

extension NearbyMealsViewController: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let padding: CGFloat = 50
let collectionViewSize = collectionView.frame.size.width - padding

return CGSize(width: collectionViewSize/2, height: 250)
return CGSize(width: 180, height: 250)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NearbyVenuesAssembly: Assembly {
interactor.set(delegate: presenter)

return NearbyVenuesWireframe(viewController: viewController, presenter: presenter)
}.inObjectScope(.transient)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation
import MaultaschenDomain

protocol NearbyVenuesPresenterProtocol: AnyObject {
func viewDidLoad()
func findVenues()
func filerVenues(by name: String)
}
Expand All @@ -34,21 +33,22 @@ class NearbyVenuesPresenter: NearbyVenuesPresenterProtocol {
self.view = view
}

func viewDidLoad() {
findVenues()
}

func findVenues() {
interactor.findVenues()
}

func filerVenues(by name: String) {
guard !name.isEmpty else {
currentActiveFilter = name
updateView()
}

private func updateView() {
guard !currentActiveFilter.isEmpty else {
view?.show(venues: currentViewModels)
return
}

let filteredViewModels = currentViewModels.filter { $0.venue.localizedCaseInsensitiveContains(name) }
let filteredViewModels = currentViewModels.filter { $0.venue.localizedCaseInsensitiveContains(currentActiveFilter) }
view?.show(venues: filteredViewModels)
}

Expand All @@ -58,8 +58,7 @@ extension NearbyVenuesPresenter: NearbyVenuesInteractorDelegate {

func didFind(venues: [Venue]) {
currentViewModels = venues.map { VenueCollectionViewCellModel(venue: $0.name, image: R.image.no_image()) }
view?.show(venues: currentViewModels)
updateView()
}


}
Loading

0 comments on commit 429a8d0

Please sign in to comment.