Skip to content

Commit

Permalink
Changes per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
lokae0 committed Jan 24, 2019
1 parent 955be85 commit 2d7a294
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 94 deletions.
12 changes: 6 additions & 6 deletions Application/Source/Detail/View/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class DetailView: UIView {
return view
}()

let contentsListTitle = UILabel.centeredLabel()
let contentsList = UILabel.centeredLabel()
let contentsButton = UIButton()
let foodListTitle = UILabel.centeredLabel()
let foodList = UILabel.centeredLabel()
let foodInfoButton = UIButton()

private(set) lazy var stackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
title,
button,
selectionResult,
spacingView,
contentsListTitle,
contentsList,
contentsButton
foodListTitle,
foodList,
foodInfoButton
])
stackView.axis = .vertical
stackView.alignment = .center
Expand Down
14 changes: 7 additions & 7 deletions Application/Source/Detail/View/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ class DetailViewController: UIViewController, ViewController {
.bind(to: detailView.selectionResult.rx.text)
.disposed(by: disposeBag)

viewModel.contentsListTitle
.bind(to: detailView.contentsListTitle.rx.text)
viewModel.foodListTitle
.bind(to: detailView.foodListTitle.rx.text)
.disposed(by: disposeBag)
viewModel.contentsListText
.bind(to: detailView.contentsList.rx.text)
viewModel.foodListText
.bind(to: detailView.foodList.rx.text)
.disposed(by: disposeBag)
viewModel.contentsButtonTitle
.bind(to: detailView.contentsButton.rx.title())
viewModel.foodInfoButtonTitle
.bind(to: detailView.foodInfoButton.rx.title())
.disposed(by: disposeBag)

detailView.button.rx.bind(to: viewModel.presentSelection, input: true)
detailView.contentsButton.rx.bind(to: viewModel.presentContents, input: ())
detailView.foodInfoButton.rx.bind(to: viewModel.presentContents, input: ())

rx.isAppeared
.bind(to: viewModel.isActive)
Expand Down
18 changes: 9 additions & 9 deletions Application/Source/Detail/View/DetailViewControllerStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import Core
struct DetailViewControllerStyle: Style {
let theme: Theme
let background: BackgroundViewStyle
let title: LabelStyle
let alternateCopy: AlternateLabelStyle
let label: LabelStyle
let alternateLabel: AlternateLabelStyle
let button: ButtonStyle

init(theme: Theme) {
self.theme = theme
background = BackgroundViewStyle(theme: theme)
title = LabelStyle(theme: theme)
alternateCopy = AlternateLabelStyle(theme: theme)
label = LabelStyle(theme: theme)
alternateLabel = AlternateLabelStyle(theme: theme)
button = ButtonStyle(theme: theme)
}

func apply(to styleable: DetailViewController) {
let view = styleable.detailView
background.apply(to: view)

title.apply(to: view.title)
title.apply(to: view.contentsListTitle)
label.apply(to: view.title)
label.apply(to: view.foodListTitle)

alternateCopy.apply(to: view.selectionResult)
alternateCopy.apply(to: view.contentsList)
alternateLabel.apply(to: view.selectionResult)
alternateLabel.apply(to: view.foodList)

button.apply(to: view.button)
button.apply(to: view.contentsButton)
button.apply(to: view.foodInfoButton)

view.stackView.spacing = theme.layout.interitemSpacing
}
Expand Down
22 changes: 9 additions & 13 deletions Application/Source/Detail/View/DetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ class DetailViewModel: ViewModel, SelectionPresentingViewModel {

let presentSelectionTitle = Property(L10n.Detail.Select.title)

let contentsListTitle = Property(L10n.Detail.ContentsList.title)
let contentsButtonTitle = Property(L10n.Detail.ContentsButton.title)
let foodListTitle = Property(L10n.Detail.FoodList.title)
let foodInfoButtonTitle = Property(L10n.Detail.FoodButton.title)

let presentContents = CocoaAction { _ in
print("Content button pressed")
return .empty()
}

let content: BehaviorRelay<[Food]> = BehaviorRelay(value: [.beans, .greens, .potatoes, .tomatoes])
let foods: BehaviorRelay<[Food]> = BehaviorRelay(value: [.beans, .greens, .potatoes, .tomatoes])

let contentListSeparator: String = ", "

private(set) lazy var contentsListText: Property<String> = {
let initial = ""
let observable = content.map { [weak self] contents -> String in
guard let self = self else { return initial }
return contents
.map { $0.name.value }
.joined(separator: self.contentListSeparator)
private(set) lazy var foodListText: Property<String> = {
let observable = foods.map { foods -> String in
return foods
.map { $0.name }
.joined(separator: ", ")
}
return Property(observable, initial: initial)
return Property(observable, initial: "")
}()

private(set) lazy var presentSelection = makePresentSelection(
Expand Down
44 changes: 0 additions & 44 deletions Application/Source/Models/Content.swift

This file was deleted.

22 changes: 22 additions & 0 deletions Application/Source/Models/Food.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import RxCocoa

/**
It's not a side project if you can't have some fun, right?
- [Original.](https://www.youtube.com/watch?v=amONEHAhLHY)
- [Crispy.](https://www.youtube.com/watch?v=1BC1G33-fNY)
*/
enum Food {

case beans, greens, potatoes, tomatoes

var name: String {
switch self {
case .beans: return L10n.Food.beans
case .greens: return L10n.Food.greens
case .potatoes: return L10n.Food.potatoes
case .tomatoes: return L10n.Food.tomatoes
}
}

}
12 changes: 6 additions & 6 deletions Application/Source/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ internal enum L10n {
internal enum Detail {
/// Details
internal static let title = L10n.tr("Localizable", "detail.title")
internal enum ContentsButton {
/// Contents Info
internal static let title = L10n.tr("Localizable", "detail.contents_button.title")
internal enum FoodButton {
/// Food Info
internal static let title = L10n.tr("Localizable", "detail.food_button.title")
}
internal enum ContentsList {
/// Contents
internal static let title = L10n.tr("Localizable", "detail.contents_list.title")
internal enum FoodList {
/// Ingredients
internal static let title = L10n.tr("Localizable", "detail.food_list.title")
}
internal enum Select {
/// Select Text
Expand Down
16 changes: 11 additions & 5 deletions Application/Supporting Files/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/* The title of the tab bar item for the detail navigation flow. */
"detail_navigation.tab_bar_item.title" = "Detail";

/* Title for the contents list on the details view. */
"detail.contents_list.title" = "Contents";
/* Title for the food list on the details view. */
"detail.food_list.title" = "Ingredients";

/* Title for the contents button that presents the contents view. */
"detail.contents_button.title" = "Contents Info";
/* Title for the food button that presents the contents view. */
"detail.food_button.title" = "Food Info";

/* The title of the button that presents the detail view. */
"home.present_detail.title" = "Details";
Expand All @@ -31,8 +31,14 @@
/* The title of the tab bar item for the settings navigation flow. */
"settings_navigation.tab_bar_item.title" = "Settings";

/* Food enum names. */
/* Name of Food: beans. */
"food.beans" = "Beans";

/* Name of Food: greens. */
"food.greens" = "Greens";

/* Name of Food: potatoes. */
"food.potatoes" = "Potatoes";

/* Name of Food: tomatoes. */
"food.tomatoes" = "Tomatoes";
8 changes: 4 additions & 4 deletions Application/Tests/DetailViewModelSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class DetailViewModelSpec: QuickSpec {
}
}

describe("contentsListText") {
describe("foodListText") {
it("should return a String list from the array of Contents") {
viewModel.content.accept([.tomatoes, .potatoes])
let expected = L10n.Food.tomatoes + viewModel.contentListSeparator + L10n.Food.potatoes
viewModel.foods.accept([.tomatoes, .potatoes])
let expected = L10n.Food.tomatoes + ", " + L10n.Food.potatoes

expect(viewModel.contentsListText.value).to(equal(expected))
expect(viewModel.foodListText.value).to(equal(expected))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Core/Source/Themes/Styles/LabelStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public struct AlternateLabelStyle: UILabelStyle {
public init(theme: Theme) {
textColor = theme.color.alternateBodyText
}

}

0 comments on commit 2d7a294

Please sign in to comment.