Archived
Cells now change colour, possibly TODO: change selector in colour picker view
This commit is contained in:
@@ -48,12 +48,19 @@ class CustomizationViewController: UIViewController, UICollectionViewDataSource,
|
||||
self.txtClasses.text = prefs.string(forKey: "classes")
|
||||
self.txtCourses.text = prefs.string(forKey: "courses")
|
||||
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) {
|
||||
if let s = storyboard?.instantiateViewController(withIdentifier: "ColourPickerView") as? ColourPickerView {
|
||||
s.course = self.courses[indexPath.item]
|
||||
s.internalCourse = self.courses[indexPath.item]
|
||||
s.currentIndexPath = indexPath
|
||||
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
|
||||
cell.label.text = self.courses[indexPath.item]
|
||||
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)
|
||||
return cell
|
||||
}
|
||||
|
||||
@@ -281,4 +281,60 @@ class DataFetcher {
|
||||
func getColourPaletteNames() -> [String] {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,32 +82,30 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
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.additional.text = self.substs[indexPath.item].additional
|
||||
cell.date.text = self.substs[indexPath.item].date
|
||||
cell.time.text = self.substs[indexPath.item].time
|
||||
cell.room.text = self.substs[indexPath.item].room
|
||||
cell.group.text = self.substs[indexPath.item].group
|
||||
cell.additional.text = self.substs[indexPath.item].additional
|
||||
cell.date.text = self.substs[indexPath.item].date
|
||||
cell.time.text = self.substs[indexPath.item].time
|
||||
cell.room.text = self.substs[indexPath.item].room
|
||||
|
||||
let course = self.substs[indexPath.item].course
|
||||
let image = df.getImage(from: course)
|
||||
|
||||
if image != nil {
|
||||
let attachment: NSTextAttachment = NSTextAttachment()
|
||||
attachment.bounds = CGRect(x: 0, y: 0, width: 16, height: 16)
|
||||
attachment.image = image
|
||||
|
||||
let course = self.substs[indexPath.item].course
|
||||
let image = df.getImage(from: course)
|
||||
let courseImage = NSMutableAttributedString(attachment: attachment)
|
||||
let courseString = NSAttributedString(string: " \(course)")
|
||||
courseImage.append(courseString)
|
||||
|
||||
if image != nil {
|
||||
let attachment: NSTextAttachment = NSTextAttachment()
|
||||
attachment.bounds = CGRect(x: 0, y: 0, width: 16, height: 16)
|
||||
attachment.image = image
|
||||
|
||||
let courseImage = NSMutableAttributedString(attachment: attachment)
|
||||
let courseString = NSAttributedString(string: " \(course)")
|
||||
courseImage.append(courseString)
|
||||
|
||||
cell.course.attributedText = courseImage
|
||||
} else {
|
||||
cell.course.text = course
|
||||
}
|
||||
cell.course.attributedText = courseImage
|
||||
} else {
|
||||
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
|
||||
return cell
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user