custom mood tint

This commit is contained in:
Trey t
2022-03-02 11:22:20 -06:00
parent d083c0ebdc
commit 2590a77bff
6 changed files with 209 additions and 53 deletions

View File

@@ -14,21 +14,22 @@ protocol MoodTintable {
enum MoodTints: Int, CaseIterable {
case Default
case AllRed
case Neon
case MonoChrome
case Pastel
case Custom
static var defaultOptions: [MoodTints] {
return [Default, Neon, Pastel]
}
func color(forMood mood: Mood) -> Color {
switch self {
case .Default:
return DefaultMoodTint.color(forMood: mood)
case .AllRed:
return AllRedMoodTint.color(forMood: mood)
case .Custom:
return CustomMoodTint.color(forMood: mood)
case .Neon:
return NeonMoodTint.color(forMood: mood)
case .MonoChrome:
return MonoChromeTint.color(forMood: mood)
case .Pastel:
return PastelTint.color(forMood: mood)
}
@@ -38,12 +39,10 @@ enum MoodTints: Int, CaseIterable {
switch self {
case .Default:
return DefaultMoodTint.secondary(forMood: mood)
case .AllRed:
return AllRedMoodTint.secondary(forMood: mood)
case .Custom:
return CustomMoodTint.secondary(forMood: mood)
case .Neon:
return NeonMoodTint.secondary(forMood: mood)
case .MonoChrome:
return MonoChromeTint.secondary(forMood: mood)
case .Pastel:
return PastelTint.secondary(forMood: mood)
}
@@ -53,18 +52,94 @@ enum MoodTints: Int, CaseIterable {
switch self {
case .Default:
return DefaultMoodTint.self
case .AllRed:
return AllRedMoodTint.self
case .Custom:
return CustomMoodTint.self
case .Neon:
return NeonMoodTint.self
case .MonoChrome:
return MonoChromeTint.self
case .Pastel:
return PastelTint.self
}
}
}
final class SavedMoodTint: NSObject, ObservableObject, Codable {
@Published var colorOne: Color
@Published var colorTwo: Color
@Published var colorThree: Color
@Published var colorFour: Color
@Published var colorFive: Color
override init() {
colorOne = Color(hex: "a92b26")
colorTwo = Color(hex: "a92b26")
colorThree = Color(hex: "a92b26")
colorFour = Color(hex: "a92b26")
colorFive = Color(hex: "a92b26")
}
enum CodingKeys: CodingKey {
case colorOne, colorTwo, colorThree, colorFour, colorFive
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
colorOne = try container.decode(Color.self, forKey: .colorOne)
colorTwo = try container.decode(Color.self, forKey: .colorTwo)
colorThree = try container.decode(Color.self, forKey: .colorThree)
colorFour = try container.decode(Color.self, forKey: .colorFour)
colorFive = try container.decode(Color.self, forKey: .colorFive)
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(colorOne, forKey: .colorOne)
try container.encode(colorTwo, forKey: .colorTwo)
try container.encode(colorThree, forKey: .colorThree)
try container.encode(colorFour, forKey: .colorFour)
try container.encode(colorFive, forKey: .colorFive)
}
}
final class CustomMoodTint: MoodTintable {
static func color(forMood mood: Mood) -> Color {
switch mood {
case .horrible:
return UserDefaultsStore.getCustomMoodTint().colorFive
case .bad:
return UserDefaultsStore.getCustomMoodTint().colorFour
case .average:
return UserDefaultsStore.getCustomMoodTint().colorThree
case .good:
return UserDefaultsStore.getCustomMoodTint().colorTwo
case .great:
return UserDefaultsStore.getCustomMoodTint().colorOne
case .missing:
return Color(uiColor: UIColor.lightGray)
case .placeholder:
return Color(uiColor: UIColor.lightGray)
}
}
static func secondary(forMood mood: Mood) -> Color {
switch mood {
case .horrible:
return UserDefaultsStore.getCustomMoodTint().colorFive
case .bad:
return UserDefaultsStore.getCustomMoodTint().colorFour
case .average:
return UserDefaultsStore.getCustomMoodTint().colorThree
case .good:
return UserDefaultsStore.getCustomMoodTint().colorTwo
case .great:
return UserDefaultsStore.getCustomMoodTint().colorOne
case .missing:
return Color(uiColor: UIColor.lightGray)
case .placeholder:
return Color(uiColor: UIColor.lightGray)
}
}
}
final class DefaultMoodTint: MoodTintable {
static func color(forMood mood: Mood) -> Color {
switch mood {