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

fixed migrations, first launch problems, and removed an unused button

parent a2cda322
......@@ -18,30 +18,6 @@ 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
_ = try! Realm()
return true
}
......
......@@ -347,19 +347,12 @@
<action selector="favoritesControlChanges:" destination="aaB-Go-aWd" eventType="valueChanged" id="5Ij-Z9-Gsa"/>
</connections>
</segmentedControl>
<barButtonItem key="rightBarButtonItem" title=" " id="vtX-VZ-RB4">
<color key="tintColor" red="0.0" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<action selector="RightButton:" destination="aaB-Go-aWd" id="47Y-7w-MFS"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="LastUpdatedLabel" destination="y4Z-i6-UYu" id="zCz-7O-cP3"/>
<outlet property="LeftButton" destination="v4j-oA-7Fa" id="EdI-if-QoB"/>
<outlet property="LocationsList" destination="naC-sZ-bcy" id="Wk4-kY-TeR"/>
<outlet property="LocationsListLayout" destination="eqw-AF-DSB" id="kLH-bz-bdn"/>
<outlet property="RightButton" destination="vtX-VZ-RB4" id="iv8-Xb-WoJ"/>
<outlet property="favoritesControl" destination="9BX-Nz-NN6" id="94S-gq-Nni"/>
<outlet property="navigationItem" destination="lS5-pu-Adr" id="4tw-ID-qgg"/>
<outlet property="settingsButton" destination="MHZ-t0-Moj" id="nyC-iO-GTe"/>
......
......@@ -21,7 +21,22 @@ class FacilitiesModel: Object {
class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIViewControllerPreviewingDelegate, UICollectionViewDelegateFlowLayout {
let realm = try! Realm()
// Tell Realm to use this new configuration object for the default Realm
let realm = try! Realm(configuration: 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) {
migration.enumerateObjects(ofType: "FacilitiesModel", { (oldObject, newObject) in
newObject!["alerts"] = List<Alert>()
})
}
}))
var facilitiesArray = List<Facility>()
var alertsList = List<Alert>()
......@@ -44,17 +59,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
@IBOutlet var LeftButton: UIBarButtonItem!
@IBAction func RightButton(_ sender: Any) {
}
@IBOutlet var RightButton: UIBarButtonItem!
@IBOutlet var settingsButton: UIBarButtonItem!
@IBOutlet var LocationsList: UICollectionView!
@IBOutlet var LocationsListLayout: UICollectionViewFlowLayout!
@IBOutlet var favoritesControl: UISegmentedControl!
var showFavorites = false
......@@ -122,6 +132,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
@IBAction func RefreshButton(_ sender: Any) {
refresh(sender, forceUpdate: true)
reloadWithFilters()
}
func checkFilterState() {
......@@ -340,7 +351,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
* Reloads data, either calling update() to attempt a download
* or simply pulling from the realm
*/
func refresh(_ sender: Any, forceUpdate: Bool = true) {
@objc func refresh(_ sender: Any, forceUpdate: Bool = true) {
refreshControl.beginRefreshing()
if(forceUpdate) {
update(sender);
......@@ -353,7 +364,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let alerts = model.alerts
let lastUpdated = model.lastUpdated
if((facilities.isEmpty && alerts.isEmpty) || lastUpdated.isLessThanDate(dateToCompare: Date(timeIntervalSinceNow: -86400.0))) {
if((facilities.isEmpty && alerts.isEmpty) || lastUpdated.isLessThanDate(dateToCompare: Date(timeIntervalSinceNow: -43200.0))) {
update(sender)
}
else {
......@@ -369,6 +380,13 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
updateFiltersLists()
reloadWithFilters()
refreshControl.endRefreshing()
}
func updateFiltersLists() {
// Add locations and categories to filters
for f in facilitiesArray {
if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) {
......@@ -378,9 +396,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
filters.onlyFromLocations.updateValue(true, forKey: (f.facilityLocation?.building)!)
}
}
reloadWithFilters()
refreshControl.endRefreshing()
}
/*
......@@ -398,6 +413,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let lastUpdated = model.lastUpdated
self.facilitiesArray = facilitiesFromDB
self.updateFiltersLists()
self.reloadWithFilters()
self.LastUpdatedLabel.title = "Updated: " + self.shortDateFormat(lastUpdated)
}
......@@ -411,7 +427,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
DispatchQueue.main.async {
let date = Date()
//self.reloadWithFilters()
self.LastUpdatedLabel.title = "Updated: " + self.shortDateFormat(date)
let results = self.realm.objects(FacilitiesModel.self)
......@@ -435,6 +450,8 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
fromRealm.lastUpdated = date
}
}
self.updateFiltersLists()
self.reloadWithFilters()
}
}
}
......@@ -474,6 +491,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
}
}
self.reloadWithFilters()
}
}
}
......
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