Cells now change colour, possibly TODO: change selector in colour picker view

This commit is contained in:
Deniz Duezgoeren
2019-07-21 22:07:50 +02:00
parent 13b9721c00
commit 8f8368327d
3 changed files with 84 additions and 23 deletions
+8 -1
View File
@@ -48,12 +48,19 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
self.txtClasses.text = prefs.string(forKey: "classes") self.txtClasses.text = prefs.string(forKey: "classes")
self.txtCourses.text = prefs.string(forKey: "courses") self.txtCourses.text = prefs.string(forKey: "courses")
self.defaultSegments.selectedSegmentIndex = prefs.integer(forKey: "default-plan") self.defaultSegments.selectedSegmentIndex = prefs.integer(forKey: "default-plan")
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) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let s = storyboard?.instantiateViewController(withIdentifier: "ColourPickerView") as? ColourPickerView { if let s = storyboard?.instantiateViewController(withIdentifier: "ColourPickerView") as? ColourPickerView {
s.course = self.courses[indexPath.item] s.course = self.courses[indexPath.item]
s.internalCourse = self.courses[indexPath.item] s.internalCourse = self.courses[indexPath.item]
s.currentIndexPath = indexPath
self.present(s, animated: true) self.present(s, animated: true)
} }
} }
@@ -100,7 +107,7 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! ColourViewCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! ColourViewCell
cell.label.text = self.courses[indexPath.item] cell.label.text = self.courses[indexPath.item]
cell.colorView.layer.cornerRadius = cell.colorView.frame.height / 2 cell.colorView.layer.cornerRadius = cell.colorView.frame.height / 2
cell.colorView.backgroundColor = self.df.getColourPalette()[prefs.integer(forKey: "debug-colour-index-\(courses[indexPath.item])")] 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) cell.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
return cell return cell
} }
+56
View File
@@ -281,4 +281,60 @@ class DataFetcher {
func getColourPaletteNames() -> [String] { func getColourPaletteNames() -> [String] {
return ["White", "Red", "Orange", "Yellow", "Green", "Cyan", "Light Blue", "Blue", "Purple", "Pink", "Brown", "Grey"] return ["White", "Red", "Orange", "Yellow", "Green", "Cyan", "Light Blue", "Blue", "Purple", "Pink", "Brown", "Grey"]
} }
func getColour(for course: String) -> UIColor {
if course.count >= 2 {
let index = course.index(course.startIndex, offsetBy: 1)
let s = course[...index].lowercased()
var searchAgain = false
var key = ""
switch (s) {
case "nw": key = "Biology"
case "wp": key = "WP"
default: searchAgain = true
}
if searchAgain && course.count >= 3 {
let index1 = course.index(course.startIndex, offsetBy: 2)
let s1 = course[...index1].lowercased()
switch (s1) {
case "deu", "dep", "daz", "fda": key = "German"
case "mat", "map": key = "Maths"
case "eng", "enp", "ena": key = "English"
case "spo", "spp", "spth": key = "PhysEd"
case "pol", "pop": key = "Politics"
case "dar", "dap": key = "Theatre"
case "phy", "php": key = "Physics"
case "bio", "bip", "nw1", "nw2", "nw3", "nw4": key = "Biology"
case "che", "chp": key = "Chemistry"
case "phi", "psp": key = "Philosophy"
case "laa", "laf", "lat": key = "Latin"
case "spa", "spf": key = "Spanish"
case "fra", "frf", "frz": key = "French"
case "inf": key = "Compsci"
case "ges": key = "History"
case "rel": key = "Religion"
case "geg": key = "Geography"
case "kun": key = "Arts"
case "mus": key = "Music"
case "tue": key = "Turkish"
case "chi": key = "Chinese"
case "gll": key = "GLL"
case "wat": key = "WAT"
case "för": key = "Forder"
case "met", "wpb": key = "WP"
default: key = ""
}
}
if key != "" {
return self.getColourPalette()[prefs.integer(forKey: "colour-index-\(key)")]
} else {
return #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
}
} else {
return #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
}
}
} }
+1 -3
View File
@@ -82,7 +82,6 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! PlanViewCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! PlanViewCell
if self.substs.count != 0 {
cell.group.text = self.substs[indexPath.item].group cell.group.text = self.substs[indexPath.item].group
cell.additional.text = self.substs[indexPath.item].additional cell.additional.text = self.substs[indexPath.item].additional
cell.date.text = self.substs[indexPath.item].date cell.date.text = self.substs[indexPath.item].date
@@ -105,9 +104,8 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
} else { } else {
cell.course.text = course cell.course.text = course
} }
}
cell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) cell.backgroundColor = self.df.getColour(for: course)
cell.tintView.backgroundColor = cell.backgroundColor cell.tintView.backgroundColor = cell.backgroundColor
return cell return cell
} }