diff --git a/AvH Plan.xcodeproj/project.pbxproj b/AvH Plan.xcodeproj/project.pbxproj index 648c932..96ef2d0 100644 --- a/AvH Plan.xcodeproj/project.pbxproj +++ b/AvH Plan.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 1BF3A6CA97BA41C38482C1A6 /* Pods_AvH_PlanTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9D6269E96544A9242A29611 /* Pods_AvH_PlanTests.framework */; }; 2E65263AFD35D6B542E89AE4 /* Pods_AvH_Plan.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7605BB0678C9E27A1D3E9DAA /* Pods_AvH_Plan.framework */; }; + A9378D352336015000C07D07 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9378D342336015000C07D07 /* LoginViewController.swift */; }; + A9378D37233619F300C07D07 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9378D36233619F300C07D07 /* WebKit.framework */; }; + A9378D392336300700C07D07 /* FirstTimeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9378D382336300700C07D07 /* FirstTimeViewController.swift */; }; A957A75122DDC15500E0A2ED /* MenuViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957A74F22DDC15500E0A2ED /* MenuViewCell.swift */; }; A957A75222DDC15500E0A2ED /* MenuViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A957A75022DDC15500E0A2ED /* MenuViewCell.xib */; }; A958A92222DF5388007052B0 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A958A92422DF5388007052B0 /* Localizable.strings */; }; @@ -70,6 +73,9 @@ 589FBD2CE6A9C73CD9B81441 /* Pods-AvH PlanUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AvH PlanUITests.release.xcconfig"; path = "Target Support Files/Pods-AvH PlanUITests/Pods-AvH PlanUITests.release.xcconfig"; sourceTree = ""; }; 74EDE3D8134812AB76BEB988 /* Pods_AvH_PlanUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AvH_PlanUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7605BB0678C9E27A1D3E9DAA /* Pods_AvH_Plan.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AvH_Plan.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A9378D342336015000C07D07 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = ""; }; + A9378D36233619F300C07D07 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; + A9378D382336300700C07D07 /* FirstTimeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstTimeViewController.swift; sourceTree = ""; }; A957A74F22DDC15500E0A2ED /* MenuViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewCell.swift; sourceTree = ""; }; A957A75022DDC15500E0A2ED /* MenuViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MenuViewCell.xib; sourceTree = ""; }; A958A92322DF5388007052B0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -117,6 +123,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A9378D37233619F300C07D07 /* WebKit.framework in Frameworks */, 2E65263AFD35D6B542E89AE4 /* Pods_AvH_Plan.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -156,6 +163,7 @@ A7F8C8C9CE4E171D98EE659D /* Frameworks */ = { isa = PBXGroup; children = ( + A9378D36233619F300C07D07 /* WebKit.framework */, 7605BB0678C9E27A1D3E9DAA /* Pods_AvH_Plan.framework */, D9D6269E96544A9242A29611 /* Pods_AvH_PlanTests.framework */, 74EDE3D8134812AB76BEB988 /* Pods_AvH_PlanUITests.framework */, @@ -212,6 +220,8 @@ A9B0465322E448EC005FB0DB /* GenericViewCell.swift */, A9B033D622E4D0AB009ACF8A /* ColourViewCell.swift */, A9B033D722E4D0AB009ACF8A /* ColourViewCell.xib */, + A9378D342336015000C07D07 /* LoginViewController.swift */, + A9378D382336300700C07D07 /* FirstTimeViewController.swift */, ); path = "AvH Plan"; sourceTree = ""; @@ -483,6 +493,7 @@ A9B0465422E448EC005FB0DB /* GenericViewCell.swift in Sources */, A9B0464E22E1F75A005FB0DB /* CustomizationViewController.swift in Sources */, A96133802299867400B541D4 /* AppDelegate.swift in Sources */, + A9378D352336015000C07D07 /* LoginViewController.swift in Sources */, A9A3496C22D4859200F35AE0 /* SubstModel.swift in Sources */, A9C1D30022D656DD00139043 /* MenuViewController.swift in Sources */, A957A75122DDC15500E0A2ED /* MenuViewCell.swift in Sources */, @@ -493,6 +504,7 @@ A9C1D30222D7237200139043 /* DataFetcher.swift in Sources */, A96D4CCA22DDE184006BAB34 /* PersonalPlanViewController.swift in Sources */, A9B033D822E4D0AB009ACF8A /* ColourViewCell.swift in Sources */, + A9378D392336300700C07D07 /* FirstTimeViewController.swift in Sources */, A9B0465022E21207005FB0DB /* ColourPickerView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/Contents.json b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/Contents.json new file mode 100644 index 0000000..16b7390 --- /dev/null +++ b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "idea1x.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "idea2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "idea3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea1x.png b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea1x.png new file mode 100644 index 0000000..bed348f Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea1x.png differ diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea2x.png b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea2x.png new file mode 100644 index 0000000..6332ea8 Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea2x.png differ diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea3x.png b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea3x.png new file mode 100644 index 0000000..dc65a68 Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa.imageset/idea3x.png differ diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/Contents.json b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/Contents.json new file mode 100644 index 0000000..a6faa93 --- /dev/null +++ b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "whiteidea1x.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "whiteidea2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "whiteidea3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea1x.png b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea1x.png new file mode 100644 index 0000000..4196b92 Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea1x.png differ diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea2x.png b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea2x.png new file mode 100644 index 0000000..2ab739f Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea2x.png differ diff --git a/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea3x.png b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea3x.png new file mode 100644 index 0000000..d8040bf Binary files /dev/null and b/AvH Plan/Assets.xcassets/ic_idea_psa_white.imageset/whiteidea3x.png differ diff --git a/AvH Plan/Base.lproj/Main.storyboard b/AvH Plan/Base.lproj/Main.storyboard index 5f4657c..bcc61bf 100644 --- a/AvH Plan/Base.lproj/Main.storyboard +++ b/AvH Plan/Base.lproj/Main.storyboard @@ -84,14 +84,14 @@ - + - + @@ -356,7 +356,7 @@ - + @@ -445,6 +445,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AvH Plan/CustomizationViewController.swift b/AvH Plan/CustomizationViewController.swift index c409085..999e3b3 100644 --- a/AvH Plan/CustomizationViewController.swift +++ b/AvH Plan/CustomizationViewController.swift @@ -32,11 +32,11 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource, } @IBAction func groupHelpButton(_ sender: UIButton) { - self.present(self.getAlert(for: "grade"), animated: true) + self.present(self.df.getInfoAlert(for: "grade"), animated: true) } @IBAction func courseHelpButton(_ sender: UIButton) { - self.present(self.getAlert(for: "course"), animated: true) + self.present(self.df.getInfoAlert(for: "course"), animated: true) } func textFieldDidBeginEditing(_ textField: UITextField) { @@ -73,7 +73,7 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource, self.txtCourses.text = prefs.string(forKey: "courses") self.defaultSegments.selectedSegmentIndex = prefs.integer(forKey: "default-plan") - NotificationCenter.default.addObserver(self, selector: #selector(loadList), name:NSNotification.Name(rawValue: "load"), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil) } @objc func loadList(notification: NSNotification){ @@ -137,11 +137,4 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource, cell.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) return cell } - - func getAlert(for type: String) -> UIAlertController { - let alert = UIAlertController(title: NSLocalizedString("enter_\(type)_title", comment: ""), message: NSLocalizedString("enter_\(type)_help", comment: ""), preferredStyle: .alert) - alert.addAction(UIAlertAction(title: NSLocalizedString("dismiss", comment: ""), style: .default) { action in - }) - return alert - } } diff --git a/AvH Plan/DataFetcher.swift b/AvH Plan/DataFetcher.swift index f208f5a..928ebb0 100644 --- a/AvH Plan/DataFetcher.swift +++ b/AvH Plan/DataFetcher.swift @@ -400,4 +400,11 @@ class DataFetcher { return nil } } + + func getInfoAlert(for type: String) -> UIAlertController { + let alert = UIAlertController(title: NSLocalizedString("enter_\(type)_title", comment: ""), message: NSLocalizedString("enter_\(type)_help", comment: ""), preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("dismiss", comment: ""), style: .default) { action in + }) + return alert + } } diff --git a/AvH Plan/FirstTimeViewController.swift b/AvH Plan/FirstTimeViewController.swift new file mode 100644 index 0000000..bd97998 --- /dev/null +++ b/AvH Plan/FirstTimeViewController.swift @@ -0,0 +1,51 @@ +// +// FirstTimeViewController.swift +// AvH Plan +// +// Created by Deniz Duezgoeren on 21.09.19. +// Copyright © 2019 Deniz Duezgoeren. All rights reserved. +// + +import UIKit + +class FirstTimeViewController: UIViewController { + + + @IBOutlet weak var scrollView: UIScrollView! + let df = DataFetcher.sharedInstance + let prefs = UserDefaults.standard + + @IBAction func gradeInfoButton(_ sender: UIButton) { + self.present(self.df.getInfoAlert(for: "grade"), animated: true) + } + + @IBAction func courseInfoButton(_ sender: UIButton) { + self.present(self.df.getInfoAlert(for: "course"), animated: true) + } + + @IBOutlet weak var nameTextField: UITextField! + @IBOutlet weak var gradeTextField: UITextField! + @IBOutlet weak var courseTextField: UITextField! + @IBOutlet weak var defaultPlanSegmentedControl: UISegmentedControl! + + @IBAction func finishSetupButton(_ sender: UIBarButtonItem) { + self.prefs.set(self.nameTextField.text, forKey: "username") + self.prefs.set(self.gradeTextField.text, forKey: "classes") + self.prefs.set(self.courseTextField.text, forKey: "courses") + self.prefs.set(self.defaultPlanSegmentedControl.selectedSegmentIndex, forKey: "default-plan") + self.prefs.set(true, forKey: "setup_finished") + self.prefs.synchronize() + + if let s = storyboard?.instantiateViewController(withIdentifier: "AppTabBarController") as? CustomTabBarController { + self.present(s, animated: true) + } + } + + + override func viewDidLoad() { + super.viewDidLoad() + + self.scrollView.isDirectionalLockEnabled = true + } + +} diff --git a/AvH Plan/LoginViewController.swift b/AvH Plan/LoginViewController.swift new file mode 100644 index 0000000..57f28cb --- /dev/null +++ b/AvH Plan/LoginViewController.swift @@ -0,0 +1,41 @@ +// +// LoginViewController.swift +// AvH Plan +// +// Created by Deniz Duezgoeren on 21.09.19. +// Copyright © 2019 Deniz Duezgoeren. All rights reserved. +// + +import UIKit +import WebKit + +class LoginViewController: UIViewController, WKNavigationDelegate { + + @IBOutlet weak var webView: WKWebView! + let prefs = UserDefaults.standard + + override func viewDidLoad() { + super.viewDidLoad() + + let request = URLRequest(url: URL(string: "https://307.joomla.schule.bremen.de/index.php/component/users/#top")!) + self.webView.load(request) + self.webView.navigationDelegate = self + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + self.webView.configuration.websiteDataStore.httpCookieStore.getAllCookies { cookies in + for cookie in cookies { + if cookie.name == "joomla_user_state" && cookie.value == "logged_in" { + self.success() + } + } + } + } + + private func success() { + self.prefs.set(true, forKey: "logged_in") + if let s = storyboard?.instantiateViewController(withIdentifier: "FirstTime") as? UINavigationController { + self.present(s, animated: true) + } + } +} diff --git a/AvH Plan/PersonalPlanViewController.swift b/AvH Plan/PersonalPlanViewController.swift index ebf9095..5f9e45f 100644 --- a/AvH Plan/PersonalPlanViewController.swift +++ b/AvH Plan/PersonalPlanViewController.swift @@ -10,8 +10,6 @@ import UIKit class PersonalPlanViewController: PlanViewController { - let prefs = UserDefaults.standard - @IBAction func customize(_ sender: UIBarButtonItem) { if let s = storyboard?.instantiateViewController(withIdentifier: "Customize") as? CustomizationViewController { self.present(s, animated: true) diff --git a/AvH Plan/PlanViewController.swift b/AvH Plan/PlanViewController.swift index 63ffc23..2836940 100644 --- a/AvH Plan/PlanViewController.swift +++ b/AvH Plan/PlanViewController.swift @@ -21,6 +21,7 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM var url = "" var indexOfPSA: Int? = nil let cancellations = ["eigenverantwortliches arbeiten", "entfall", "entfällt", "fällt aus", "freisetzung", "vtr. ohne lehrer"] + let prefs = UserDefaults.standard required init?(coder decoder: NSCoder) { super.init(coder: decoder) @@ -28,12 +29,26 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM } override func viewWillAppear(_ animated: Bool) { + + + if !self.prefs.bool(forKey: "logged_in") { + if let s = storyboard?.instantiateViewController(withIdentifier: "Login") as? UINavigationController { + self.present(s, animated: true) + } + } else if !self.prefs.bool(forKey: "setup_finished") { + if let s = storyboard?.instantiateViewController(withIdentifier: "FirstTime") as? UINavigationController { + self.present(s, animated: true) + } + } + super.viewWillAppear(animated) - 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 + if self.prefs.bool(forKey: "logged_in") { + 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 = true @@ -65,6 +80,7 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM override func viewDidLoad() { super.viewDidLoad() + self.extendedLayoutIncludesOpaqueBars = true self.collectionView.contentInsetAdjustmentBehavior = .always self.df.setTabBarBadge(for: self.tabBarController?.tabBar.items) @@ -128,7 +144,7 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM url = "\(dateString[dateString.index(dateString.startIndex, offsetBy: 3)...])" indexOfPSA = indexPath.item } - image = UIImage(named: "ic_idea_w") + image = UIImage(named: "ic_idea_psa_white") cell.tintView.backgroundColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) cell.group.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) cell.course.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) @@ -195,9 +211,6 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM courseImage.append(NSAttributedString(string: " ")) let courseString = mutableStrings[2] courseImage.append(courseString) - if psa == true { - courseImage.addAttribute(NSAttributedString.Key.foregroundColor, value: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), range: NSMakeRange(0, 3)) - } courseText = courseImage } else {