-
Notifications
You must be signed in to change notification settings - Fork 15
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/filter by animal type #90
base: develop
Are you sure you want to change the base?
Changes from all commits
636b506
0e9b375
775ddf0
cc0e8c1
ef09dd4
08152f7
0c852ca
4096a22
cb3f6fe
ce029b4
317abea
6123e6e
7c7a70a
759d558
cb3358e
b621d78
77066d7
4b6fb28
f15d898
31da2d4
1ef2470
8b4feb5
d39f3a1
bd8b2ef
50a3b0d
363b04b
de972fc
94889e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | |
|
||
navBar.barStyle = .black | ||
|
||
UIButton.appearance().tintColor = UIColor.themeTintColor() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to comment this line out because it causes tableviewCell checkmark accessory views and button labels to be white on white (and therefore invisible). I tried to solve this by setting the tint color of the table view and its cells locally, but that didn't work, so for now I just commented this line out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say just go ahead and remove the line instead. I'm not sure why we had UIButton appearances set to white. UIBarButtonItem appearances is fine to be white, since the navigation bar is not white. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the UIButton tintColor appearance setting 4b6fb28 |
||
UIBarButtonItem.appearance().tintColor = UIColor.themeTintColor() | ||
UITabBar.appearance().tintColor = UIColor.themePrimaryColor() | ||
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font:UIFont.themeNormalFont(ofSize: 10.0)], for: UIControlState.normal) | ||
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font:UIFont.themeNormalFont(ofSize: 10.0)], for: UIControlState.normal) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "filterIcon.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "[email protected]", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// | ||
// FilterViewController.swift | ||
// PetAdoption-iOS | ||
// | ||
// Created by Amir Fleminger on 4/11/18. | ||
// Copyright © 2018 Code For Orlando. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class FilterViewController: UITableViewController { | ||
var delegate: FilterSelectorDelegate? | ||
enum RowIndex:Int { | ||
case all = 0, dogs, cats, birds, smallFurry, horses, barnYard, reptiles, rabbits | ||
} | ||
|
||
var selectedAnimalTypes: Set<String> = [] | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
// Adding a footer removes redundant cell dividers from the tableview | ||
tableView.tableFooterView = UIView(frame: .zero) | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
selectedAnimalTypes = FilterViewController.loadAnimalTypesSelected() | ||
setAnimalTypeCheckmarks() | ||
} | ||
|
||
class func loadAnimalTypesSelected() -> Set<String>{ | ||
let defaults = UserDefaults.standard | ||
|
||
guard let data:Data = defaults.object(forKey: "selectedAnimalTypes") as? Data else { | ||
print("Couldnt load animal type preferences! Default to all animal types") | ||
return ["all"] | ||
} | ||
// convert the Data object to a Set<String> | ||
return NSKeyedUnarchiver.unarchiveObject(with: data) as! Set<String> | ||
} | ||
|
||
class func saveAnimalTypesSelected(_ selectedAnimalTypes_: Set<String>){ | ||
let defaults = UserDefaults.standard | ||
let encodedData = NSKeyedArchiver.archivedData(withRootObject: selectedAnimalTypes_) | ||
defaults.set(encodedData, forKey: "selectedAnimalTypes") | ||
defaults.synchronize() | ||
} | ||
|
||
func setAnimalTypeCheckmarks() { | ||
let section = 0 | ||
for row in 0...self.tableView.numberOfRows(inSection: section) - 1{ | ||
let indexPath = IndexPath(row: row, section: section) | ||
let cell = tableView.cellForRow(at: indexPath) | ||
|
||
if selectedAnimalTypes.contains("all"){ | ||
// put a checkmark only on the 'All' cell | ||
cell?.accessoryType = (indexPath.row == RowIndex.all.rawValue) ? .checkmark : .none | ||
} else { | ||
switch indexPath.row{ | ||
case RowIndex.dogs.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Dog") ? .checkmark : .none | ||
case RowIndex.cats.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Cat") ? .checkmark : .none | ||
case RowIndex.birds.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Bird") ? .checkmark : .none | ||
case RowIndex.smallFurry.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Small&Furry") ? .checkmark : .none | ||
case RowIndex.horses.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Horse") ? .checkmark : .none | ||
case RowIndex.barnYard.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("BarnYard") ? .checkmark : .none | ||
case RowIndex.reptiles.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Reptile") ? .checkmark : .none | ||
case RowIndex.rabbits.rawValue: | ||
cell?.accessoryType = selectedAnimalTypes.contains("Rabbit") ? .checkmark : .none | ||
default: | ||
cell?.accessoryType = .none | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
func resetSelectedAnimalTypes(){ | ||
selectedAnimalTypes = ["all"] | ||
} | ||
|
||
func toggleSelectedAnimalType(_ animalType:String){ | ||
if animalType == "all" { | ||
resetSelectedAnimalTypes() | ||
return | ||
} else { | ||
selectedAnimalTypes.remove("all") | ||
if selectedAnimalTypes.contains(animalType) { | ||
selectedAnimalTypes.remove(animalType) | ||
} else { | ||
selectedAnimalTypes.insert(animalType) | ||
} | ||
} | ||
if selectedAnimalTypes.count == 0 { | ||
resetSelectedAnimalTypes() | ||
} | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
switch indexPath.row { | ||
case RowIndex.all.rawValue: | ||
toggleSelectedAnimalType("all") | ||
case RowIndex.dogs.rawValue: | ||
toggleSelectedAnimalType("Dog") | ||
case RowIndex.cats.rawValue: | ||
toggleSelectedAnimalType("Cat") | ||
case RowIndex.birds.rawValue: | ||
toggleSelectedAnimalType("Bird") | ||
case RowIndex.smallFurry.rawValue: | ||
toggleSelectedAnimalType("Small&Furry") | ||
case RowIndex.horses.rawValue: | ||
toggleSelectedAnimalType("Horse") | ||
case RowIndex.barnYard.rawValue: | ||
toggleSelectedAnimalType("BarnYard") | ||
case RowIndex.reptiles.rawValue: | ||
toggleSelectedAnimalType("Reptile") | ||
case RowIndex.rabbits.rawValue: | ||
toggleSelectedAnimalType("Rabbit") | ||
default: | ||
print("no action") | ||
} | ||
setAnimalTypeCheckmarks() | ||
tableView.deselectRow(at: indexPath, animated: true) | ||
FilterViewController.saveAnimalTypesSelected(selectedAnimalTypes) | ||
delegate?.didChangeAnimalTypeSelections() | ||
} | ||
} | ||
|
||
|
||
protocol FilterSelectorDelegate { | ||
func didChangeAnimalTypeSelections() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, being nitpicky, but all the other groups are capitalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 8b4feb5