Archived
Setup screen scrolls up when keyboard would block textfields; fixed bug that would prevent a substitution from being shown if it contained a question mark (e.g.: 'INF7?inf999')
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
isa = PBXBuildRule;
|
||||
compilerSpec = com.apple.compilers.proxy.script;
|
||||
fileType = pattern.proxy;
|
||||
inputFiles = (
|
||||
);
|
||||
isEditable = 1;
|
||||
outputFiles = (
|
||||
);
|
||||
|
||||
@@ -109,17 +109,29 @@ class DataFetcher {
|
||||
return table.insert(group <- s.group, course <- s.course, additional <- s.additional, date <- s.date, time <- s.time, room <- s.room, teacher <- s.teacher, subst_type <- s.type, group_priority <- Int64(s.groupPriority), date_priority <- Int64(s.datePriority), website_priority <- Int64(s.websitePriority))
|
||||
}
|
||||
|
||||
private func isPersonal(with g: String, and c: String, for s: SubstModel) -> Bool {
|
||||
if !g.isEmpty && c.isEmpty {
|
||||
if !s.group.isEmpty {
|
||||
if g.contains(s.group) || s.group.contains(g) {
|
||||
private func isPersonal(with group: String, and course: String, for substitution: SubstModel) -> Bool {
|
||||
if !group.isEmpty && course.isEmpty {
|
||||
if !substitution.group.isEmpty {
|
||||
if group.contains(substitution.group) || substitution.group.contains(group) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if !g.isEmpty && !c.isEmpty {
|
||||
if s.group != "" && s.course != "" {
|
||||
if (g.contains(s.group) || s.group.contains(g)) && c.contains(s.course) {
|
||||
} else if !group.isEmpty && !course.isEmpty {
|
||||
if substitution.group != "" && substitution.course != "" {
|
||||
|
||||
if let qmark = substitution.course.firstIndex(of: "?") {
|
||||
if group.contains(substitution.group) || substitution.group.contains(group) {
|
||||
|
||||
if course.contains(substitution.course[..<qmark]) {
|
||||
return true
|
||||
} else if course.contains(substitution.course[substitution.course.index(qmark, offsetBy: 1)...]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (group.contains(substitution.group) || substitution.group.contains(group)) && course.contains(substitution.course) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ class FirstTimeViewController: UIViewController, UITextFieldDelegate {
|
||||
@IBOutlet weak var defaultPlanSegmentedControl: UISegmentedControl!
|
||||
@IBOutlet weak var textToolbar: UIToolbar!
|
||||
|
||||
var activeTextField: UITextField?
|
||||
|
||||
@IBAction func gradeInfoButton(_ sender: UIButton) {
|
||||
self.present(self.df.getInfoAlert(for: "grade"), animated: true)
|
||||
}
|
||||
@@ -34,6 +36,54 @@ class FirstTimeViewController: UIViewController, UITextFieldDelegate {
|
||||
|
||||
func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
textField.inputAccessoryView = textToolbar
|
||||
self.activeTextField = textField
|
||||
}
|
||||
|
||||
func textFieldDidEndEditing(_ textField: UITextField) {
|
||||
self.activeTextField = nil
|
||||
}
|
||||
|
||||
func registerForKeyboardNotifications(){
|
||||
//Adding notifies on keyboard appearing
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
}
|
||||
|
||||
func deregisterFromKeyboardNotifications(){
|
||||
//Removing notifies on keyboard appearing
|
||||
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc func keyboardWasShown(notification: NSNotification){
|
||||
//Need to calculate keyboard exact size due to Apple suggestions
|
||||
self.scrollView.isScrollEnabled = true
|
||||
let info = notification.userInfo!
|
||||
let keyboardSize = (info[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
|
||||
let contentInsets: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize!.height + self.textToolbar.frame.height, right: 0.0)
|
||||
|
||||
self.scrollView.contentInset = contentInsets
|
||||
self.scrollView.scrollIndicatorInsets = contentInsets
|
||||
|
||||
var aRect: CGRect = self.view.frame
|
||||
aRect.size.height -= keyboardSize!.height
|
||||
if let activeField = self.activeTextField {
|
||||
if (!aRect.contains(activeField.frame.origin)) {
|
||||
self.scrollView.scrollRectToVisible(activeField.frame, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func keyboardWillBeHidden(notification: NSNotification){
|
||||
//Once keyboard disappears, restore original positions
|
||||
let info = notification.userInfo!
|
||||
let keyboardSize = (info[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
|
||||
let contentInsets: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: -(keyboardSize!.height + self.textToolbar.frame.height), right: 0.0)
|
||||
self.scrollView.contentInset = contentInsets
|
||||
self.scrollView.scrollIndicatorInsets = contentInsets
|
||||
self.view.endEditing(true)
|
||||
self.scrollView.isScrollEnabled = false
|
||||
}
|
||||
|
||||
@IBAction func finishSetupButton(_ sender: UIBarButtonItem) {
|
||||
@@ -50,6 +100,11 @@ class FirstTimeViewController: UIViewController, UITextFieldDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
self.registerForKeyboardNotifications()
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@@ -59,4 +114,8 @@ class FirstTimeViewController: UIViewController, UITextFieldDelegate {
|
||||
self.scrollView.isDirectionalLockEnabled = true
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
self.deregisterFromKeyboardNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM
|
||||
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
super.loadView()
|
||||
self.collectionView.isPrefetchingEnabled = false
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
||||
if !self.prefs.bool(forKey: "logged_in") {
|
||||
@@ -101,6 +96,7 @@ class PlanViewController : UICollectionViewController, UICollectionViewDelegateM
|
||||
|
||||
self.collectionView.contentInsetAdjustmentBehavior = .always
|
||||
self.df.setTabBarBadge(for: self.tabBarController?.tabBar.items)
|
||||
self.collectionView.isPrefetchingEnabled = false
|
||||
}
|
||||
|
||||
func getViewType() -> String {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// UICollectionViewSubstitutionLayout.swift
|
||||
// AvH Plan
|
||||
//
|
||||
// Created by Deniz Duezgoeren on 22.10.19.
|
||||
// Copyright © 2019 Deniz Duezgoeren. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class UICollectionViewSubstitutionLayout: UICollectionViewFlowLayout {
|
||||
|
||||
override func
|
||||
}
|
||||
Reference in New Issue
Block a user