diff --git a/AvH Plan/AppDelegate.swift b/AvH Plan/AppDelegate.swift index ec75064..04cbbb3 100644 --- a/AvH Plan/AppDelegate.swift +++ b/AvH Plan/AppDelegate.swift @@ -14,7 +14,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() @@ -48,7 +47,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) { print("Firebase registration token: \(fcmToken)") - let dataDict:[String: String] = ["token": fcmToken] + let dataDict: [String: String] = ["token": fcmToken] NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict) // TODO: If necessary send token to application server. // Note: This callback is fired at each app startup and whenever a new token is generated. diff --git a/AvH Plan/InfoViewController.swift b/AvH Plan/InfoViewController.swift index 68fd93c..7cefcec 100644 --- a/AvH Plan/InfoViewController.swift +++ b/AvH Plan/InfoViewController.swift @@ -32,6 +32,7 @@ class InfoViewController : UIViewController { override func viewDidLoad() { super.viewDidLoad() + self.extendedLayoutIncludesOpaqueBars = true self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("information", comment: "") let layer = contentView.layer layer.cornerRadius = 12.0 diff --git a/AvH Plan/MenuViewController.swift b/AvH Plan/MenuViewController.swift index 17330ef..c2352c6 100644 --- a/AvH Plan/MenuViewController.swift +++ b/AvH Plan/MenuViewController.swift @@ -9,29 +9,29 @@ import UIKit import MagazineLayout -class MenuViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout { +class MenuViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout { var items = [String]() private let refreshControl = UIRefreshControl() let df = DataFetcher.sharedInstance let layout = MagazineLayout() - var collectionView: UICollectionView let identifier = "menu_cell" required init?(coder decoder: NSCoder) { - collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) super.init(coder: decoder) + collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) view.addSubview(collectionView) - collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.translatesAutoresizingMaskIntoConstraints = true + NSLayoutConstraint.activate([ collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - collectionView.topAnchor.constraint(equalTo: view.topAnchor), + collectionView.topAnchor.constraint(equalTo: view.superview!.topAnchor), collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) collectionView.register(UINib(nibName: "MenuViewCell", bundle: nil), forCellWithReuseIdentifier: identifier) @@ -54,6 +54,8 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle override func viewDidLoad() { super.viewDidLoad() + self.extendedLayoutIncludesOpaqueBars = true + self.collectionView.contentInsetAdjustmentBehavior = .always self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("food_menu", comment: "") } @@ -66,11 +68,11 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle } } - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.items.count } - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! MenuViewCell cell.content.text = self.items[indexPath.item] diff --git a/AvH Plan/PlanViewController.swift b/AvH Plan/PlanViewController.swift index 64b9392..fd2b828 100644 --- a/AvH Plan/PlanViewController.swift +++ b/AvH Plan/PlanViewController.swift @@ -11,20 +11,19 @@ import MagazineLayout import Crashlytics import Firebase -class PlanViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout { +class PlanViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout { let identifier = "plan_cell" var substs = [SubstModel]() let refreshControl = UIRefreshControl() let df = DataFetcher.sharedInstance let layout = MagazineLayout() - var collectionView: UICollectionView var url = "" var indexOfPSA: Int? = nil required init?(coder decoder: NSCoder) { - collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) super.init(coder: decoder) + collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) } override func viewWillAppear(_ animated: Bool) { @@ -33,13 +32,15 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle Messaging.messaging().subscribe(toTopic: "substitutions-ios") Messaging.messaging().subscribe(toTopic: "substitutions-broadcast") Crashlytics.sharedInstance().setUserIdentifier(UserDefaults.standard.string(forKey: "username")) + // check if these can be put in AppDelegate view.addSubview(collectionView) - collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.translatesAutoresizingMaskIntoConstraints = true + NSLayoutConstraint.activate([ collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - collectionView.topAnchor.constraint(equalTo: view.topAnchor), + collectionView.topAnchor.constraint(equalTo: view.superview!.topAnchor), collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) collectionView.register(UINib(nibName: "PlanViewCell", bundle: nil), forCellWithReuseIdentifier: identifier) @@ -62,7 +63,8 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle override func viewDidLoad() { super.viewDidLoad() - + self.extendedLayoutIncludesOpaqueBars = true + self.collectionView.contentInsetAdjustmentBehavior = .always self.df.setTabBarBadge(for: self.tabBarController?.tabBar.items) } @@ -87,21 +89,19 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle } } - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.substs.count } - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { if indexOfPSA == indexPath.item { UIApplication.shared.open(URL(string: url)!) } } - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! PlanViewCell - var psa = false - let course = self.substs[indexPath.item].course var image = df.getImage(from: course) @@ -189,8 +189,6 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle return cell } - // stubs - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeModeForItemAt indexPath: IndexPath) -> MagazineLayoutItemSizeMode { var widthMode: MagazineLayoutItemWidthMode if UIDevice.current.userInterfaceIdiom == .pad { // iPad