diff --git a/AvH Plan.xcodeproj/project.pbxproj b/AvH Plan.xcodeproj/project.pbxproj index baa4f7b..648c932 100644 --- a/AvH Plan.xcodeproj/project.pbxproj +++ b/AvH Plan.xcodeproj/project.pbxproj @@ -30,7 +30,6 @@ A9B0464E22E1F75A005FB0DB /* CustomizationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B0464D22E1F75A005FB0DB /* CustomizationViewController.swift */; }; A9B0465022E21207005FB0DB /* ColourPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B0464F22E21207005FB0DB /* ColourPickerView.swift */; }; A9B0465422E448EC005FB0DB /* GenericViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B0465322E448EC005FB0DB /* GenericViewCell.swift */; }; - A9C1D2FE22D656A400139043 /* InfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C1D2FD22D656A400139043 /* InfoViewController.swift */; }; A9C1D30022D656DD00139043 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C1D2FF22D656DD00139043 /* MenuViewController.swift */; }; A9C1D30222D7237200139043 /* DataFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C1D30122D7237200139043 /* DataFetcher.swift */; }; A9D830A722DE258C00D7EA05 /* PlanViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D830A522DE258C00D7EA05 /* PlanViewCell.swift */; }; @@ -101,7 +100,6 @@ A9B0464D22E1F75A005FB0DB /* CustomizationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomizationViewController.swift; sourceTree = ""; }; A9B0464F22E21207005FB0DB /* ColourPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColourPickerView.swift; sourceTree = ""; }; A9B0465322E448EC005FB0DB /* GenericViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericViewCell.swift; sourceTree = ""; }; - A9C1D2FD22D656A400139043 /* InfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoViewController.swift; sourceTree = ""; }; A9C1D2FF22D656DD00139043 /* MenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; A9C1D30122D7237200139043 /* DataFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataFetcher.swift; sourceTree = ""; }; A9D830A522DE258C00D7EA05 /* PlanViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanViewCell.swift; sourceTree = ""; }; @@ -193,7 +191,6 @@ A99AB5F7230155DE00555295 /* GoogleService-Info.plist */, A961337F2299867400B541D4 /* AppDelegate.swift */, A96133812299867400B541D4 /* PlanViewController.swift */, - A9C1D2FD22D656A400139043 /* InfoViewController.swift */, A9C1D2FF22D656DD00139043 /* MenuViewController.swift */, A96133852299867400B541D4 /* Main.storyboard */, A96133882299867A00B541D4 /* Assets.xcassets */, @@ -489,7 +486,6 @@ A9A3496C22D4859200F35AE0 /* SubstModel.swift in Sources */, A9C1D30022D656DD00139043 /* MenuViewController.swift in Sources */, A957A75122DDC15500E0A2ED /* MenuViewCell.swift in Sources */, - A9C1D2FE22D656A400139043 /* InfoViewController.swift in Sources */, A9B0464C22E1F255005FB0DB /* CustomTabBarController.swift in Sources */, A9D830A722DE258C00D7EA05 /* PlanViewCell.swift in Sources */, A96D4CC822DDE01A006BAB34 /* GeneralPlanViewController.swift in Sources */, diff --git a/AvH Plan/Base.lproj/Main.storyboard b/AvH Plan/Base.lproj/Main.storyboard index 1a2399d..e56b1a3 100644 --- a/AvH Plan/Base.lproj/Main.storyboard +++ b/AvH Plan/Base.lproj/Main.storyboard @@ -242,65 +242,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -377,6 +318,7 @@ + @@ -385,11 +327,7 @@ - - - - @@ -420,6 +358,6 @@ - + diff --git a/AvH Plan/DataFetcher.swift b/AvH Plan/DataFetcher.swift index 1530a17..9f679d3 100644 --- a/AvH Plan/DataFetcher.swift +++ b/AvH Plan/DataFetcher.swift @@ -151,8 +151,8 @@ class DataFetcher { prefs.set(personalPlanCount, forKey: "personalPlanCount") if isPersonalEmpty { - personalSubst.append(SubstModel(group: NSLocalizedString("personal_plan_empty", comment: ""), course: "", additional: "", date: "", time: "", room: "", teacher: "", type: "")) - let insertPersonal = personal.insert(group <- NSLocalizedString("personal_plan_empty", comment: ""), course <- "", additional <- "", date <- "", time <- "", room <- "", teacher <- "", substType <- "") + personalSubst.append(SubstModel(group: "", course: NSLocalizedString("personal_plan_empty", comment: ""), additional: "", date: "", time: "", room: "", teacher: "", type: "")) + let insertPersonal = personal.insert(group <- "", course <- NSLocalizedString("personal_plan_empty", comment: ""), additional <- "", date <- "", time <- "", room <- "", teacher <- "", substType <- "") try db.run(insertPersonal) } @@ -386,4 +386,26 @@ class DataFetcher { layer.shadowRadius = 1.5 layer.shadowOpacity = 0.7 } + + func presentInformationAlert(for tabBarController: UITabBarController, at index: Int) -> UIAlertController? { + if tabBarController.selectedIndex == 2 { + tabBarController.selectedIndex = index + let alert = UIAlertController(title: NSLocalizedString("information", comment: ""), message: self.readInformation(), preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("dismiss", comment: ""), style: .default) { action in + }) + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = NSTextAlignment.left + let messageText = NSMutableAttributedString( + string: self.readInformation(), + attributes: [ + NSAttributedString.Key.paragraphStyle: paragraphStyle, + NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: UIFont.TextStyle.caption1) + ] + ) + alert.setValue(messageText, forKey: "attributedMessage") + return alert + } else { + return nil + } + } } diff --git a/AvH Plan/InfoViewController.swift b/AvH Plan/InfoViewController.swift deleted file mode 100644 index f7b29ad..0000000 --- a/AvH Plan/InfoViewController.swift +++ /dev/null @@ -1,48 +0,0 @@ -// -// InfoViewController.swift -// AvH Plan -// -// Created by Deniz Duezgoeren on 10.07.19. -// Copyright © 2019 Deniz Duezgoeren. All rights reserved. -// - -import UIKit - -class InfoViewController : UIViewController { - - @IBOutlet weak var content: UILabel! - @IBOutlet weak var contentView: UIView! - @IBOutlet weak var scrollView: UIScrollView! - private let refreshControl = UIRefreshControl() - let df = DataFetcher.sharedInstance - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - if #available(iOS 10.0, *) { - scrollView.refreshControl = refreshControl - } else { - scrollView.addSubview(refreshControl) - } - refreshControl.addTarget(self, action: #selector(objDoAsync(_:)), for: .valueChanged) - refreshControl.tintColor = #colorLiteral(red: 0.07843137255, green: 0.5568627451, blue: 1, alpha: 1) - refreshControl.attributedTitle = NSAttributedString(string: NSLocalizedString("fetch_info", comment: "")) - self.scrollView.isDirectionalLockEnabled = true - content.text = df.readInformation() - } - - override func viewDidLoad() { - super.viewDidLoad() - self.extendedLayoutIncludesOpaqueBars = true - self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("information", comment: "") - let layer = contentView.layer - df.setCardFormatting(for: layer) - } - - @objc private func objDoAsync(_ sender: Any) { - self.df.doAsync(do: "info") { infoArray in - self.content.text = infoArray[0] as? String - self.refreshControl.endRefreshing() - self.df.setTabBarBadge(for: self.tabBarController?.tabBar.items) - } - } -} diff --git a/AvH Plan/MenuViewController.swift b/AvH Plan/MenuViewController.swift index 377f3fb..a72fefe 100644 --- a/AvH Plan/MenuViewController.swift +++ b/AvH Plan/MenuViewController.swift @@ -9,7 +9,7 @@ import UIKit import MagazineLayout -class MenuViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout { +class MenuViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout, UITabBarControllerDelegate { var items = [String]() private let refreshControl = UIRefreshControl() @@ -47,6 +47,7 @@ class MenuViewController : UICollectionViewController, UICollectionViewDelegateM refreshControl.addTarget(self, action: #selector(objDoAsync(_:)), for: .valueChanged) refreshControl.tintColor = #colorLiteral(red: 0.07843137255, green: 0.5568627451, blue: 1, alpha: 1) refreshControl.attributedTitle = NSAttributedString(string: NSLocalizedString("fetch_menu", comment: "")) + self.tabBarController?.delegate = self self.items = self.df.readMenu() self.collectionView.reloadData() @@ -68,6 +69,12 @@ class MenuViewController : UICollectionViewController, UICollectionViewDelegateM } } + func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) { + if let alert = self.df.presentInformationAlert(for: tabBarController, at: 3) { + self.present(alert, animated: true, completion: nil) + } + } + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.items.count } diff --git a/AvH Plan/PersonalPlanViewController.swift b/AvH Plan/PersonalPlanViewController.swift index 3ce1474..c90573c 100644 --- a/AvH Plan/PersonalPlanViewController.swift +++ b/AvH Plan/PersonalPlanViewController.swift @@ -40,4 +40,7 @@ class PersonalPlanViewController: PlanViewController { return df.getPersonalFromDatabase() } + override func getIndex() -> Int { + return 1 + } } diff --git a/AvH Plan/PlanViewController.swift b/AvH Plan/PlanViewController.swift index 03d8dc1..63ffc23 100644 --- a/AvH Plan/PlanViewController.swift +++ b/AvH Plan/PlanViewController.swift @@ -11,7 +11,7 @@ import MagazineLayout import Crashlytics import Firebase -class PlanViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout { +class PlanViewController : UICollectionViewController, UICollectionViewDelegateMagazineLayout, UITabBarControllerDelegate { let identifier = "plan_cell" var substs = [SubstModel]() @@ -57,6 +57,7 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM refreshControl.addTarget(self, action: #selector(objDoAsync(_:)), for: .valueChanged) refreshControl.tintColor = #colorLiteral(red: 0.07843137255, green: 0.5568627451, blue: 1, alpha: 1) refreshControl.attributedTitle = NSAttributedString(string: getRefreshViewString()) + self.tabBarController?.delegate = self self.substs = getFromDatabase() self.collectionView.reloadData() @@ -81,6 +82,10 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM return NSLocalizedString("fetch_plan", comment: "") } + func getIndex() -> Int { + return 0 + } + @objc private func objDoAsync(_ sender: Any) { self.df.doAsync(do: self.getViewType()) { substitutions in self.substs = substitutions as! [SubstModel] @@ -90,6 +95,12 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM } } + func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) { + if let alert = self.df.presentInformationAlert(for: tabBarController, at: self.getIndex()) { + self.present(alert, animated: true, completion: nil) + } + } + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.substs.count } diff --git a/AvH Plan/de.lproj/Localizable.strings b/AvH Plan/de.lproj/Localizable.strings index bba4774..85e197e 100644 --- a/AvH Plan/de.lproj/Localizable.strings +++ b/AvH Plan/de.lproj/Localizable.strings @@ -75,3 +75,4 @@ "last_updated" = "Zuletzt aktualisiert: "; "back" = "Zurück"; "your_plan" = "Dein Plan"; +"dismiss" = "Schließen"; diff --git a/AvH Plan/en.lproj/Localizable.strings b/AvH Plan/en.lproj/Localizable.strings index 71442d2..d5a5790 100644 --- a/AvH Plan/en.lproj/Localizable.strings +++ b/AvH Plan/en.lproj/Localizable.strings @@ -76,3 +76,4 @@ "last_updated" = "Last updated: "; "back" = "Back"; "your_plan" = "Your Plan"; +"dismiss" = "Dismiss";