Unverified Commit 91f1b476 authored by Zach Knox's avatar Zach Knox
Browse files

Alerts UI!

TODO: Specify which image to use and a background color, also just make it prettier
parent 44862e28
......@@ -16,6 +16,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Realm Migration in case we add more fields
let config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: 1,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 1) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
})
// Tell Realm to use this new configuration object for the default Realm
Realm.Configuration.defaultConfiguration = config
// Now that we've told Realm how to handle the schema change, opening the file
// will automatically perform the migration
let realm = try! Realm()
return true
}
......
{
"images" : [
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "major.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "major@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "major@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "warning.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "warning@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "warning@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -25,6 +25,8 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
var facilitiesArray = List<Facility>()
var alertsList = List<Alert>()
var currentAlerts = List<Alert>()
// array of facilities that pass the current filters
var filteredFacilities = List<Facility>()
......@@ -252,9 +254,25 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func reloadWithFilters() {
// Facilities
filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray)
shownFacilities = filteredFacilities
favoritesControlChanges(self)
// Alerts
let shown = List<Alert>()
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(identifier: "America/New_York")
let now = Date()
for alert in alertsList {
if now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!) {
shown.append(alert)
}
}
currentAlerts = shown
LocationsList.reloadData()
}
......@@ -461,7 +479,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
if alertsList.count > 0 {
if currentAlerts.count > 0 {
return 2
}
else {
......@@ -475,7 +493,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
else {
// TODO: get current alerts, not just any alerts
return alertsList.count
return currentAlerts.count
}
}
......@@ -551,7 +569,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
else {
// Do Alerts things here
return UICollectionViewCell() //This is bad
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Alert Cell", for: indexPath) as! AlertCollectionViewCell
cell.imageView.image = #imageLiteral(resourceName: "major")
cell.messageLabel.text = currentAlerts[indexPath.row].message
return cell
}
}
......@@ -666,5 +689,47 @@ extension FacilitiesListViewController: UISearchResultsUpdating {
}
}
// based on https://stackoverflow.com/questions/26198526/nsdate-comparison-using-swift
extension Date {
func isGreaterThanDate(dateToCompare: Date) -> Bool {
//Declare Variables
var isGreater = false
//Compare Values
if self.compare(dateToCompare) == ComparisonResult.orderedDescending {
isGreater = true
}
//Return Result
return isGreater
}
func isLessThanDate(dateToCompare: Date) -> Bool {
//Declare Variables
var isLess = false
//Compare Values
if self.compare(dateToCompare) == ComparisonResult.orderedAscending {
isLess = true
}
//Return Result
return isLess
}
func equalToDate(dateToCompare: Date) -> Bool {
//Declare Variables
var isEqualTo = false
//Compare Values
if self.compare(dateToCompare) == ComparisonResult.orderedSame {
isEqualTo = true
}
//Return Result
return isEqualTo
}
}
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