Archived
Added done button to keyboard in Customization View Controller, added code for Firebase notifications (non-functional without APNs key from a developer account)
This commit is contained in:
+33
-20
@@ -10,7 +10,7 @@ import UIKit
|
||||
import Firebase
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
@@ -19,27 +19,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
FirebaseApp.configure()
|
||||
|
||||
// if #available(iOS 10.0, *) {
|
||||
// // For iOS 10 display notification (sent via APNS)
|
||||
// UNUserNotificationCenter.current().delegate = self
|
||||
//
|
||||
// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
||||
// UNUserNotificationCenter.current().requestAuthorization(
|
||||
// options: authOptions,
|
||||
// completionHandler: {_, _ in })
|
||||
// } else {
|
||||
// let settings: UIUserNotificationSettings =
|
||||
// UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
||||
// application.registerUserNotificationSettings(settings)
|
||||
// }
|
||||
//
|
||||
// application.registerForRemoteNotifications()
|
||||
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions-ios")
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions-broadcast")
|
||||
Crashlytics.sharedInstance().setUserIdentifier(UserDefaults.standard.string(forKey: "username"))
|
||||
if #available(iOS 10.0, *) {
|
||||
// For iOS 10 display notification (sent via APNS)
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
||||
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
||||
UNUserNotificationCenter.current().requestAuthorization(
|
||||
options: authOptions,
|
||||
completionHandler: {_, _ in })
|
||||
} else {
|
||||
let settings: UIUserNotificationSettings =
|
||||
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
||||
application.registerUserNotificationSettings(settings)
|
||||
}
|
||||
|
||||
application.registerForRemoteNotifications()
|
||||
InstanceID.instanceID().instanceID { (result, error) in
|
||||
if let error = error {
|
||||
print("Error fetching remote instance ID: \(error)")
|
||||
} else if let result = result {
|
||||
print("Remote instance ID token: \(result.token)")
|
||||
}
|
||||
}
|
||||
Messaging.messaging().delegate = self
|
||||
return true
|
||||
}
|
||||
|
||||
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
|
||||
print("Firebase registration 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.
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
|
||||
@@ -163,12 +163,25 @@
|
||||
<connections>
|
||||
<outlet property="collectionView" destination="hWP-3N-RUn" id="RFo-DP-uPX"/>
|
||||
<outlet property="defaultSegments" destination="omP-RH-Hlh" id="hVo-ND-9EG"/>
|
||||
<outlet property="textToolbar" destination="cDy-2Q-2zk" id="UlY-Aa-f41"/>
|
||||
<outlet property="txtClasses" destination="bCV-w1-hVY" id="lDD-NQ-f8f"/>
|
||||
<outlet property="txtCourses" destination="69O-Fo-TQF" id="AC7-pO-Jms"/>
|
||||
<outlet property="txtName" destination="TpM-Mz-EpI" id="W0o-NR-E96"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="fIE-1y-qpc" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="cDy-2Q-2zk">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<items>
|
||||
<barButtonItem style="plain" systemItem="flexibleSpace" id="Tsa-Dg-qek"/>
|
||||
<barButtonItem systemItem="done" id="nSG-vf-dVd">
|
||||
<connections>
|
||||
<action selector="textDismissButton:" destination="8XB-jK-YFD" id="aXf-TS-Wxk"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</items>
|
||||
</toolbar>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="2691" y="-514"/>
|
||||
</scene>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import UIKit
|
||||
import MagazineLayout
|
||||
|
||||
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout {
|
||||
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout, UITextFieldDelegate {
|
||||
|
||||
var courses = [String]()
|
||||
var translatedCourses = [String]()
|
||||
@@ -24,6 +24,16 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
@IBOutlet weak var txtCourses: UITextField!
|
||||
@IBOutlet weak var defaultSegments: UISegmentedControl!
|
||||
|
||||
@IBOutlet weak var textToolbar: UIToolbar!
|
||||
|
||||
@IBAction func textDismissButton(_ sender: Any) {
|
||||
view.endEditing(true)
|
||||
}
|
||||
|
||||
func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
textField.inputAccessoryView = textToolbar
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
courses = self.df.courses
|
||||
@@ -45,6 +55,10 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
self.txtName.delegate = self
|
||||
self.txtClasses.delegate = self
|
||||
self.txtCourses.delegate = self
|
||||
|
||||
self.txtName.text = prefs.string(forKey: "username")
|
||||
self.txtClasses.text = prefs.string(forKey: "classes")
|
||||
self.txtCourses.text = prefs.string(forKey: "courses")
|
||||
|
||||
@@ -55,6 +55,7 @@ class DataFetcher {
|
||||
var infoList = [String]()
|
||||
var menuList = [String]()
|
||||
var isPersonalEmpty = true
|
||||
var personalPlanCount = 0
|
||||
do {
|
||||
let doc = try SwiftSoup.parse(html)
|
||||
|
||||
@@ -119,6 +120,7 @@ class DataFetcher {
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
_ = try db.run(insertPersonal)
|
||||
isPersonalEmpty = false
|
||||
personalPlanCount += 1
|
||||
}
|
||||
}
|
||||
} else if courses != nil && courses != "" && classes != nil && classes != "" {
|
||||
@@ -131,6 +133,7 @@ class DataFetcher {
|
||||
date <- mDate, time <- mTime, room <- mRoom)
|
||||
_ = try db.run(insertPersonal)
|
||||
isPersonalEmpty = false
|
||||
personalPlanCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +141,7 @@ class DataFetcher {
|
||||
|
||||
}
|
||||
|
||||
prefs.set(personalPlanCount, forKey: "personalPlanCount")
|
||||
if isPersonalEmpty {
|
||||
personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: ""))
|
||||
let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "")
|
||||
|
||||
@@ -46,6 +46,14 @@ class InfoViewController : UIViewController {
|
||||
self.df.doAsync(do: "info") { infoArray in
|
||||
self.content.text = infoArray[0] as? String
|
||||
self.refreshControl.endRefreshing()
|
||||
if let tabItems = self.tabBarController?.tabBar.items {
|
||||
let tabItem = tabItems[1]
|
||||
if self.prefs.integer(forKey: "personalPlanCount") != 0 {
|
||||
tabItem.badgeValue = "\(self.prefs.integer(forKey: "personalPlanCount"))"
|
||||
} else {
|
||||
tabItem.badgeValue = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
let layout = MagazineLayout()
|
||||
var collectionView: UICollectionView
|
||||
let identifier = "menu_cell"
|
||||
let prefs = UserDefaults.standard
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
||||
@@ -62,6 +63,14 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
self.items = menuItems as! [String]
|
||||
self.collectionView.reloadData()
|
||||
self.refreshControl.endRefreshing()
|
||||
if let tabItems = self.tabBarController?.tabBar.items {
|
||||
let tabItem = tabItems[1]
|
||||
if self.prefs.integer(forKey: "personalPlanCount") != 0 {
|
||||
tabItem.badgeValue = "\(self.prefs.integer(forKey: "personalPlanCount"))"
|
||||
} else {
|
||||
tabItem.badgeValue = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +92,6 @@ class MenuViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
return cell
|
||||
}
|
||||
|
||||
// generated stubs filled with return values
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeModeForItemAt indexPath: IndexPath) -> MagazineLayoutItemSizeMode {
|
||||
let widthMode = MagazineLayoutItemWidthMode.fullWidth(respectsHorizontalInsets: true)
|
||||
let heightMode = MagazineLayoutItemHeightMode.dynamic
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import UIKit
|
||||
import MagazineLayout
|
||||
import Crashlytics
|
||||
import Firebase
|
||||
|
||||
class PlanViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout {
|
||||
|
||||
@@ -16,6 +17,7 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
var substs = [SubstModel]()
|
||||
let refreshControl = UIRefreshControl()
|
||||
let df = DataFetcher.sharedInstance
|
||||
let planPrefs = UserDefaults.standard
|
||||
let layout = MagazineLayout()
|
||||
var collectionView: UICollectionView
|
||||
var url = ""
|
||||
@@ -33,12 +35,16 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions-ios")
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions-broadcast")
|
||||
Crashlytics.sharedInstance().setUserIdentifier(UserDefaults.standard.string(forKey: "username"))
|
||||
|
||||
view.addSubview(collectionView)
|
||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
collectionView.topAnchor.constraint(equalTo: view.topAnchor), // getToolbarBottomAnchor()),
|
||||
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
collectionView.register(UINib(nibName: "PlanViewCell", bundle: nil), forCellWithReuseIdentifier: identifier)
|
||||
@@ -80,6 +86,14 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
self.substs = substitutions as! [SubstModel]
|
||||
self.collectionView.reloadData()
|
||||
self.refreshControl.endRefreshing()
|
||||
if let tabItems = self.tabBarController?.tabBar.items {
|
||||
let tabItem = tabItems[1]
|
||||
if self.planPrefs.integer(forKey: "personalPlanCount") != 0 {
|
||||
tabItem.badgeValue = "\(self.planPrefs.integer(forKey: "personalPlanCount"))"
|
||||
} else {
|
||||
tabItem.badgeValue = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user