-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainMenuCellBuilder.swift
121 lines (91 loc) · 3.78 KB
/
MainMenuCellBuilder.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// MainMenuCellBuilder.swift
// Weather
//
// Created by Alexander Rubtsov on 12.09.2021.
//
import UIKit
protocol MainMenuCellBuilderProtocol: AnyObject {
// You should call it first
@discardableResult
func erase() -> Self
@discardableResult
func build(colorThemeModel: ColorThemeModel?, conditionId: Int) -> Self
@discardableResult
func build(cityLabelByString: String) -> Self
@discardableResult
func build(degreeLabelByString: String) -> Self
@discardableResult
func build(timeLabelByTimeZone: TimeZone?) -> Self
@discardableResult
func build(imageByConditionId conditionId: Int) -> Self
@discardableResult
func build(colorThemeModel: ColorThemeModel?, conditionId: Int, isDay: Bool)-> Self
var content: MainMenuTableViewCell { get }
}
final class MainMenuCellBuilder {
private var _content = MainMenuTableViewCell()
}
extension MainMenuCellBuilder: MainMenuCellBuilderProtocol {
func erase() -> Self {
_content = MainMenuTableViewCell()
_content.accessibilityIdentifier = K.AccessabilityIdentifier.mainMenuTableViewCell
return self
}
func build(colorThemeModel: ColorThemeModel?, conditionId: Int) -> Self {
guard let safeColortheme = colorThemeModel else {
return self
}
_content.cityNameLabel.textColor = safeColortheme.getColorByConditionId(conditionId).labelsColor
_content.degreeLabel.textColor = safeColortheme.getColorByConditionId(conditionId).labelsColor
_content.timeLabel.textColor = safeColortheme.getColorByConditionId(conditionId).labelsColor
_content.gradient.startPoint = safeColortheme.mainMenu.cells.gradient.startPoint
_content.gradient.endPoint = safeColortheme.mainMenu.cells.gradient.endPoint
if safeColortheme.mainMenu.cells.isShadowVisible {
DesignManager.setBackgroundStandartShadow(layer: _content.weatherBackgroundView.layer)
}
if let currentImage = _content.conditionImage.image {
_content.conditionImage.image = currentImage.withTintColor(safeColortheme.getColorByConditionId(conditionId).iconsColor)
}
return self
}
func build(cityLabelByString cityNameString: String) -> Self {
_content.cityNameLabel.text = cityNameString
return self
}
func build(degreeLabelByString degreeString: String) -> Self {
_content.degreeLabel.text = degreeString
return self
}
func build(timeLabelByTimeZone timeLabelTimeZone: TimeZone?) -> Self {
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.timeZone = timeLabelTimeZone
dateFormatter.dateFormat = "hh:mm"
_content.timeLabel.text = dateFormatter.string(from: date)
return self
}
func build(imageByConditionId conditionId: Int) -> Self {
let imageBuilder = ConditionImageBuilder()
let newImage = imageBuilder
.erase(.defaultColors)
.build(systemImageName: WeatherModel.getConditionNameBy(conditionId: conditionId), pointConfiguration: Grid.pt20)
.content
_content.conditionImage.image = newImage
return self
}
func build(colorThemeModel: ColorThemeModel?, conditionId: Int, isDay: Bool) -> Self {
guard let backgroundColors = colorThemeModel?.getColorByConditionId(conditionId).colors else {
return self
}
var colors = ColorThemeModel.convertUiColorsToCg(backgroundColors)
if let firstColor = colors.first, colors.count < 2 {
colors.append(firstColor)
}
_content.gradient.colors = colors
return self
}
var content: MainMenuTableViewCell {
_content
}
}