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
|
|
|
|
|
import MagazineLayout
|
|
|
|
|
|
2019-08-21 19:36:56 +02:00
|
|
|
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout, UITextFieldDelegate {
|
2019-07-21 21:14:38 +02:00
|
|
|
|
2019-07-22 13:38:01 +02:00
|
|
|
var courses = [String]()
|
|
|
|
|
var translatedCourses = [String]()
|
2019-07-21 21:14:38 +02:00
|
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
|
|
|
let identifier = "customisation_cell"
|
|
|
|
|
let prefs = UserDefaults.standard
|
|
|
|
|
let df = DataFetcher.sharedInstance
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var txtName: UITextField!
|
|
|
|
|
@IBOutlet weak var txtClasses: UITextField!
|
|
|
|
|
@IBOutlet weak var txtCourses: UITextField!
|
|
|
|
|
@IBOutlet weak var defaultSegments: UISegmentedControl!
|
2019-08-21 19:36:56 +02:00
|
|
|
@IBOutlet weak var textToolbar: UIToolbar!
|
|
|
|
|
|
2019-09-20 18:11:27 +02:00
|
|
|
@IBOutlet weak var inputsView: UIView!
|
|
|
|
|
@IBOutlet weak var colourView: UIView!
|
|
|
|
|
|
|
|
|
|
@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-08-21 19:36:56 +02:00
|
|
|
func textFieldDidBeginEditing(_ textField: UITextField) {
|
|
|
|
|
textField.inputAccessoryView = textToolbar
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 21:14:38 +02:00
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
|
super.viewWillAppear(animated)
|
2019-07-22 13:38:01 +02:00
|
|
|
courses = self.df.courses
|
|
|
|
|
translatedCourses = self.df.translatedCourses
|
2019-07-21 21:14:38 +02:00
|
|
|
self.collectionView.register(UINib(nibName: "ColourViewCell", bundle: nil), forCellWithReuseIdentifier: identifier)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func done(_ sender: UIBarButtonItem) {
|
|
|
|
|
|
|
|
|
|
self.prefs.set(self.txtName.text, forKey: "username")
|
|
|
|
|
self.prefs.set(self.txtClasses.text, forKey: "classes")
|
|
|
|
|
self.prefs.set(self.txtCourses.text, forKey: "courses")
|
|
|
|
|
self.prefs.set(self.defaultSegments.selectedSegmentIndex, forKey: "default-plan")
|
|
|
|
|
|
|
|
|
|
self.prefs.synchronize()
|
|
|
|
|
self.dismiss(animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
self.defaultSegments.selectedSegmentIndex = prefs.integer(forKey: "default-plan")
|
2019-07-21 22:07:50 +02:00
|
|
|
|
2019-09-21 14:04:49 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil)
|
2019-07-21 22:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func loadList(notification: NSNotification){
|
|
|
|
|
self.collectionView.reloadItems(at: [notification.userInfo?["indexPath"] as! IndexPath])
|
2019-07-21 21:14:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
|
if let s = storyboard?.instantiateViewController(withIdentifier: "ColourPickerView") as? ColourPickerView {
|
2019-07-22 13:38:01 +02:00
|
|
|
s.course = self.translatedCourses[indexPath.item]
|
2019-07-21 21:14:38 +02:00
|
|
|
s.internalCourse = self.courses[indexPath.item]
|
2019-07-21 22:07:50 +02:00
|
|
|
s.currentIndexPath = indexPath
|
2019-07-21 21:14:38 +02:00
|
|
|
self.present(s, animated: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeModeForItemAt indexPath: IndexPath) -> MagazineLayoutItemSizeMode {
|
|
|
|
|
let widthMode = MagazineLayoutItemWidthMode.fullWidth(respectsHorizontalInsets: true)
|
|
|
|
|
let heightMode = MagazineLayoutItemHeightMode.dynamic
|
|
|
|
|
return MagazineLayoutItemSizeMode(widthMode: widthMode, heightMode: heightMode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, visibilityModeForHeaderInSectionAtIndex index: Int) -> MagazineLayoutHeaderVisibilityMode {
|
|
|
|
|
return .hidden
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, visibilityModeForFooterInSectionAtIndex index: Int) -> MagazineLayoutFooterVisibilityMode {
|
|
|
|
|
return .hidden
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, visibilityModeForBackgroundInSectionAtIndex index: Int) -> MagazineLayoutBackgroundVisibilityMode {
|
|
|
|
|
return .hidden
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, horizontalSpacingForItemsInSectionAtIndex index: Int) -> CGFloat {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, verticalSpacingForElementsInSectionAtIndex index: Int) -> CGFloat {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetsForSectionAtIndex index: Int) -> UIEdgeInsets {
|
|
|
|
|
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetsForItemsInSectionAtIndex index: Int) -> UIEdgeInsets {
|
|
|
|
|
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
|
return self.courses.count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! ColourViewCell
|
2019-07-22 13:38:01 +02:00
|
|
|
cell.label.text = self.translatedCourses[indexPath.item]
|
2019-07-21 21:14:38 +02:00
|
|
|
cell.colorView.layer.cornerRadius = cell.colorView.frame.height / 2
|
2019-07-22 13:38:01 +02:00
|
|
|
cell.colorView.layer.borderWidth = 0.4
|
|
|
|
|
cell.colorView.layer.borderColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)
|
2019-07-21 22:07:50 +02:00
|
|
|
cell.colorView.backgroundColor = self.df.getColourPalette()[prefs.integer(forKey: "colour-index-\(courses[indexPath.item])")]
|
2019-07-21 21:14:38 +02:00
|
|
|
cell.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
|
|
|
|
|
return cell
|
|
|
|
|
}
|
|
|
|
|
}
|