Skip to content

Commit 3f55b2e

Browse files
authored
Merge branch 'devpass-tech:main' into feature/ContactListView
2 parents 4094d61 + da0c630 commit 3f55b2e

File tree

8 files changed

+89
-17
lines changed

8 files changed

+89
-17
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import UIKit
2+
3+
extension UIColor {
4+
static func fromRGB(_ rgbValue: Int) -> UIColor! {
5+
return UIColor(
6+
red: CGFloat((Float((rgbValue & 0xff0000) >> 16)) / 255.0),
7+
green: CGFloat((Float((rgbValue & 0x00ff00) >> 8)) / 255.0),
8+
blue: CGFloat((Float((rgbValue & 0x0000ff) >> 0)) / 255.0),
9+
alpha: 1.0)
10+
}
11+
12+
convenience init?(hexString: String?) {
13+
let input: String! = (hexString ?? "")
14+
.replacingOccurrences(of: "#", with: "")
15+
.uppercased()
16+
var alpha: CGFloat = 1.0
17+
var red: CGFloat = 0
18+
var blue: CGFloat = 0
19+
var green: CGFloat = 0
20+
switch (input.count) {
21+
case 3 /* #RGB */:
22+
red = Self.colorComponent(from: input, start: 0, length: 1)
23+
green = Self.colorComponent(from: input, start: 1, length: 1)
24+
blue = Self.colorComponent(from: input, start: 2, length: 1)
25+
break
26+
case 4 /* #ARGB */:
27+
alpha = Self.colorComponent(from: input, start: 0, length: 1)
28+
red = Self.colorComponent(from: input, start: 1, length: 1)
29+
green = Self.colorComponent(from: input, start: 2, length: 1)
30+
blue = Self.colorComponent(from: input, start: 3, length: 1)
31+
break
32+
case 6 /* #RRGGBB */:
33+
red = Self.colorComponent(from: input, start: 0, length: 2)
34+
green = Self.colorComponent(from: input, start: 2, length: 2)
35+
blue = Self.colorComponent(from: input, start: 4, length: 2)
36+
break
37+
case 8 /* #AARRGGBB */:
38+
alpha = Self.colorComponent(from: input, start: 0, length: 2)
39+
red = Self.colorComponent(from: input, start: 2, length: 2)
40+
green = Self.colorComponent(from: input, start: 4, length: 2)
41+
blue = Self.colorComponent(from: input, start: 6, length: 2)
42+
break
43+
default:
44+
NSException.raise(NSExceptionName("Invalid color value"), format: "Color value \"%@\" is invalid. It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB", arguments:getVaList([hexString ?? ""]))
45+
}
46+
self.init(red: red, green: green, blue: blue, alpha: alpha)
47+
}
48+
49+
static func colorComponent(from string: String!, start: Int, length: Int) -> CGFloat {
50+
let substring = (string as NSString)
51+
.substring(with: NSRange(location: start, length: length))
52+
let fullHex = length == 2 ? substring : "\(substring)\(substring)"
53+
var hexComponent: UInt64 = 0
54+
Scanner(string: fullHex)
55+
.scanHexInt64(&hexComponent)
56+
return CGFloat(Double(hexComponent) / 255.0)
57+
}
58+
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ActivityDetails/ActivityCellView.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ import UIKit
1010
enum ActivityTypes: String {
1111
case mall = "Mall"
1212
case foodCourt = "Food Court"
13+
case oceanicAirlines = "Oceanic Airlines"
1314

1415
func getColor() -> UIColor {
1516
switch self {
1617
case .mall:
17-
return .red
18+
return UIColor(red: 190/255, green: 81/255, blue: 255/255, alpha: 1)
1819
case .foodCourt:
1920
return .blue
21+
case .oceanicAirlines:
22+
return .orange
23+
}
24+
}
25+
26+
func getIcon() -> UIImage? {
27+
switch self {
28+
case .mall:
29+
return UIImage(named: "bag.circle.fill")
30+
case .foodCourt:
31+
return UIImage(named: "fork.knife.circle.fill")
32+
case .oceanicAirlines:
33+
return UIImage(named: "airplane.circle.fill")
2034
}
2135
}
2236
}
@@ -72,6 +86,7 @@ class ActivityCellView: UITableViewCell {
7286

7387
if let type = ActivityTypes(rawValue: activity.name) {
7488
icon.tintColor = type.getColor()
89+
icon.image = type.getIcon()
7590
}
7691

7792
titleDescription.text = String.activityDetails(with: activity.price, and: activity.time)
@@ -96,22 +111,17 @@ extension ActivityCellView: ViewCodable {
96111

97112

98113
func setupConstraints() {
99-
100114
NSLayoutConstraint.activate([
101-
icon.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8),
115+
icon.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
102116
icon.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8),
103117
icon.heightAnchor.constraint(equalToConstant: 48),
104118
icon.widthAnchor.constraint(equalToConstant: 48),
105119

106-
stackView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
120+
stackView.heightAnchor.constraint(greaterThanOrEqualToConstant: 48),
121+
stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8),
122+
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -8),
107123
stackView.leadingAnchor.constraint(equalTo: icon.trailingAnchor, constant: 8),
108-
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8),
109-
110-
titleLabel.leadingAnchor.constraint(equalTo: stackView.trailingAnchor),
111-
titleLabel.trailingAnchor.constraint(equalTo: stackView.trailingAnchor),
112-
113-
titleDescription.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor),
114-
titleDescription.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor),
124+
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8)
115125
])
116126
}
117127
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/Home/HomeView.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ struct HomeViewConfiguration {
1212
}
1313

1414
final class HomeView: UIView {
15-
private let listViewCellIdentifier = "ListViewCellIdentifier"
16-
1715
private var activities: [Activity] = []
1816

1917
private lazy var accountSummaryView: AccountSummaryView = {
@@ -25,7 +23,8 @@ final class HomeView: UIView {
2523
private lazy var tableView: UITableView = {
2624
let tableView = UITableView(frame: .zero)
2725
tableView.translatesAutoresizingMaskIntoConstraints = false
28-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.listViewCellIdentifier)
26+
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
27+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
2928
tableView.dataSource = self
3029
return tableView
3130
}()
@@ -81,8 +80,13 @@ extension HomeView: UITableViewDataSource {
8180
}
8281

8382
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
84-
let cell = tableView.dequeueReusableCell(withIdentifier: self.listViewCellIdentifier)!
85-
cell.textLabel?.text = activities[indexPath.row].name
83+
guard let cell: ActivityCellView = .createCell(for: tableView, at: indexPath),
84+
indexPath.row < activities.count else {
85+
return .init()
86+
}
87+
88+
89+
cell.updateValues(activity: activities[indexPath.row])
8690
return cell
8791
}
8892
}

solutions/devsprint-caio-santos-7/FinanceAppTests/Screens/ActivityDetails/ActivityCellViewTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class ActivityCellViewTests: XCTestCase {
3232
unwrappedSut.updateValues(activity: Activity(name: "TESTE TESTE TESTE TESTE TESTE TESTE TESTE",
3333
price: 0,
3434
time: "TESTE"))
35-
assertSnapshot(matching: unwrappedSut, as: .image)
35+
assertSnapshot(matching: unwrappedSut, as: .image(size: .init(width: UIScreen.main.bounds.width, height: 78)))
3636
}
3737

3838
func test_WhenInitActivityCellViewWithMall_ThenView_ShouldHaveValidSnapshot() throws {
Loading

0 commit comments

Comments
 (0)