Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rantia/v3 redesign #34

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
70 changes: 42 additions & 28 deletions Grocery List.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

125 changes: 0 additions & 125 deletions Grocery List/Cells/ItemCell.swift

This file was deleted.

52 changes: 52 additions & 0 deletions Grocery List/Cells/ItemCellCollapsible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// ItemCellCollapsible.swift
// Grocery List
//
// Created by Rushad Antia on 9/6/20.
// Copyright © 2020 Rushad Antia. All rights reserved.

import Lightbox
import UIKit
import BEMCheckBox

class ItemCellCollapsible: UITableViewCell {

@IBOutlet var checkbox: BEMCheckBox!
@IBOutlet var itemLabel: UILabel!
@IBOutlet var itemImageView: UIImageView!
@IBOutlet var descriptionLabel: UILabel!
@IBOutlet var favoriteView: CircleView!

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}


class CircleView: UIView {

var circleColor: UIColor!
var favorite: Bool!

override func draw(_ rect: CGRect) {

let path = UIBezierPath(ovalIn: CGRect(x: 2, y: 2, width: 12, height: 12))
path.lineWidth = 1

if favorite {
circleColor.setStroke()
circleColor.setFill()
}
else {
#colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1).setStroke()
#colorLiteral(red: 0.9176470588, green: 0.9176470588, blue: 0.9176470588, alpha: 1).setFill()
}

path.fill()
path.stroke()
}
}
33 changes: 33 additions & 0 deletions Grocery List/Cells/StoreListHeader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// StoreListHeader.swift
// Grocery List
//
// Created by Rushad Antia on 9/4/20.
// Copyright © 2020 Rushad Antia. All rights reserved.

import UIKit

class StoreListHeader: UITableViewHeaderFooterView {
static let reuseIdentifier = String(describing: self)

var addButton: UIButton?

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)

addButton = UIButton()
contentView.addSubview(addButton!)

addButton?.translatesAutoresizingMaskIntoConstraints = false

addButton?.widthAnchor.constraint(equalToConstant: 24).isActive = true
addButton?.heightAnchor.constraint(equalToConstant: 24).isActive = true
addButton?.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor).isActive = true
addButton?.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor).isActive = true

}

required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
25 changes: 7 additions & 18 deletions Grocery List/Data Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class Category: Codable {
var name: String
var items: [Item]
var collapsed: Bool
var toAdd: Bool

init(name: String, items: [Item] = [Item](), collapsed: Bool = false) {
self.name = name.lowercased()
self.items = items
self.collapsed = collapsed
self.toAdd = collapsed
}

func getItems() -> [String] {
Expand All @@ -34,22 +34,11 @@ class Category: Codable {
return total
}

func pruneNonFavorites() {
var faves = [Item]()

for item in items {
if item.isFavorite {
faves.append(item)
}
}
items = faves
}

func resetFavorites() {
for item in items {
if item.isFavorite, item.isDone {
item.isDone = false
}
func removeNonFavorites() {
self.items = items.filter { $0.favorite }
for item in self.items {
item.isDone = false
}
}

}
40 changes: 23 additions & 17 deletions Grocery List/Data Models/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,56 @@ import UIKit
class Item: Codable {
var imageString: String?

var hasImage: Bool {
imageString != nil
}

var name: String
var isDone: Bool = false
var isFavorite: Bool

init(name: String, isFave: Bool, imageString: String, isDone: Bool) {
var description: String
var isExpanded: Bool = false // if there is image to expand
var favorite: Bool = false

init(name: String, imageString: String, isDone: Bool) {
self.name = name.lowercased()
self.imageString = imageString
self.isDone = isDone
isFavorite = isFave
self.description = ""
}

init(name: String, isFave: Bool, isDone: Bool) {
init(name: String, isDone: Bool) {
self.name = name.lowercased()
self.isDone = isDone
isFavorite = isFave
self.description = ""
}

init(name: String) {
self.name = name.lowercased()
isDone = false
isFavorite = false
self.description = ""
}

init(name: String, isFav: Bool) {
self.name = name
isDone = false
isFavorite = isFav
self.description = ""
}

init() {
name = ""
isDone = false
isFavorite = false
self.description = ""
}

init(name: String, imageString: String) {
init(name: String, imageString: String, _ description: String = "") {
self.name = name.lowercased()
self.imageString = imageString
isDone = false
isFavorite = false
self.description = description
}

func isExpandable() -> Bool {
return description != "" || hasImage()
}

func getImage() -> UIImage? {
if hasImage {
if hasImage() {
let newImageData = Data(base64Encoded: imageString!)
if let img = newImageData {
return UIImage(data: img)
Expand All @@ -66,8 +68,12 @@ class Item: Codable {
return nil
}

func hasImage() -> Bool {
return imageString != nil && imageString! != ""
}

func getGreyImage() -> UIImage? {
if hasImage {
if hasImage() {
let ciImage = CIImage(image: getImage()!)
let bw = ciImage!.applyingFilter("CIColorControls", parameters: ["inputSaturation": 0, "inputContrast": 1])
return UIImage(ciImage: bw)
Expand Down
27 changes: 12 additions & 15 deletions Grocery List/Data Models/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class Store: Codable {
category.items[itemIndex].name = newItemName
save()
}

public func getItem(indexPath: IndexPath) -> Item {
return self.categories[indexPath[0]].items[indexPath[1]]
}

public func deleteItem(category: String, item: Item) {
let items = getCategory(name: category)!.items
Expand Down Expand Up @@ -118,22 +122,8 @@ class Store: Codable {
}
}

public func finishShopping() {
for category in categories {
category.pruneNonFavorites()
category.resetFavorites()
}

save()
}

public func getCategories() -> [String] {
var categories = [String]()

for c in self.categories {
categories.append(c.name.lowercased())
}
return categories
return self.categories.map { c in c.name.lowercased()}
}

public func getNumNonDoneItems() -> Int {
Expand Down Expand Up @@ -192,4 +182,11 @@ class Store: Codable {
func save() {
DataStore.saveStoreData(store: self)
}

func finishShopping() {
self.categories.forEach { category in
category.removeNonFavorites()
}
save()
}
}
Loading