HistoryTableViewCell.swift
3.07 KB
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
//
// HistoryTableViewCell.swift
// browser
//
// Created by Artem Talko on 29.09.2023.
//
//MARK: Checked
import UIKit
import SnapKit
final class HistoryTableViewCell: UITableViewCell {
static let tabID = String(describing: HistoryTableViewCell.self)
var model: HistoryDataBase? {
didSet {
handleUI()
}
}
private let searchImageLogo: UIImageView = {
let obj = UIImageView()
obj.image = UIImage(systemName: "magnifyingglass")
obj.tintColor = .gray
obj.contentMode = .scaleAspectFit
return obj
}()
private let lastVisitSiteLabel: UILabel = {
let obj = UILabel()
obj.font = FontConstants.regularFont_14
return obj
}()
private let lastVisitSiteUrlLabel: UILabel = {
let obj = UILabel()
obj.textColor = .gray
obj.font = FontConstants.regularFont_12
return obj
}()
private let lastVisitDateLabel: UILabel = {
let obj = UILabel()
obj.font = FontConstants.regularFont_12
obj.textColor = .gray
return obj
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
contentView.addSubview(searchImageLogo)
contentView.addSubview(lastVisitSiteLabel)
contentView.addSubview(lastVisitSiteUrlLabel)
contentView.addSubview(lastVisitDateLabel)
setupConstraints()
}
private func setupConstraints() {
searchImageLogo.snp.makeConstraints { make in
make.leading.equalToSuperview().inset(8.sizeW)
make.top.equalToSuperview().inset(8.sizeH)
make.height.equalTo(18.sizeW)
make.width.equalTo(18.sizeW)
}
lastVisitSiteLabel.snp.makeConstraints { make in
make.leading.equalTo(searchImageLogo.snp.trailing).offset(8.sizeW)
make.trailing.equalTo(lastVisitDateLabel.snp.leading).offset(-8.sizeW)
make.top.equalToSuperview().inset(8.sizeH)
}
lastVisitDateLabel.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(8.sizeW)
make.top.equalToSuperview().inset(8.sizeH)
}
lastVisitSiteUrlLabel.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(34.sizeW)
make.top.equalTo(lastVisitSiteLabel.snp.bottom).offset(4.sizeH)
make.bottom.equalToSuperview().inset(8.sizeH)
make.trailing.equalToSuperview().inset(61.sizeW)
}
}
}
extension HistoryTableViewCell {
private func handleUI() {
let dateForLabel = DateManager.shared.getTimeFromDB(model?.lastVisit)
lastVisitDateLabel.text = dateForLabel
lastVisitSiteLabel.text = model?.siteTitle
lastVisitSiteUrlLabel.text = model?.siteUrl
}
}