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/filter by animal type #90

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
636b506
add filter Icon
amirfl Apr 11, 2018
0e9b375
add filter bar button item
amirfl Apr 11, 2018
775ddf0
add popover with filter view controller
amirfl Apr 11, 2018
cc0e8c1
remove unnecesary navigation controller
amirfl Apr 11, 2018
ef09dd4
add filter view controller class
amirfl Apr 11, 2018
08152f7
remove appearance for UIButton
amirfl Apr 12, 2018
0c852ca
add filterVC
amirfl Apr 12, 2018
4096a22
handle animal type selection
amirfl Apr 12, 2018
cb3f6fe
add save and load selectedAnimalTypes to userdefaults
amirfl Apr 13, 2018
ce029b4
add FilterSelectorDelegate
amirfl Apr 13, 2018
317abea
add filtering functionality
amirfl Apr 13, 2018
6123e6e
fix segue to detail not using filtered results
amirfl Apr 13, 2018
7c7a70a
remove print statement
amirfl Apr 13, 2018
759d558
fix endless scrolling not working when watching filtered results
amirfl Apr 13, 2018
cb3358e
add no results placeholder
amirfl Apr 13, 2018
b621d78
add hide/show functionality to 'no results found' placeholder label
amirfl Apr 13, 2018
77066d7
add 'Rabbits' to filter options
amirfl Apr 14, 2018
4b6fb28
remove appearance tintColor setting for UIButton
amirfl Apr 18, 2018
f15d898
remove History.md
amirfl Apr 18, 2018
31da2d4
fix and change name of filterViewControlelr.swift to FilterViewContro…
amirfl Apr 18, 2018
1ef2470
refactor filterVC optional unwrapping with guard let statement
amirfl Apr 18, 2018
8b4feb5
refactor filter to Filter
amirfl Apr 18, 2018
d39f3a1
remove comment
amirfl Apr 18, 2018
bd8b2ef
refactor enum
amirfl Apr 18, 2018
50a3b0d
Fix: user can't deselect all animal types
amirfl Apr 18, 2018
363b04b
Extract load more items into new function
amirfl Apr 21, 2018
de972fc
add protection: do not allow fetching data in loadPets if currently i…
amirfl Apr 21, 2018
94889e0
fix filtered pets not loading by adding more fetch calls until filter…
amirfl Apr 22, 2018
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 PetAdoption-iOS/PetAdoption-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
42BC91261D67C7DA00B3B8FD /* PetCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42BC91251D67C7DA00B3B8FD /* PetCell.swift */; };
42C2522A1C8881DE00B2BE6D /* BackgroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C252291C8881DE00B2BE6D /* BackgroundView.swift */; };
42C2522C1C8899BD00B2BE6D /* TransparentNavBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C2522B1C8899BD00B2BE6D /* TransparentNavBar.swift */; };
6F2A704C207EB59700BF5AA0 /* FilterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F2A704B207EB59700BF5AA0 /* FilterViewController.swift */; };
90ADBC339006BDDE435B71C4 /* Pods_PetAdoption_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FCC61B47493AD9AFC8BA810 /* Pods_PetAdoption_iOS.framework */; };
942F6A6A205F46CD00F3179F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 942F6A69205F46CD00F3179F /* Constants.swift */; };
942F6A6B205F46CD00F3179F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 942F6A69205F46CD00F3179F /* Constants.swift */; };
Expand Down Expand Up @@ -150,6 +151,7 @@
42C252291C8881DE00B2BE6D /* BackgroundView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BackgroundView.swift; path = Views/BackgroundView.swift; sourceTree = "<group>"; };
42C2522B1C8899BD00B2BE6D /* TransparentNavBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TransparentNavBar.swift; path = Views/TransparentNavBar.swift; sourceTree = "<group>"; };
5FCC61B47493AD9AFC8BA810 /* Pods_PetAdoption_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PetAdoption_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6F2A704B207EB59700BF5AA0 /* FilterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FilterViewController.swift; path = Controllers/FilterViewController.swift; sourceTree = "<group>"; };
8AAD5FEFC48F2F2A23F42E1D /* Pods-PetAdoption-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PetAdoption-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PetAdoption-iOS/Pods-PetAdoption-iOS.debug.xcconfig"; sourceTree = "<group>"; };
925933A48637FAFF5BE6240D /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
942F6A69205F46CD00F3179F /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -340,6 +342,14 @@
name = Views;
sourceTree = "<group>";
};
6F2A704A207EB56D00BF5AA0 /* Filter */ = {
isa = PBXGroup;
children = (
6F2A704B207EB59700BF5AA0 /* FilterViewController.swift */,
);
name = filter;
sourceTree = "<group>";
};
942F6A68205F46B600F3179F /* Utilities */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -466,6 +476,7 @@
D0950AF71C618D86002E198C /* ViewControllers */ = {
isa = PBXGroup;
children = (
6F2A704A207EB56D00BF5AA0 /* filter */,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 8b4feb5

D0E5367F1C704206004794D8 /* LostPet */,
D0E5367E1C704200004794D8 /* Info */,
D0E5367D1C7041F9004794D8 /* Search */,
Expand Down Expand Up @@ -944,6 +955,7 @@
42ACC1AD1D68A8A3001C7C83 /* ReusableView.swift in Sources */,
42C2522C1C8899BD00B2BE6D /* TransparentNavBar.swift in Sources */,
42C2522A1C8881DE00B2BE6D /* BackgroundView.swift in Sources */,
6F2A704C207EB59700BF5AA0 /* FilterViewController.swift in Sources */,
42070E091D7470A100B02BA2 /* DescriptionCell.swift in Sources */,
D013BFA71C717935007C8808 /* ImageGalleryView.swift in Sources */,
42BC91261D67C7DA00B3B8FD /* PetCell.swift in Sources */,
Expand Down
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>
3 changes: 1 addition & 2 deletions PetAdoption-iOS/PetAdoption-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

navBar.barStyle = .black

UIButton.appearance().tintColor = UIColor.themeTintColor()
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Commenting this out, as a temporary solution, didn't seem to have any bad affect on the existing UI.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 142 additions & 0 deletions PetAdoption-iOS/PetAdoption-iOS/Controllers/FilterViewController.swift
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()
}
Loading