Unverified Commit 4ed7c97a authored by Zach Knox's avatar Zach Knox
Browse files

I'm not going to do picker views because they're too much work

started on having a second view for selecting things instead, not done yet
parent 8c1e574a
......@@ -20,6 +20,7 @@
927C80DA1EB02566009079AD /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 927C80D91EB02566009079AD /* SettingsTableViewController.swift */; };
927C80DC1EB18B89009079AD /* FiltersTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */; };
929157221FF4662F00ED63C7 /* PickingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929157211FF4662F00ED63C7 /* PickingTableViewCell.swift */; };
92B2D2FF1FF8599500349E90 /* FilterSelectionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92B2D2FE1FF8599500349E90 /* FilterSelectionTableViewController.swift */; };
92EA81971FB7D1B500B1F6E3 /* PaddedUILabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92EA81961FB7D1B500B1F6E3 /* PaddedUILabel.swift */; };
92F681581FC1353700393DF4 /* Pods-WhatsOpen-acknowledgements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 92F681571FC1353700393DF4 /* Pods-WhatsOpen-acknowledgements.plist */; };
92F6815A1FC137CF00393DF4 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 92F681591FC137CF00393DF4 /* Settings.bundle */; };
......@@ -61,6 +62,7 @@
927C80D91EB02566009079AD /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = "<group>"; };
927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FiltersTableViewController.swift; sourceTree = "<group>"; };
929157211FF4662F00ED63C7 /* PickingTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickingTableViewCell.swift; sourceTree = "<group>"; };
92B2D2FE1FF8599500349E90 /* FilterSelectionTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterSelectionTableViewController.swift; sourceTree = "<group>"; };
92EA81961FB7D1B500B1F6E3 /* PaddedUILabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PaddedUILabel.swift; path = WhatsOpen/PaddedUILabel.swift; sourceTree = SOURCE_ROOT; };
92F681571FC1353700393DF4 /* Pods-WhatsOpen-acknowledgements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Pods-WhatsOpen-acknowledgements.plist"; path = "Pods/Target Support Files/Pods-WhatsOpen/Pods-WhatsOpen-acknowledgements.plist"; sourceTree = SOURCE_ROOT; };
92F681591FC137CF00393DF4 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
......@@ -112,6 +114,7 @@
9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */,
927C80D91EB02566009079AD /* SettingsTableViewController.swift */,
927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */,
92B2D2FE1FF8599500349E90 /* FilterSelectionTableViewController.swift */,
92182EBF1E95BD2C00192ABA /* FacilitiesListViewController.swift */,
);
path = Views;
......@@ -368,6 +371,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
92B2D2FF1FF8599500349E90 /* FilterSelectionTableViewController.swift in Sources */,
92182EC41E95C38400192ABA /* FacilityDetailViewController.swift in Sources */,
929157221FF4662F00ED63C7 /* PickingTableViewCell.swift in Sources */,
92108A331ED755F100675E16 /* CheckingTableViewCell.swift in Sources */,
......
......@@ -67,6 +67,17 @@
<outlet property="pickerView" destination="Rpt-Of-2BY" id="ek7-I8-MFW"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="toSelection" id="HkW-HK-Uqf">
<rect key="frame" x="0.0" y="300.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="HkW-HK-Uqf" id="3BF-KX-2nF">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<connections>
<segue destination="yIT-AR-gdn" kind="show" id="86R-Fz-PuY"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="jkQ-vu-LQa" id="DbO-38-R86"/>
......@@ -91,6 +102,34 @@
</objects>
<point key="canvasLocation" x="-8599.2000000000007" y="-349.47526236881561"/>
</scene>
<!--Filter Selection Table View Controller-->
<scene sceneID="4jA-Yu-4Hs">
<objects>
<tableViewController id="yIT-AR-gdn" customClass="FilterSelectionTableViewController" customModule="WhatsOpen" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="eE2-pe-hUF">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="selectingFilter" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="filterSelection" id="PMw-NR-MFe">
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="PMw-NR-MFe" id="6cy-eT-L9c">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="yIT-AR-gdn" id="Fhe-kA-hP5"/>
<outlet property="delegate" destination="yIT-AR-gdn" id="oaw-vU-qFm"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="5t1-ko-HSd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-8599" y="362"/>
</scene>
<!--What's Open-->
<scene sceneID="w5e-Fb-rsR">
<objects>
......
......@@ -16,11 +16,8 @@ class Filters {
var sortBy = SortMethod.alphabetical
var openFirst = true
// TODO: Deal with these
var onlyFromLocations = [String: Bool]() // Locations to show, could simply use Location objects instead if you wanted
var onlyFromCategories = [String: Bool]() //same as above, but for Categories, not Locations
//can check these using the .equals() functions in Locations and Categories
init() {
//nothing to do here
......@@ -29,7 +26,15 @@ class Filters {
func applyFiltersOnFacilities(_ facilities: [Facility]) -> [Facility] {
//TODO: Add checks for onlyFromLocations and onlyFromCategories here before doing the rest
let (open, closed) = separateOpenAndClosed(facilities)
var specifiedFacilities = [Facility]()
// facility must be within both a specified location and category
for f in facilities {
if(onlyFromLocations[(f.facilityLocation?.building)!] == true && onlyFromCategories[(f.category?.categoryName)!] == true) {
specifiedFacilities.append(f)
}
}
let (open, closed) = separateOpenAndClosed(specifiedFacilities)
// This switch statement figures out what sort method is being used, and will sort accordingly
switch sortBy {
......@@ -146,6 +151,26 @@ class Filters {
openFirst = to
return true
}
func setCategory(_ category: String?, to: Bool) -> Bool{
if(category != nil) {
onlyFromCategories[category!] = to
return true
}
else {
return false
}
}
func setLocation(_ location: String?, to: Bool) -> Bool{
if(location != nil) {
onlyFromLocations[location!] = to
return true
}
else {
return false
}
}
}
......
......@@ -14,7 +14,7 @@ class PickingTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewD
var pickerStrings: [String] = [String]()
var pickerItems: [Any?]! //literally just here for convienence
var pickerChecked = [Bool]() //Should I use a dictionary? maybe, but this is way easier
var pickFunc: ((String?) -> Bool)!
var pickFunc: ((String?, Bool) -> Bool)!
override func awakeFromNib() {
self.selectionStyle = .none
......@@ -45,7 +45,8 @@ class PickingTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewD
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerChecked[row] = !pickerChecked[row]
pickerView.showsSelectionIndicator = pickerChecked[row]
pickFunc(pickerStrings[row], pickerChecked[row])
pickerView.reloadComponent(component)
}
}
//
// FilterSelectionTableViewController.swift
// WhatsOpen
//
// Created by Zach Knox on 12/30/17.
// Copyright © 2017 SRCT. All rights reserved.
//
import UIKit
class FilterSelectionTableViewController: UITableViewController {
// Passing functions rather than direct objects to make this class reusable
var getFunc: (() -> [String: Bool])!
var selectFunc: ((String, Bool) -> Bool)!
var selectAllFunc: (() -> Bool)!
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 1 + getFunc().count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "filterSelection", for: indexPath)
let values = getFunc()
// Configure the cell...
if(indexPath.row == 0) {
cell.textLabel?.text = "Show All"
cell.accessoryType = .checkmark
for v in values {
if(v.value == false) {
cell.accessoryType = .none
break
}
}
}
else {
var i = 1
for v in values {
if i == indexPath.row {
cell.textLabel?.text = v.key
if(v.value == true) {
cell.accessoryType = .checkmark
}
else {
cell.accessoryType = .none
}
break
}
i += 1
}
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(indexPath.row == 0) {
selectAllFunc()
tableView.reloadData()
}
else {
let tableCell = self.tableView(tableView, cellForRowAt: indexPath)
var res: Bool
if(tableCell.accessoryType == .none) {
res = true
}
else {
res = false
}
selectFunc((tableCell.textLabel?.text)!, res)
tableView.reloadRows(at: [IndexPath(row: 0, section: 0), indexPath], with: .automatic)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
......@@ -174,7 +174,7 @@ class FiltersTableViewController: UITableViewController {
}
cell.pickerStrings = strings
cell.pickerChecked = items
cell.pickFunc = filters.setLocation
return cell
case 4: // TODO
let cell = tableView.dequeueReusableCell(withIdentifier: "picking", for: indexPath) as! PickingTableViewCell
......@@ -186,7 +186,7 @@ class FiltersTableViewController: UITableViewController {
}
cell.pickerStrings = strings
cell.pickerChecked = items
cell.pickFunc = filters.setCategory
return cell
default:
let cell = UITableViewCell() //this is bad don't let this happen
......@@ -199,7 +199,7 @@ class FiltersTableViewController: UITableViewController {
func updateOpenFirstEnabledState(_ to: Bool) -> Bool {
filters.setShowOpen(to)
var index = IndexPath(row: 0, section: 1)
let index = IndexPath(row: 0, section: 1)
tableView.reloadRows(at: [index], with: .automatic)
return true
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment