Commit 710480be authored by Zach Knox's avatar Zach Knox
Browse files

Merge branch 'no-buttons-in-peek' into 'dev-1.0.1'

buttons in detail view no longer display within a 3D Touch peek

See merge request !30
parents bd13a72b 8b2b138c
......@@ -40,6 +40,8 @@
92182EC01E95BD2C00192ABA /* FacilitiesListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92182EBF1E95BD2C00192ABA /* FacilitiesListViewController.swift */; };
92182EC41E95C38400192ABA /* FacilityDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92182EC31E95C38400192ABA /* FacilityDetailViewController.swift */; };
924840F81EA915F200DBFF4E /* FacilityCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924840F71EA915F200DBFF4E /* FacilityCollectionViewCell.swift */; };
924E0E312085851400C1F2AF /* DetailViewButtonsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924E0E302085851400C1F2AF /* DetailViewButtonsViewController.swift */; };
924E0E322085851500C1F2AF /* DetailViewButtonsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924E0E302085851400C1F2AF /* DetailViewButtonsViewController.swift */; };
92554183207ECEC30058E420 /* SelectOneDefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */; };
9259134520784D66002E50B1 /* SelectOneDefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */; };
9265F3A11F2969E500A54A21 /* SettingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */; };
......@@ -89,6 +91,7 @@
92182EBF1E95BD2C00192ABA /* FacilitiesListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FacilitiesListViewController.swift; sourceTree = "<group>"; };
92182EC31E95C38400192ABA /* FacilityDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FacilityDetailViewController.swift; sourceTree = "<group>"; };
924840F71EA915F200DBFF4E /* FacilityCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FacilityCollectionViewCell.swift; sourceTree = "<group>"; };
924E0E302085851400C1F2AF /* DetailViewButtonsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewButtonsViewController.swift; sourceTree = "<group>"; };
9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectOneDefaultTableViewController.swift; sourceTree = "<group>"; };
9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingTableViewCell.swift; sourceTree = "<group>"; };
9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutScreenViewController.swift; sourceTree = "<group>"; };
......@@ -170,6 +173,7 @@
92B89E2D20093E3600928284 /* AlertDetailViewController.swift */,
9281AD7B2002CF1700D09203 /* SetIconTableViewController.swift */,
92182EC31E95C38400192ABA /* FacilityDetailViewController.swift */,
924E0E302085851400C1F2AF /* DetailViewButtonsViewController.swift */,
9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */,
927C80D91EB02566009079AD /* SettingsTableViewController.swift */,
927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */,
......@@ -639,6 +643,7 @@
9203CB8B2023D51A006ACC3B /* FacilitiesListViewController.swift in Sources */,
9203CB8C2023D51A006ACC3B /* AlertDetailViewController.swift in Sources */,
9203CB8D2023D51A006ACC3B /* Model.swift in Sources */,
924E0E322085851500C1F2AF /* DetailViewButtonsViewController.swift in Sources */,
9203CB8E2023D51A006ACC3B /* AboutScreenViewController.swift in Sources */,
9203CB8F2023D51A006ACC3B /* PaddedUILabel.swift in Sources */,
9203CB912023D51A006ACC3B /* SetIconTableViewController.swift in Sources */,
......@@ -668,6 +673,7 @@
92182EC01E95BD2C00192ABA /* FacilitiesListViewController.swift in Sources */,
92B89E2E20093E3600928284 /* AlertDetailViewController.swift in Sources */,
CD763A7A1DE24EF100ADFD6B /* Model.swift in Sources */,
924E0E312085851400C1F2AF /* DetailViewButtonsViewController.swift in Sources */,
9265F3A31F2C0B1500A54A21 /* AboutScreenViewController.swift in Sources */,
92EA81971FB7D1B500B1F6E3 /* PaddedUILabel.swift in Sources */,
9281AD7C2002CF1700D09203 /* SetIconTableViewController.swift in Sources */,
......
//
// DetailViewButtonsViewController.swift
// WhatsOpen
//
// Created by Zach Knox on 4/16/18.
// Copyright © 2018 SRCT. All rights reserved.
//
import UIKit
import MapKit
class DetailViewButtonsViewController: UIViewController {
@IBOutlet var facilityDetailView: UIView!
var detailViewController: FacilityDetailViewController?
var facility: Facility!
@IBOutlet var favoritesButton: UIButton!
@IBOutlet var directionsButton: UIButton!
@IBOutlet var shareButton: UIButton!
/**
Favorites button touch handler
Adds a facility to favorites if it isn't a favorite,
removes from favorites if it is a favorite.
*/
@IBAction func setFavButton(_ sender: Any) {
if(Utilities.isFavoriteFacility(facility)) { // if the facility is a favorite
_ = Utilities.removeFavoriteFacility(facility) // remove it from favorites
}
else { // else add it to favorites
_ = Utilities.addFavoriteFacility(facility)
}
setFavoriteButtonText()
}
@IBAction func getDirections(_ sender: Any) {
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
if let url = URL(string: "comgooglemaps://?q=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
else if appToUse == "Waze" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
if let url = URL(string: "https://waze.com/ul?ll=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!))") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
else {
let regionDistance:CLLocationDistance = 100
let coordinates = CLLocationCoordinate2DMake((facility.facilityLocation?.coordinates?.coords?.last)!, (facility.facilityLocation?.coordinates?.coords?.first)!)
dump(coordinates)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = facility.facilityName
mapItem.openInMaps(launchOptions: options)
}
}
@IBAction func shareFacility(_ sender: Any) {
let str = "\(facility.facilityName) is \(Utilities.openOrClosedUntil(facility)!.lowercased())"
let shareSheet = UIActivityViewController(activityItems: ["\(str) https://whatsopen.gmu.edu/"], applicationActivities: nil)
shareSheet.excludedActivityTypes = [.print, .openInIBooks, .addToReadingList] // Sorry you can't print a Facility
present(shareSheet, animated: true, completion: nil)
}
/**
Change the favorite button text depending on if the facility is a favorite
*/
func setFavoriteButtonText() {
if(Utilities.isFavoriteFacility(facility)) {
favoritesButton.setTitle("Remove from Favorites", for: .normal)
favoritesButton.titleLabel?.text = "Remove from Favorites"
}
else {
favoritesButton.setTitle("Add to Favorites", for: .normal)
favoritesButton.titleLabel?.text = "Add to Favorites"
}
}
override func viewDidLoad() {
// Dealing with container views and subviews
// https://spin.atomicobject.com/2015/10/13/switching-child-view-controllers-ios-auto-layout/
self.detailViewController!.view.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.detailViewController!)
self.addSubview(self.detailViewController!.view, toView: self.facilityDetailView)
super.viewDidLoad()
setFavoriteButtonText()
favoritesButton.tintColor = UIColor.white
favoritesButton.backgroundColor = UIColor(red:0.00, green:0.40, blue:0.20, alpha:1.0)
favoritesButton.layer.cornerRadius = 10
directionsButton.tintColor = UIColor.white
directionsButton.backgroundColor = #colorLiteral(red: 0, green: 0.4793452024, blue: 0.9990863204, alpha: 1)
directionsButton.layer.cornerRadius = 10
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
directionsButton.setTitle("View in Google Maps", for: .normal)
}
else if appToUse == "Waze" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
directionsButton.setTitle("View in Waze", for: .normal)
}
else {
directionsButton.setTitle("View in Maps", for: .normal)
}
shareButton.tintColor = UIColor.white
shareButton.backgroundColor = UIColor.orange
shareButton.layer.cornerRadius = 10
shareButton.setImage(#imageLiteral(resourceName: "shareIcon"), for: .normal)
shareButton.setTitle("", for: .normal)
// Do any additional setup after loading the view.
}
func addSubview(_ subView: UIView, toView parentView: UIView) {
parentView.addSubview(subView)
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["subView"] = subView
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// 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.
}
*/
}
......@@ -183,26 +183,36 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func presentDetailView(_ destination: UIViewController, tapped: UICollectionViewCell) {
var trueDest: UIViewController
if destination is FacilityDetailViewController {
let detailViewWithButtons = self.storyboard?.instantiateViewController(withIdentifier: "detailViewButtons") as? DetailViewButtonsViewController
detailViewWithButtons?.detailViewController = (destination as! FacilityDetailViewController)
detailViewWithButtons?.facility = (destination as! FacilityDetailViewController).facility
trueDest = detailViewWithButtons!
}
else {
trueDest = destination
}
if(self.view.traitCollection.horizontalSizeClass == .regular && self.view.traitCollection.verticalSizeClass == .regular) {
//do a popover here for the iPad
//iPads are cool right?
destination.modalPresentationStyle = .popover
let popoverController = destination.popoverPresentationController
trueDest.modalPresentationStyle = .popover
let popoverController = trueDest.popoverPresentationController
popoverController?.permittedArrowDirections = .any
popoverController?.sourceView = tapped.contentView
popoverController?.sourceRect = tapped.bounds
// present the detail view over the search controller if we're searching
if searchController.isActive {
searchController.present(destination, animated: true, completion: nil)
searchController.present(trueDest, animated: true, completion: nil)
}
else {
present(destination, animated: true, completion: nil)
present(trueDest, animated: true, completion: nil)
}
}
else {
let finalDestination = self.storyboard?.instantiateViewController(withIdentifier: "pulling") as? PullingViewController // Fox only, no items
finalDestination?.currentViewController = destination
finalDestination?.currentViewController = trueDest
let destDelegate = DeckTransitioningDelegate()
finalDestination?.modalPresentationStyle = .custom
finalDestination?.transitioningDelegate = destDelegate
......@@ -871,13 +881,28 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
guard let facilityDetailView = viewControllerToCommit as? FacilityDetailViewController
else {
let finalDestination = self.storyboard?.instantiateViewController(withIdentifier: "pulling") as? PullingViewController // Fox only, no items
finalDestination?.currentViewController = viewControllerToCommit
let destDelegate = DeckTransitioningDelegate()
finalDestination?.modalPresentationStyle = .custom
finalDestination?.transitioningDelegate = destDelegate
//If one day 3D touch comes to the iPad, this is no longer good.
present(finalDestination!, animated: true, completion: nil)
return
}
let detailViewWithButtons = self.storyboard?.instantiateViewController(withIdentifier: "detailViewButtons") as? DetailViewButtonsViewController
detailViewWithButtons?.detailViewController = facilityDetailView
detailViewWithButtons?.facility = facilityDetailView.facility
let finalDestination = self.storyboard?.instantiateViewController(withIdentifier: "pulling") as? PullingViewController // Fox only, no items
finalDestination?.currentViewController = viewControllerToCommit
finalDestination?.currentViewController = detailViewWithButtons
let destDelegate = DeckTransitioningDelegate()
finalDestination?.modalPresentationStyle = .custom
finalDestination?.transitioningDelegate = destDelegate
//If one day 3D touch comes to the iPad, this is no longer good.
present(finalDestination!, animated: true, completion: nil)
}
}
......
......@@ -17,9 +17,7 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
@IBOutlet var OpenLabel: UILabel!
@IBOutlet var CategoryLabel: UILabel!
@IBOutlet var OpenTimesList: UITableView!
@IBOutlet var favoritesButton: UIButton!
@IBOutlet var directionsButton: UIButton!
@IBOutlet var shareButton: UIButton!
var facility: Facility!
......@@ -35,72 +33,7 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
return [favoritePreviewItem]
}
/**
Favorites button touch handler
Adds a facility to favorites if it isn't a favorite,
removes from favorites if it is a favorite.
*/
@IBAction func setFavButton(_ sender: Any) {
if(Utilities.isFavoriteFacility(facility)) { // if the facility is a favorite
_ = Utilities.removeFavoriteFacility(facility) // remove it from favorites
}
else { // else add it to favorites
_ = Utilities.addFavoriteFacility(facility)
}
setFavoriteButtonText()
}
@IBAction func getDirections(_ sender: Any) {
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
if let url = URL(string: "comgooglemaps://?q=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
else if appToUse == "Waze" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
if let url = URL(string: "https://waze.com/ul?ll=\((facility.facilityLocation?.coordinates?.coords?.last)!)),\((facility.facilityLocation?.coordinates?.coords?.first)!))") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
else {
let regionDistance:CLLocationDistance = 100
let coordinates = CLLocationCoordinate2DMake((facility.facilityLocation?.coordinates?.coords?.last)!, (facility.facilityLocation?.coordinates?.coords?.first)!)
dump(coordinates)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = facility.facilityName
mapItem.openInMaps(launchOptions: options)
}
}
@IBAction func shareFacility(_ sender: Any) {
let str = "\(facility.facilityName) is \(Utilities.openOrClosedUntil(facility)!.lowercased())"
let shareSheet = UIActivityViewController(activityItems: ["\(str) https://whatsopen.gmu.edu/"], applicationActivities: nil)
shareSheet.excludedActivityTypes = [.print, .openInIBooks, .addToReadingList] // Sorry you can't print a Facility
present(shareSheet, animated: true, completion: nil)
}
/**
Change the favorite button text depending on if the facility is a favorite
*/
func setFavoriteButtonText() {
if(Utilities.isFavoriteFacility(facility)) {
favoritesButton.setTitle("Remove from Favorites", for: .normal)
favoritesButton.titleLabel?.text = "Remove from Favorites"
}
else {
favoritesButton.setTitle("Add to Favorites", for: .normal)
favoritesButton.titleLabel?.text = "Add to Favorites"
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
......@@ -148,30 +81,6 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
OpenLabel.backgroundColor = UIColor(red:0.17, green:0.17, blue: 0.17, alpha: 1.0)
}
setFavoriteButtonText()
favoritesButton.tintColor = UIColor.white
favoritesButton.backgroundColor = UIColor(red:0.00, green:0.40, blue:0.20, alpha:1.0)
favoritesButton.layer.cornerRadius = 10
directionsButton.tintColor = UIColor.white
directionsButton.backgroundColor = #colorLiteral(red: 0, green: 0.4793452024, blue: 0.9990863204, alpha: 1)
directionsButton.layer.cornerRadius = 10
let appToUse = UserDefaults.standard.value(forKey: "mapsApp") as? String
if appToUse == "Google Maps" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
directionsButton.setTitle("View in Google Maps", for: .normal)
}
else if appToUse == "Waze" && UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
directionsButton.setTitle("View in Waze", for: .normal)
}
else {
directionsButton.setTitle("View in Maps", for: .normal)
}
shareButton.tintColor = UIColor.white
shareButton.backgroundColor = UIColor.orange
shareButton.layer.cornerRadius = 10
shareButton.setImage(#imageLiteral(resourceName: "shareIcon"), for: .normal)
shareButton.setTitle("", for: .normal)
OpenTimesList.bounces = false
if #available(iOS 11.0, *) {
......
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