Various theming fixes

This commit is contained in:
Ilya Laktyushin
2019-12-16 10:33:16 +04:00
parent 26f89fedef
commit 62ae89d18b
29 changed files with 302 additions and 174 deletions

View File

@@ -39,9 +39,9 @@ extension TelegramWallpaper: Codable {
case "builtin":
self = .builtin(WallpaperSettings())
default:
let options = ["motion", "blur"]
let optionKeys = ["motion", "blur"]
if [6,7].contains(value.count), let color = UIColor(hexString: value) {
if value.count == 6, let color = UIColor(hexString: value) {
self = .color(Int32(bitPattern: color.rgb))
} else {
let components = value.components(separatedBy: " ")
@@ -54,7 +54,15 @@ extension TelegramWallpaper: Codable {
blur = true
}
if components.count >= 2 && components.count <= 4 && [6,7].contains(components[0].count) && !options.contains(components[0]) && [6,7].contains(components[1].count) && !options.contains(components[1]), let topColor = UIColor(hexString: components[0]), let bottomColor = UIColor(hexString: components[1]) {
if components.count >= 2 && components.count <= 5 && components[0].count == 6 && !optionKeys.contains(components[0]) && components[1].count == 6 && !optionKeys.contains(components[1]), let topColor = UIColor(hexString: components[0]), let bottomColor = UIColor(hexString: components[1]) {
var rotation: Int32?
if components.count > 2, components[2].count <= 3, let value = Int32(components[2]) {
if value >= 0 && value < 360 {
rotation = value
}
}
self = .gradient(Int32(bitPattern: topColor.rgb), Int32(bitPattern: bottomColor.rgb), WallpaperSettings(blur: blur, motion: motion))
} else {
var slug: String?
@@ -68,7 +76,7 @@ extension TelegramWallpaper: Codable {
if components.count > 1 {
for i in 1 ..< components.count {
let component = components[i]
if options.contains(component) {
if optionKeys.contains(component) {
continue
}
if component.count == 6, let value = UIColor(hexString: component) {
@@ -110,6 +118,9 @@ extension TelegramWallpaper: Codable {
var components: [String] = []
components.append(String(format: "%06x", topColor))
components.append(String(format: "%06x", bottomColor))
if let rotation = settings.rotation {
components.append("\(rotation)")
}
if settings.motion {
components.append("motion")
}
@@ -130,6 +141,9 @@ extension TelegramWallpaper: Codable {
if let bottomColor = file.settings.bottomColor {
components.append(String(format: "%06x", bottomColor))
}
if let rotation = file.settings.rotation {
components.append("\(rotation)")
}
}
if file.settings.motion {
components.append("motion")