Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CookSmart/CookSmart.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
39024F62243174BB0063725D /* CSIngredientsExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39024F61243174BB0063725D /* CSIngredientsExt.swift */; };
392D8645242FD0FF002064D6 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392D8644242FD0FF002064D6 /* Colors.swift */; };
392D865424304F2D002064D6 /* IngredientListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392D865324304F2D002064D6 /* IngredientListViewController.swift */; };
392D865724306D0D002064D6 /* CSConversionVCExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392D865624306D0D002064D6 /* CSConversionVCExt.swift */; };
396E363D2439684E00C2815B /* UnitPickerCenterLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396E363C2439684E00C2815B /* UnitPickerCenterLineView.swift */; };
396E363F24396D5900C2815B /* UnitPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396E363E24396D5900C2815B /* UnitPickerView.swift */; };
396E3643243976A000C2815B /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396E3642243976A000C2815B /* GradientView.swift */; };
Expand Down Expand Up @@ -83,7 +86,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
39024F61243174BB0063725D /* CSIngredientsExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSIngredientsExt.swift; sourceTree = "<group>"; };
392D8644242FD0FF002064D6 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
392D865324304F2D002064D6 /* IngredientListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IngredientListViewController.swift; sourceTree = "<group>"; };
392D865624306D0D002064D6 /* CSConversionVCExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSConversionVCExt.swift; sourceTree = "<group>"; };
396E363C2439684E00C2815B /* UnitPickerCenterLineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitPickerCenterLineView.swift; sourceTree = "<group>"; };
396E363E24396D5900C2815B /* UnitPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitPickerView.swift; sourceTree = "<group>"; };
396E3642243976A000C2815B /* GradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -232,6 +238,7 @@
93D0993B18977D320014DB3E /* Units */,
80592C0318924B010082D4E1 /* CSIngredients.h */,
80592C0418924B010082D4E1 /* CSIngredients.m */,
39024F61243174BB0063725D /* CSIngredientsExt.swift */,
80592C0618924B0F0082D4E1 /* CSIngredient.h */,
80592C0718924B0F0082D4E1 /* CSIngredient.m */,
80592C091892541D0082D4E1 /* CSIngredientGroup.h */,
Expand Down Expand Up @@ -271,6 +278,7 @@
9368096F1891059700655B89 /* CSIngredientListVC.m */,
807C0B6A1BB3DD4D007D2C03 /* CSIngredientListViewCell.h */,
807C0B6B1BB3DD4D007D2C03 /* CSIngredientListViewCell.m */,
392D865324304F2D002064D6 /* IngredientListViewController.swift */,
);
name = "Ingredient List UI";
sourceTree = "<group>";
Expand Down Expand Up @@ -332,6 +340,7 @@
9358BD6B1891CAAA00A99D51 /* CSConversionVC.h */,
9358BD6C1891CAAA00A99D51 /* CSConversionVC.m */,
9358BD6D1891CAAA00A99D51 /* CSConversionVC.xib */,
392D865624306D0D002064D6 /* CSConversionVCExt.swift */,
8000355C18B3CBF50032BF91 /* Scales */,
80592C0218924AEA0082D4E1 /* Model */,
807C0B681BB3DD04007D2C03 /* Ingredient List UI */,
Expand Down Expand Up @@ -575,6 +584,8 @@
774EBD6524426CC2002A59AC /* Double+StringUtils.swift in Sources */,
396E363F24396D5900C2815B /* UnitPickerView.swift in Sources */,
77479AEA242FB9C8000CFB0E /* ScaleTile.swift in Sources */,
392D865424304F2D002064D6 /* IngredientListViewController.swift in Sources */,
392D865724306D0D002064D6 /* CSConversionVCExt.swift in Sources */,
774EBD802442EC26002A59AC /* UIView+Constraints.swift in Sources */,
392D8645242FD0FF002064D6 /* Colors.swift in Sources */,
80A614DE18BF3D4100A205BB /* CSGlassView.m in Sources */,
Expand All @@ -600,6 +611,7 @@
396E3643243976A000C2815B /* GradientView.swift in Sources */,
396E363D2439684E00C2815B /* UnitPickerCenterLineView.swift in Sources */,
936809701891059700655B89 /* CSIngredientListVC.m in Sources */,
39024F62243174BB0063725D /* CSIngredientsExt.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 5 additions & 3 deletions CookSmart/CookSmart/CSConversionVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "CSUnit.h"
#import "CSUnitCollection.h"
#import "CSScaleVC.h"
#import "cake-Swift.h"

#define CHOOSE_UNITS_TEXT @"Choose Units"

Expand Down Expand Up @@ -153,9 +154,10 @@ - (void)refreshIngredientNameUI

- (void)handleIngredientTap:(id)sender
{
CSIngredientListVC* ingrListVC = [[CSIngredientListVC alloc] initWithDelegate:self];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:ingrListVC];
[self presentViewController:nav animated:YES completion:nil];
[self showIngredientList];
// CSIngredientListVC* ingrListVC = [[CSIngredientListVC alloc] initWithDelegate:self];
// UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:ingrListVC];
// [self presentViewController:nav animated:YES completion:nil];
Comment on lines +158 to +160

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up the comments.

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Expand Down
17 changes: 17 additions & 0 deletions CookSmart/CookSmart/CSConversionVCExt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CSConversionVCExt.swift
// cake
//
// Created by Alex King on 3/28/20.
// Copyright © 2020 Olga Galchenko. All rights reserved.
//

import Foundation

extension CSConversionVC {
@objc
func showIngredientList() {
let ingredientListViewController = IngredientListViewController()
present(ingredientListViewController, animated: true, completion: nil)
}
}
46 changes: 0 additions & 46 deletions CookSmart/CookSmart/CSIngredientListVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,52 +171,6 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)
((numGroups > 1) || (numGroups == 1 && [[[CSIngredients sharedInstance] ingredientGroupAtIndex:0] countOfIngredients] > 1));
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
CSIngredients *ingredients = [self ingredientsToSupplyData];
CSRecentsIngredientGroup *beforeChangeRecents = ingredients.recents;
CSIngredientGroup *ingredientGroup = [ingredients ingredientGroupAtIndex:indexPath.section];
CSIngredient *ingredientToDelete = [ingredientGroup ingredientAtIndex:indexPath.row];
BOOL needToDeleteFromRecents = beforeChangeRecents && [beforeChangeRecents indexOfIngredient:ingredientToDelete] != NSNotFound;
BOOL deleteSuccess = [ingredients deleteIngredientAtGroupIndex:indexPath.section ingredientIndex:indexPath.row];
if (deleteSuccess)
{
logUserAction(@"ingredient_delete", [ingredientToDelete dictionaryForAnalytics]);

[tableView beginUpdates];
if (ingredientGroup.countOfIngredients == 0)
{
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else
{
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

if (needToDeleteFromRecents)
{
CSRecentsIngredientGroup *afterChangeRecents = ingredients.recents;
if (afterChangeRecents == nil)
{
[tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else
{
[tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:[beforeChangeRecents indexOfIngredient:ingredientToDelete] inSection:0]]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
[tableView endUpdates];
}
else
{
logIssue(@"ingredient_delete_fail", [ingredientToDelete dictionaryForAnalytics]);
}
}
}

- (void)editIngredient:(id)sender
{
UIViewController *editVC;
Expand Down
30 changes: 30 additions & 0 deletions CookSmart/CookSmart/CSIngredientsExt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CSIngredientsExt.swift
// cake
//
// Created by Alex King on 3/29/20.
// Copyright © 2020 Olga Galchenko. All rights reserved.
//

import Foundation

extension CSIngredient: Identifiable {
public var id: String { name }
}

extension CSIngredientGroup: Identifiable {
public var id: String { name }
}

extension CSIngredientGroup {
var ingredients: [CSIngredient] {
(0 ..< countOfIngredients()).map { ingredient(at: $0) }
}
}

extension CSIngredients {
var ingredientList: [CSIngredientGroup] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I would name it all or ingredientGroups, because ingredientList kinda looks like [CSIngredient].

let groups: [CSIngredientGroup] = (0 ..< countOfIngredientGroups()).map { ingredientGroup(at: $0) }
return groups
}
}
10 changes: 9 additions & 1 deletion CookSmart/CookSmart/CSScaleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ static inline CGFloat unitsPerPoint(CSScaleView *scaleView)

static inline CGFloat ptsPerUnit(CSScaleView *scaleView)
{
return (SCALE_TILE_HEIGHT/scaleView.unitsPerTile);
CGFloat pts = (SCALE_TILE_HEIGHT/scaleView.unitsPerTile);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... that sounds like we have some kind of a problem with the view lifecycle. It sounds like this is being called when unitsPerTile is zero?

if (isnan(pts)) {
return 0;
}
return pts;
}

static inline CGFloat getTargetContentOffset(CSScaleView *scaleView)
Expand All @@ -206,10 +210,14 @@ static inline CGFloat getTargetContentOffset(CSScaleView *scaleView)

static inline void setScrollViewOffset(CSScaleView *scaleView, CGPoint newContentOffset, BOOL cancelDeceleration)
{
if (isnan(newContentOffset.y)) {
return;
}
Comment on lines +213 to +215

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some weird crashes that I needed to fix with this. 🤷‍♂ Should be fine once this is converted to Swift

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

id delegate = scaleView.delegate;
scaleView.delegate = nil;
if (cancelDeceleration)
{
NSLog(@"%f", newContentOffset.y);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up.

[scaleView setContentOffset:newContentOffset animated:NO];
}
else
Expand Down
2 changes: 1 addition & 1 deletion CookSmart/CookSmart/Core/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
enum Color {
static let redLineColor = Color.color(
light: UIColor(red: 187.0 / 255.0, green: 1.0 / 255.0, blue: 3.0 / 255.0, alpha: 1.0),
dark: UIColor(red: 187.0 / 255.0, green: 1.0 / 255.0, blue: 3.0 / 255.0, alpha: 1.0)
dark: UIColor(red: 234.0 / 255.0, green: 110.0 / 255.0, blue: 104.0 / 255.0, alpha: 1.0)
)

static let background = Color.color(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
//

import Foundation
import SwiftUI

struct EditIngredientViewControllerRepresentable: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> EditIngredientViewController {
EditIngredientViewController()
}

func updateUIViewController(_ uiViewController: EditIngredientViewController, context: Context) {}
}

class EditIngredientViewController: UIViewController {

Expand Down
127 changes: 127 additions & 0 deletions CookSmart/CookSmart/IngredientListViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// IngredientListViewController.swift
// cake
//
// Created by Alex King on 3/28/20.
// Copyright © 2020 Olga Galchenko. All rights reserved.
//

import Foundation
import SwiftUI

class IngredientListViewController: UIHostingController<IngredientListView> {
init() {
super.init(rootView: IngredientListView())
}

@objc
dynamic required init?(coder _: NSCoder) {
assertionFailure("init(coder:) has not been implemented")
return nil
}

override func viewDidLoad() {
super.viewDidLoad()
CSIngredients.sharedInstance()?.refreshRecents()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, why is the CSIngredients optional? When might it be missing? Might it make sense to just throw when it's not available inside the sharedInstance implementation and leave the return type non-optional.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is the optional just the artifact of Objective C interop?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn't this go into viewWillAppear or something like that, i.e. wouldn't we want to refresh recents every time this view is shown.

}
}

struct IngredientListView: View {
@State private var searchText: String = ""

var body: some View {
NavigationView {
List {
SearchBar(text: $searchText)
ForEach(CSIngredients.sharedInstance()!.ingredientList) { group in
Section(header: Text(group.name)) {
ForEach(group.ingredients) { ingredient in
IngredientListCell(ingredientName: ingredient.name)
}
}
}
}
.listStyle(GroupedListStyle())
.navigationBarTitle("Ingredients")
.navigationBarItems(leading:
Button(action: {
print("Pressed")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fill in the action here.

}, label: {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope all this indentation looks better in XCode than it does here.

Image(systemName: "xmark")
.foregroundColor(SwiftUI.Color(Color.redLineColor))
.font(Font.system(size: 20, weight: .medium, design: .default))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we try Avenir here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why is there font in here at all? This is the closing X thing, right?

}),
trailing:
NavigationLink(destination: EditIngredientViewControllerRepresentable(),
label: { Image(systemName: "plus")
.foregroundColor(SwiftUI.Color(Color.redLineColor))
.font(Font.system(size: 20, weight: .medium, design: .default))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Why do we need a font here at all?

}))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we missing the "Reset to Defaults" button here somewhere?

}
}
}

struct IngredientListCell: View {
private let ingredientName: String

init(ingredientName: String = "Sugar") {
self.ingredientName = ingredientName
}

var body: some View {
ZStack {
NavigationLink(destination: EditIngredientViewControllerRepresentable()) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
HStack {
Text(ingredientName)
Spacer()
Button(action: {
print("Edit Tapped")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fill in action here.

}, label: {
Image(systemName: "pencil.circle")
.foregroundColor(SwiftUI.Color(Color.redLineColor))
.font(Font.system(size: 22, weight: .regular, design: .default))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question regarding font.

}).buttonStyle(BorderlessButtonStyle())
}
}
}
}

private struct SearchBar: UIViewRepresentable {
@Binding var text: String

class Coordinator: NSObject, UISearchBarDelegate {
@Binding var text: String

init(text: Binding<String>) {
_text = text
}

func searchBar(_: UISearchBar, textDidChange searchText: String) {
text = searchText
}
}

func makeCoordinator() -> SearchBar.Coordinator {
Coordinator(text: $text)
}

func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar {
let searchBar = UISearchBar(frame: .zero)
searchBar.placeholder = "Search"
searchBar.delegate = context.coordinator
searchBar.searchBarStyle = .minimal
return searchBar
}

func updateUIView(_ uiView: UISearchBar, context _: UIViewRepresentableContext<SearchBar>) {
uiView.text = text
}
}

struct IngredientListViewController_Previews: PreviewProvider {
static var previews: some View {
IngredientListView()
}
}
3 changes: 3 additions & 0 deletions CookSmart/CookSmart/cake-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
#import "CSIngredient.h"
#import "CSIngredients.h"
#import "CSIngredientListVC.h"
#import "CSIngredientGroup.h"
#import "CSRecentsIngredientGroup.h"
#import "CSIngredientGroupInternals.h"