Archived
Attempt to fix jumpy pull-to-refresh behaviour, revamped settings page to suit the iOS design better
This commit is contained in:
@@ -7,28 +7,20 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MagazineLayout
|
||||
|
||||
class CustomizationViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateMagazineLayout, UITextFieldDelegate {
|
||||
class CustomizationViewController: UITableViewController, UITextFieldDelegate {
|
||||
|
||||
var courses = [String]()
|
||||
var translatedCourses = [String]()
|
||||
@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!
|
||||
@IBOutlet weak var defaultSwitch: UISwitch!
|
||||
@IBOutlet weak var textToolbar: UIToolbar!
|
||||
@IBOutlet weak var orderingSegments: UISegmentedControl!
|
||||
@IBOutlet weak var autoRefreshToggle: UISwitch!
|
||||
|
||||
@IBOutlet weak var inputsView: UIView!
|
||||
@IBOutlet weak var colourView: UIView!
|
||||
|
||||
@IBAction func textDismissButton(_ sender: UIBarButtonItem) {
|
||||
view.endEditing(true)
|
||||
}
|
||||
@@ -49,26 +41,31 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
textField.inputAccessoryView = textToolbar
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
courses = self.df.courses
|
||||
translatedCourses = self.df.translatedCourses
|
||||
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")
|
||||
|
||||
var defaultPlan: Int
|
||||
if self.defaultSwitch.isOn {
|
||||
defaultPlan = 1
|
||||
} else {
|
||||
defaultPlan = 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")
|
||||
|
||||
self.prefs.synchronize()
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
@IBAction func customizeColoursButton(_ sender: UIButton) {
|
||||
if let s = storyboard?.instantiateViewController(withIdentifier: "CoursePickerViewController") as? CoursePickerViewController {
|
||||
self.present(s, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@@ -79,7 +76,11 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
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")
|
||||
if self.prefs.integer(forKey: "default-plan") == 1 {
|
||||
self.defaultSwitch.isOn = true
|
||||
} else {
|
||||
self.defaultSwitch.isOn = false
|
||||
}
|
||||
var order: Int
|
||||
if self.prefs.bool(forKey: "original_sorting") {
|
||||
order = 1
|
||||
@@ -88,69 +89,5 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
}
|
||||
self.orderingSegments.selectedSegmentIndex = order
|
||||
self.autoRefreshToggle.isOn = self.prefs.bool(forKey: "auto_refresh")
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil)
|
||||
}
|
||||
|
||||
@objc func loadList(notification: NSNotification){
|
||||
self.collectionView.reloadItems(at: [notification.userInfo?["indexPath"] as! IndexPath])
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
if let s = storyboard?.instantiateViewController(withIdentifier: "ColourPickerView") as? ColourPickerView {
|
||||
s.course = self.translatedCourses[indexPath.item]
|
||||
s.internalCourse = self.courses[indexPath.item]
|
||||
s.currentIndexPath = indexPath
|
||||
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
|
||||
cell.label.text = self.translatedCourses[indexPath.item]
|
||||
cell.colorView.layer.cornerRadius = cell.colorView.frame.height / 2
|
||||
cell.colorView.layer.borderWidth = 0.4
|
||||
cell.colorView.layer.borderColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)
|
||||
cell.colorView.backgroundColor = self.df.getColourPalette()[prefs.integer(forKey: "colour-index-\(courses[indexPath.item])")]
|
||||
cell.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user