2019-07-21 21:14:38 +02:00
|
|
|
//
|
|
|
|
|
// CustomizationViewController.swift
|
|
|
|
|
// AvH Plan
|
|
|
|
|
//
|
|
|
|
|
// Created by Deniz Duezgoeren on 19.07.19.
|
|
|
|
|
// Copyright © 2019 Deniz Duezgoeren. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2019-10-13 16:53:08 +02:00
|
|
|
import Crashlytics
|
|
|
|
|
import Toast_Swift
|
2019-07-21 21:14:38 +02:00
|
|
|
|
2019-10-08 21:37:42 +02:00
|
|
|
class CustomizationViewController: UITableViewController, UITextFieldDelegate, UIAdaptivePresentationControllerDelegate {
|
2019-07-21 21:14:38 +02:00
|
|
|
|
|
|
|
|
let prefs = UserDefaults.standard
|
|
|
|
|
let df = DataFetcher.sharedInstance
|
2019-10-08 11:51:21 +02:00
|
|
|
var buttonTextChanged = false
|
2019-07-21 21:14:38 +02:00
|
|
|
|
|
|
|
|
@IBOutlet weak var txtName: UITextField!
|
|
|
|
|
@IBOutlet weak var txtClasses: UITextField!
|
|
|
|
|
@IBOutlet weak var txtCourses: UITextField!
|
2019-09-28 12:46:17 +02:00
|
|
|
@IBOutlet weak var defaultSwitch: UISwitch!
|
2019-08-21 19:36:56 +02:00
|
|
|
@IBOutlet weak var textToolbar: UIToolbar!
|
2019-09-25 19:17:23 +02:00
|
|
|
@IBOutlet weak var orderingSegments: UISegmentedControl!
|
|
|
|
|
@IBOutlet weak var autoRefreshToggle: UISwitch!
|
2019-10-08 11:51:21 +02:00
|
|
|
@IBOutlet weak var customizeCourseColorsButton: UIButton!
|
2019-08-21 19:36:56 +02:00
|
|
|
|
2019-09-20 18:11:27 +02:00
|
|
|
@IBAction func textDismissButton(_ sender: UIBarButtonItem) {
|
2019-08-21 19:36:56 +02:00
|
|
|
view.endEditing(true)
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 18:11:27 +02:00
|
|
|
@IBAction func groupHelpButton(_ sender: UIButton) {
|
2019-09-21 14:04:49 +02:00
|
|
|
self.present(self.df.getInfoAlert(for: "grade"), animated: true)
|
2019-09-20 18:11:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func courseHelpButton(_ sender: UIButton) {
|
2019-09-21 14:04:49 +02:00
|
|
|
self.present(self.df.getInfoAlert(for: "course"), animated: true)
|
2019-09-20 18:11:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-25 19:17:23 +02:00
|
|
|
@IBAction func orderHelpButton(_ sender: UIButton) {
|
|
|
|
|
self.present(self.df.getInfoAlert(for: "order"), animated: true)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 19:36:56 +02:00
|
|
|
func textFieldDidBeginEditing(_ textField: UITextField) {
|
|
|
|
|
textField.inputAccessoryView = textToolbar
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 21:14:38 +02:00
|
|
|
@IBAction func done(_ sender: UIBarButtonItem) {
|
|
|
|
|
self.dismiss(animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-28 12:46:17 +02:00
|
|
|
@IBAction func customizeColoursButton(_ sender: UIButton) {
|
|
|
|
|
if let s = storyboard?.instantiateViewController(withIdentifier: "CoursePickerViewController") as? CoursePickerViewController {
|
|
|
|
|
self.present(s, animated: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 11:51:21 +02:00
|
|
|
@IBAction func longPressListener(_ sender: UILongPressGestureRecognizer) {
|
|
|
|
|
sender.minimumPressDuration = 2
|
|
|
|
|
if sender.state == .ended {
|
|
|
|
|
if !buttonTextChanged {
|
|
|
|
|
self.customizeCourseColorsButton.setTitle(NSLocalizedString("made_by_deniz", comment: ""), for: .normal)
|
|
|
|
|
buttonTextChanged = true
|
|
|
|
|
} else {
|
|
|
|
|
self.customizeCourseColorsButton.setTitle(NSLocalizedString("customize_course_colors", comment: ""), for: .normal)
|
|
|
|
|
buttonTextChanged = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func infoLongPressListener(_ sender: UILongPressGestureRecognizer) {
|
|
|
|
|
sender.minimumPressDuration = 2
|
|
|
|
|
if sender.state == .ended {
|
|
|
|
|
let youtubeId = "Jc2xfYuLWgE"
|
|
|
|
|
if let youtubeURL = URL(string: "youtube://\(youtubeId)"),
|
|
|
|
|
UIApplication.shared.canOpenURL(youtubeURL) {
|
|
|
|
|
// redirect to app
|
|
|
|
|
UIApplication.shared.open(youtubeURL, options: [:], completionHandler: nil)
|
|
|
|
|
} else if let youtubeURL = URL(string: "https://www.youtube.com/watch?v=\(youtubeId)") {
|
|
|
|
|
// redirect through safari
|
|
|
|
|
UIApplication.shared.open(youtubeURL, options: [:], completionHandler: nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 16:53:08 +02:00
|
|
|
@IBAction func openHiddenInputDialog(_ sender: UILongPressGestureRecognizer) {
|
|
|
|
|
sender.minimumPressDuration = 2
|
|
|
|
|
if sender.state == .ended {
|
|
|
|
|
let alert = UIAlertController(title: NSLocalizedString("hidden_dialog_title", comment: ""), message: NSLocalizedString("hidden_dialog_desc", comment: ""), preferredStyle: .alert)
|
|
|
|
|
alert.addTextField { textField in }
|
|
|
|
|
alert.addAction(UIAlertAction(title: NSLocalizedString("apply", comment: ""), style: .default, handler: { [weak alert] (action) -> Void in
|
|
|
|
|
let toastMessage: String
|
|
|
|
|
switch alert!.textFields![0].text {
|
2019-10-13 17:33:17 +02:00
|
|
|
case "_firsttime":
|
2019-10-13 16:53:08 +02:00
|
|
|
self.prefs.set(false, forKey: "setup_finished")
|
|
|
|
|
toastMessage = "First time flag cleared"
|
|
|
|
|
break
|
2019-10-13 17:33:17 +02:00
|
|
|
case "_login":
|
2019-10-13 16:53:08 +02:00
|
|
|
self.prefs.set(false, forKey: "logged_in")
|
|
|
|
|
toastMessage = "Login flag cleared"
|
|
|
|
|
break
|
2019-10-13 17:33:17 +02:00
|
|
|
case "_devchannel":
|
2019-10-13 16:53:08 +02:00
|
|
|
let newValue = !self.prefs.bool(forKey: "subscribed_to_dev_channel")
|
|
|
|
|
self.prefs.set(newValue, forKey: "subscribed_to_dev_channel")
|
|
|
|
|
let sub: String
|
|
|
|
|
if newValue {
|
|
|
|
|
sub = "Subscribed to"
|
|
|
|
|
} else {
|
|
|
|
|
sub = "Unsubscribed from"
|
|
|
|
|
}
|
|
|
|
|
toastMessage = "\(sub) Firebase development channel"
|
|
|
|
|
break
|
2019-10-13 17:33:17 +02:00
|
|
|
case "_crash":
|
2019-10-13 16:53:08 +02:00
|
|
|
toastMessage = ""
|
|
|
|
|
Crashlytics.sharedInstance().crash()
|
|
|
|
|
break
|
2019-10-13 17:33:17 +02:00
|
|
|
case "_testurls":
|
2019-10-13 16:53:08 +02:00
|
|
|
let newValue = !self.prefs.bool(forKey: "use_test_urls")
|
|
|
|
|
self.prefs.set(newValue, forKey: "use_test_urls")
|
|
|
|
|
toastMessage = "Test URLs set to \(newValue)"
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
toastMessage = NSLocalizedString("invalid_code", comment: "")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
self.view.makeToast(toastMessage, position: .center)
|
|
|
|
|
}))
|
|
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 21:14:38 +02:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
2019-08-21 19:36:56 +02:00
|
|
|
self.txtName.delegate = self
|
|
|
|
|
self.txtClasses.delegate = self
|
|
|
|
|
self.txtCourses.delegate = self
|
|
|
|
|
|
2019-07-21 21:14:38 +02:00
|
|
|
self.txtName.text = prefs.string(forKey: "username")
|
|
|
|
|
self.txtClasses.text = prefs.string(forKey: "classes")
|
|
|
|
|
self.txtCourses.text = prefs.string(forKey: "courses")
|
2019-10-08 11:51:21 +02:00
|
|
|
self.defaultSwitch.isOn = self.prefs.integer(forKey: "default-plan") == 1 ? true : false
|
|
|
|
|
let order = self.prefs.bool(forKey: "original_sorting") ? 1 : 0
|
2019-09-25 19:17:23 +02:00
|
|
|
self.orderingSegments.selectedSegmentIndex = order
|
|
|
|
|
self.autoRefreshToggle.isOn = self.prefs.bool(forKey: "auto_refresh")
|
2019-10-08 21:37:42 +02:00
|
|
|
|
|
|
|
|
if #available(iOS 13.0, *) {
|
|
|
|
|
presentedViewController?.isModalInPresentation = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
|
|
super.viewWillDisappear(animated)
|
|
|
|
|
self.savePreferences()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func savePreferences() {
|
|
|
|
|
self.prefs.set(self.txtName.text, forKey: "username")
|
|
|
|
|
self.prefs.set(self.txtClasses.text, forKey: "classes")
|
|
|
|
|
self.prefs.set(self.txtCourses.text, forKey: "courses")
|
|
|
|
|
|
|
|
|
|
let defaultPlan = self.defaultSwitch.isOn ? 1 : 0
|
|
|
|
|
self.prefs.set(defaultPlan, forKey: "default-plan")
|
|
|
|
|
self.prefs.set(self.orderingSegments.selectedSegmentIndex == 1, forKey: "original_sorting")
|
|
|
|
|
self.prefs.set(self.autoRefreshToggle.isOn, forKey: "auto_refresh")
|
2019-07-21 21:14:38 +02:00
|
|
|
}
|
|
|
|
|
}
|