Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-ios
Commits
2d8fd574
Unverified
Commit
2d8fd574
authored
Sep 30, 2018
by
Zach Knox
Browse files
URL Schemes!
Open facilities with
whatsopen://open/?facility=FacilityNameHere
parent
e74fd696
Changes
6
Hide whitespace changes
Inline
Side-by-side
WhatsOpen/TodayWidget/TodayViewController.swift
View file @
2d8fd574
...
...
@@ -36,15 +36,36 @@ class TodayViewController: UIViewController, NCWidgetProviding, UITableViewDeleg
// Do any additional setup after loading the view from its nib.
tableView
.
reloadData
()
extensionContext
?
.
widgetLargestAvailableDisplayMode
=
.
expanded
}
func
widgetActiveDisplayModeDidChange
(
_
activeDisplayMode
:
NCWidgetDisplayMode
,
withMaximumSize
maxSize
:
CGSize
)
{
if
activeDisplayMode
==
.
expanded
{
self
.
preferredContentSize
=
tableView
.
contentSize
}
else
{
self
.
preferredContentSize
=
maxSize
}
}
func
widgetPerformUpdate
(
completionHandler
:
(
@escaping
(
NCUpdateResult
)
->
Void
))
{
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData
let
results
=
realm
.
objects
(
WOPFacilitiesModel
.
self
)
if
results
.
count
>
0
{
let
model
=
results
[
0
]
let
facilities
=
model
.
facilities
facilitiesArray
=
facilities
.
filter
({
(
facility
:
WOPFacility
)
->
Bool
in
return
WOPUtilities
.
isFavoriteFacility
(
facility
)
})
}
tableView
.
reloadData
()
completionHandler
(
NCUpdateResult
.
newData
)
}
...
...
@@ -60,7 +81,9 @@ class TodayViewController: UIViewController, NCWidgetProviding, UITableViewDeleg
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"todayWidgetCell"
,
for
:
indexPath
)
let
facility
=
facilitiesArray
[
indexPath
.
row
]
cell
.
textLabel
?
.
font
=
UIFont
.
preferredFont
(
forTextStyle
:
.
headline
)
cell
.
textLabel
!.
text
=
facility
.
facilityName
cell
.
detailTextLabel
?
.
font
=
UIFont
.
preferredFont
(
forTextStyle
:
.
body
)
let
isopen
=
WOPUtilities
.
isOpen
(
facility
:
facility
)
if
isopen
{
cell
.
detailTextLabel
!.
text
=
"Open"
...
...
@@ -70,5 +93,11 @@ class TodayViewController: UIViewController, NCWidgetProviding, UITableViewDeleg
return
cell
}
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
let
facilityName
=
tableView
.
cellForRow
(
at
:
indexPath
)?
.
textLabel
?
.
text
!
let
encodedName
=
facilityName
!.
addingPercentEncoding
(
withAllowedCharacters
:
.
urlQueryAllowed
)
!
let
url
=
URL
(
string
:
"whatsopen://open/?facility=
\(
encodedName
)
"
)
extensionContext
?
.
open
(
url
??
URL
(
string
:
"whatsopen://"
)
!
,
completionHandler
:
nil
)
}
}
WhatsOpen/WhatsOpen/AppDelegate.swift
View file @
2d8fd574
...
...
@@ -23,14 +23,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
// Override point for customization after application launch.
var
defaults
:
UserDefaults
#if APPSTORE
Fabric
.
with
([
Crashlytics
.
self
])
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
initAlerts
(
defaults
)
initCampuses
(
defaults
)
...
...
@@ -55,6 +52,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
func
application
(
_
app
:
UIApplication
,
open
url
:
URL
,
options
:
[
UIApplication
.
OpenURLOptionsKey
:
Any
]
=
[:])
->
Bool
{
let
base
=
URL
(
string
:
"/"
,
relativeTo
:
url
)?
.
absoluteString
if
base
==
"whatsopen://open/"
{
let
queryItems
=
URLComponents
(
url
:
url
,
resolvingAgainstBaseURL
:
true
)?
.
queryItems
let
facilityParam
=
queryItems
?
.
filter
({
$0
.
name
==
"facility"
})
.
first
if
facilityParam
!=
nil
{
NotificationCenter
.
default
.
post
(
Notification
(
name
:
Notification
.
Name
(
rawValue
:
"openFacilityFromURL"
),
object
:
url
,
userInfo
:
[
"facility"
:
facilityParam
!.
value
]))
return
true
}
return
false
}
else
{
return
false
}
}
func
initAlerts
(
_
defaults
:
UserDefaults
)
{
let
alerts
=
defaults
.
dictionary
(
forKey
:
"alerts"
)
if
alerts
==
nil
{
...
...
WhatsOpen/WhatsOpen/Info.plist
View file @
2d8fd574
...
...
@@ -22,6 +22,19 @@
<string>
APPL
</string>
<key>
CFBundleShortVersionString
</key>
<string>
1.2
</string>
<key>
CFBundleURLTypes
</key>
<array>
<dict>
<key>
CFBundleTypeRole
</key>
<string>
Editor
</string>
<key>
CFBundleURLName
</key>
<string>
whatsopen
</string>
<key>
CFBundleURLSchemes
</key>
<array>
<string>
whatsopen
</string>
</array>
</dict>
</array>
<key>
CFBundleVersion
</key>
<string>
40
</string>
<key>
Fabric
</key>
...
...
WhatsOpen/WhatsOpen/Views/Primary Views/FacilitiesListViewController.swift
View file @
2d8fd574
...
...
@@ -206,6 +206,39 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
update
(
notification
,
completion
:
toDetailCompletion
)
}
}
@objc
func
toDetailFromURL
(
_
notification
:
Notification
)
{
let
facilityEncoded
=
notification
.
userInfo
!
[
"facility"
]
as?
String
let
facilityDecoded
=
facilityEncoded
?
.
removingPercentEncoding
let
facility
=
realm
.
objects
(
WOPFacilitiesModel
.
self
)[
0
]
.
facilities
.
filter
(
NSPredicate
(
format
:
"facilityName = '"
+
(
facilityDecoded
)
!
+
"'"
))
.
first
if
(
facility
==
nil
)
{
return
// don't do anything
}
let
dest
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"detailView"
)
as!
FacilityDetailViewController
dest
.
facility
=
facility
!
let
detailViewWithButtons
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"detailViewButtons"
)
as?
DetailViewButtonsViewController
detailViewWithButtons
?
.
detailViewController
=
dest
detailViewWithButtons
?
.
facility
=
dest
.
facility
let
buttonDest
=
detailViewWithButtons
!
let
finalDestination
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"pulling"
)
as?
PullingViewController
// Fox only, no items
finalDestination
?
.
currentViewController
=
buttonDest
let
destDelegate
=
DeckTransitioningDelegate
(
isSwipeToDismissEnabled
:
true
,
dismissCompletion
:
begForReviews
)
finalDestination
?
.
modalPresentationStyle
=
.
custom
finalDestination
?
.
transitioningDelegate
=
destDelegate
// present the detail view over the search controller if we're searching
if
searchController
.
isActive
{
searchController
.
present
(
finalDestination
!
,
animated
:
true
,
completion
:
nil
)
}
else
{
present
(
finalDestination
!
,
animated
:
true
,
completion
:
nil
)
}
}
func
presentDetailView
(
_
destination
:
UIViewController
,
tapped
:
UICollectionViewCell
)
{
var
trueDest
:
UIViewController
if
destination
is
FacilityDetailViewController
{
...
...
@@ -276,6 +309,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
override
func
viewDidLoad
()
{
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
toDetailFromSearch(_:)
)
,
name
:
NSNotification
.
Name
(
rawValue
:
"launchToFacility"
),
object
:
nil
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
toDetailFromURL(_:)
)
,
name
:
NSNotification
.
Name
(
rawValue
:
"openFacilityFromURL"
),
object
:
nil
)
super
.
viewDidLoad
()
let
nc
=
NotificationCenter
.
default
...
...
WhatsOpen/WhatsOpenKit/DatabaseController.swift
View file @
2d8fd574
...
...
@@ -39,11 +39,11 @@ public class WOPDatabaseController {
return
config
}
public
static
func
getDefaults
(
_
isAppstore
:
Bool
=
false
)
->
UserDefaults
{
if
isAppstore
{
return
UserDefaults
.
init
(
suiteName
:
"group.edu.gmu.srct.whatsopen"
)
!
}
else
{
return
UserDefaults
.
standard
}
public
static
func
getDefaults
()
->
UserDefaults
{
#
if
APPSTORE
return
UserDefaults
.
init
(
suiteName
:
"group.edu.gmu.srct.whatsopen"
)
!
#
else
return
UserDefaults
.
standard
#endif
}
}
WhatsOpen/WhatsOpenKit/Utilities.swift
View file @
2d8fd574
...
...
@@ -259,12 +259,7 @@ public class WOPUtilities: NSObject {
true if the facility is a favorite, false if it isn't
*/
public
static
func
isFavoriteFacility
(
_
facility
:
WOPFacility
)
->
Bool
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
let
favoriteStrings
=
defaults
.
array
(
forKey
:
"favorites"
)
as!
[
String
]?
if
(
favoriteStrings
==
nil
)
{
return
false
...
...
@@ -286,12 +281,7 @@ public class WOPUtilities: NSObject {
return
false
}
else
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
favoriteStrings
=
defaults
.
array
(
forKey
:
"favorites"
)
as!
[
String
]?
if
(
favoriteStrings
==
nil
)
{
favoriteStrings
=
[]
...
...
@@ -310,12 +300,7 @@ public class WOPUtilities: NSObject {
*/
public
static
func
removeFavoriteFacility
(
_
facility
:
WOPFacility
)
->
Bool
{
if
(
isFavoriteFacility
(
facility
))
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
favoriteStrings
=
defaults
.
array
(
forKey
:
"favorites"
)
as!
[
String
]
let
removing
=
favoriteStrings
.
index
(
of
:
facility
.
facilityName
)
favoriteStrings
.
remove
(
at
:
removing
!
)
...
...
@@ -336,12 +321,7 @@ public class WOPUtilities: NSObject {
true if the alerts was added correctly.
*/
public
static
func
setAlertDefaults
(
_
key
:
String
,
value
:
Bool
)
->
Bool
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
alerts
=
defaults
.
dictionary
(
forKey
:
"alerts"
)
as!
[
String
:
Bool
]?
if
alerts
!=
nil
{
alerts
!.
updateValue
(
value
,
forKey
:
key
)
...
...
@@ -360,12 +340,7 @@ public class WOPUtilities: NSObject {
true if the alerts was changed correctly, false if nil was retrieved from User Defaults.
*/
public
static
func
setAllAlertDefaults
()
->
Bool
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
alerts
=
defaults
.
dictionary
(
forKey
:
"alerts"
)
as!
[
String
:
Bool
]?
if
alerts
!=
nil
{
...
...
@@ -394,12 +369,7 @@ public class WOPUtilities: NSObject {
item stored in User Defaults for key 'alerts'
*/
public
static
func
getAlertDefaults
()
->
[
String
:
Bool
]
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
let
returning
=
defaults
.
dictionary
(
forKey
:
"alerts"
)
as!
[
String
:
Bool
]?
if
returning
==
nil
{
return
[:]
...
...
@@ -419,12 +389,7 @@ public class WOPUtilities: NSObject {
true if the campus was added correctly.
*/
public
static
func
setCampusDefaults
(
_
key
:
String
,
value
:
Bool
)
->
Bool
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
campuses
=
defaults
.
dictionary
(
forKey
:
"campuses"
)
as!
[
String
:
Bool
]?
if
campuses
!=
nil
{
campuses
!.
updateValue
(
value
,
forKey
:
key
)
...
...
@@ -443,12 +408,7 @@ public class WOPUtilities: NSObject {
true if the campuses were changed correctly, false if nil was retrieved from User Defaults.
*/
public
static
func
setAllCampusDefaults
()
->
Bool
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
var
campuses
=
defaults
.
dictionary
(
forKey
:
"campuses"
)
as!
[
String
:
Bool
]?
if
campuses
!=
nil
{
...
...
@@ -477,12 +437,7 @@ public class WOPUtilities: NSObject {
item stored in User Defaults for key 'campuses'
*/
public
static
func
getCampusDefaults
()
->
[
String
:
Bool
]
{
var
defaults
:
UserDefaults
#if APPSTORE
defaults
=
WOPDatabaseController
.
getDefaults
(
true
)
#else
defaults
=
WOPDatabaseController
.
getDefaults
(
false
)
#endif
let
defaults
=
WOPDatabaseController
.
getDefaults
()
let
returning
=
defaults
.
dictionary
(
forKey
:
"campuses"
)
as!
[
String
:
Bool
]?
if
returning
==
nil
{
return
[:]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment