Unverified Commit f9281304 authored by Zach Knox's avatar Zach Knox
Browse files

Google Maps and Waze support for maps button

If you have either of the other apps installed, you can set them as your preferred mapping app in the app settings
parent fac09534
......@@ -43,6 +43,7 @@
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 */; };
9259134520784D66002E50B1 /* SelectOneDefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */; };
9265F3A11F2969E500A54A21 /* SettingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A01F2969E500A54A21 /* SettingTableViewCell.swift */; };
9265F3A31F2C0B1500A54A21 /* AboutScreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9265F3A21F2C0B1500A54A21 /* AboutScreenViewController.swift */; };
9270A4DB1EB5565400DFBDA3 /* SwitchingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9270A4DA1EB5565400DFBDA3 /* SwitchingTableViewCell.swift */; };
......@@ -93,6 +94,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>"; };
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>"; };
9270A4DA1EB5565400DFBDA3 /* SwitchingTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwitchingTableViewCell.swift; sourceTree = "<group>"; };
......@@ -178,6 +180,7 @@
927C80D91EB02566009079AD /* SettingsTableViewController.swift */,
927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */,
92B2D2FE1FF8599500349E90 /* FilterSelectionTableViewController.swift */,
9259134420784D66002E50B1 /* SelectOneDefaultTableViewController.swift */,
92182EBF1E95BD2C00192ABA /* FacilitiesListViewController.swift */,
);
path = Views;
......@@ -673,6 +676,7 @@
927C80DC1EB18B89009079AD /* FiltersTableViewController.swift in Sources */,
92B89E302009444E00928284 /* PullingViewController.swift in Sources */,
CD763A7E1DE253B900ADFD6B /* SRCTUtilities.swift in Sources */,
9259134520784D66002E50B1 /* SelectOneDefaultTableViewController.swift in Sources */,
927C80DA1EB02566009079AD /* SettingsTableViewController.swift in Sources */,
CD3C97491DC18AB300A84434 /* SRCTNetworkController.swift in Sources */,
CD763A7C1DE251C400ADFD6B /* SRCTSimpleTableViewCell.swift in Sources */,
......
<?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>
......@@ -28,6 +28,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let defaults = UserDefaults.standard
initAlerts(defaults)
initCampuses(defaults)
if defaults.value(forKey: "mapsApp") == nil {
defaults.set("Apple Maps", forKey: "mapsApp")
}
return true
}
......
......@@ -138,6 +138,35 @@
</objects>
<point key="canvasLocation" x="-8153" y="448"/>
</scene>
<!--Select One Default Table View Controller-->
<scene sceneID="XVT-Zz-bv3">
<objects>
<tableViewController id="irm-NL-2LQ" customClass="SelectOneDefaultTableViewController" 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="OEx-Rt-9S3">
<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" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="thereCanOnlyBeOne" id="Hzs-zq-KNQ">
<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="Hzs-zq-KNQ" id="U3O-ey-kO0">
<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="irm-NL-2LQ" id="TS4-il-abg"/>
<outlet property="delegate" destination="irm-NL-2LQ" id="8zp-cD-0dG"/>
</connections>
</tableView>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="v6f-sy-cSe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-7343" y="448"/>
</scene>
<!--What's Open-->
<scene sceneID="w5e-Fb-rsR">
<objects>
......@@ -394,6 +423,33 @@
<segue destination="yIT-AR-gdn" kind="show" identifier="settingSelection" id="FRf-a6-Dgs"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="settingDefaultCell" textLabel="thC-fo-X1p" detailTextLabel="yaK-Xw-Fsi" style="IBUITableViewCellStyleValue1" id="EKX-GL-oCV">
<rect key="frame" x="0.0" y="143.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EKX-GL-oCV" id="b50-wo-rdD">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="thC-fo-X1p">
<rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="yaK-Xw-Fsi">
<rect key="frame" x="296" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="irm-NL-2LQ" kind="show" identifier="settingDefault" id="wTS-KZ-Irl"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Lhp-lE-ieb" id="B56-3p-ltP"/>
......
......@@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>What's Open</string>
<string>What&apos;s Open</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
......@@ -63,5 +63,10 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
<string>waze</string>
</array>
</dict>
</plist>
......@@ -52,8 +52,20 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
}
@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
print("Lat: \(String(describing: facility.facilityLocation?.coordinates?.coords?.first)) Long: \(String(describing: facility.facilityLocation?.coordinates?.coords?.last))")
let coordinates = CLLocationCoordinate2DMake((facility.facilityLocation?.coordinates?.coords?.last)!, (facility.facilityLocation?.coordinates?.coords?.first)!)
dump(coordinates)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
......@@ -66,6 +78,7 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
mapItem.name = facility.facilityName
mapItem.openInMaps(launchOptions: options)
}
}
@IBAction func shareFacility(_ sender: Any) {
......@@ -142,7 +155,17 @@ class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITab
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
......
......@@ -15,6 +15,7 @@ class FilterSelectionTableViewController: UITableViewController {
var selectFunc: ((String, Bool) -> Bool)!
var selectAllFunc: (() -> Bool)!
var updateFacilities: (() -> Void)!
var canSelectAll = true
override func viewDidLoad() {
super.viewDidLoad()
......@@ -39,9 +40,11 @@ class FilterSelectionTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if canSelectAll {
return 1 + getFunc().count
}
return getFunc().count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
......@@ -49,12 +52,18 @@ class FilterSelectionTableViewController: UITableViewController {
let values = getFunc()
// Configure the cell...
if(indexPath.row == 0) {
if(indexPath.row == 0 && canSelectAll) {
cell.textLabel?.text = "Select All/None"
cell.accessoryType = .none
}
else {
var i = 1
var i: Int
if canSelectAll {
i = 1
}
else {
i = 0
}
for v in values {
if i == indexPath.row {
cell.textLabel?.text = v.key.capitalized
......@@ -77,6 +86,9 @@ class FilterSelectionTableViewController: UITableViewController {
if navigationItem.title == "Show Alerts" {
return "Emergency Alerts are always enabled in the app for your safety. We will never send a notification to your device without your consent."
}
else if navigationItem.title == "Select Maps App" {
return "The app selected here will be used when opening a map from a facility's detail page."
}
return nil
}
......
//
// SelectOneDefaultTableViewController.swift
// WhatsOpen
//
// Created by Zach Knox on 4/6/18.
// Copyright © 2018 SRCT. All rights reserved.
//
import UIKit
class SelectOneDefaultTableViewController: UITableViewController {
// Passing functions rather than direct objects to make this class reusable
var options: [String]!
var defaultKey: String!
let defaults = UserDefaults.standard
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 {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "thereCanOnlyBeOne", for: indexPath)
cell.textLabel?.text = options[indexPath.row]
if defaults.value(forKey: defaultKey) as! String == options[indexPath.row] {
cell.accessoryType = .checkmark
}
else {
cell.accessoryType = .none
}
return cell
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if navigationItem.title == "Select Maps App" {
return "The app selected here will be used when opening a map from a facility's detail page."
}
return nil
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
defaults.set(tableView.cellForRow(at: indexPath)?.textLabel?.text, forKey: defaultKey)
tableView.reloadData()
}
// 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.
if(segue.identifier == "toSelection") {
let destination = segue.destination as! FiltersTableViewController
destination.tableView.reloadData()
}
}
}
......@@ -55,7 +55,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
return 1
}
else if(section == 1) {
return 1
return 2
}
else if(section == 2) {
return 2
......@@ -76,10 +76,22 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
cell.textLabel!.text = "Are Our Hours Wrong?"
return cell
case 1:
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
cell.textLabel!.text = "Select App Icon"
cell.accessoryType = .disclosureIndicator
return cell
}
else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "settingDefaultCell", for: indexPath)
cell.textLabel!.text = "Select Maps App"
cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .body)
cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote)
cell.detailTextLabel?.text = UserDefaults.standard.value(forKey: "mapsApp") as? String
cell.accessoryType = .disclosureIndicator
return cell
}
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "settingSelection", for: indexPath)
cell.accessoryType = .disclosureIndicator
......@@ -281,6 +293,21 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
destination.updateFacilities = updateFacilities
}
}
else if segue.identifier == "settingDefault" {
if (sender as! UITableViewCell).textLabel?.text == "Select Maps App" {
let destination = segue.destination as! SelectOneDefaultTableViewController
destination.navigationItem.title = "Select Maps App"
destination.defaultKey = "mapsApp"
var options = ["Apple Maps"]
if UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
options.append("Google Maps")
}
if UIApplication.shared.canOpenURL(URL(string:"waze://")!) {
options.append("Waze")
}
destination.options = options
}
}
}
......
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