Small code refactoring
This commit is contained in:
@@ -11,8 +11,6 @@ import UIKit
|
||||
final class LicenceListViewController: UITableViewController {
|
||||
|
||||
// MARK: - Var
|
||||
|
||||
fileprivate let reuseIdentifier = "openSourceCell"
|
||||
|
||||
fileprivate var config: OpenSourceControllerConfig
|
||||
|
||||
@@ -40,7 +38,7 @@ final class LicenceListViewController: UITableViewController {
|
||||
|
||||
fileprivate func prepareTableView() {
|
||||
self.tableView.tableFooterView = UIView()
|
||||
self.tableView.register(OpenSourceTableViewCell.self, forCellReuseIdentifier: self.reuseIdentifier)
|
||||
self.tableView.register(cellType: OpenSourceTableViewCell.self)
|
||||
self.tableView.dataSource = self
|
||||
self.tableView.delegate = self
|
||||
self.tableView.separatorStyle = .singleLine
|
||||
@@ -61,19 +59,10 @@ extension LicenceListViewController {
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
var cell = tableView.dequeueReusableCell(withIdentifier: self.reuseIdentifier,
|
||||
for: indexPath) as? OpenSourceTableViewCell
|
||||
// Init cell
|
||||
if cell == nil {
|
||||
cell = OpenSourceTableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: self.reuseIdentifier)
|
||||
}
|
||||
|
||||
// Configure the cell with licence
|
||||
if let licence = self.downloadedLicence.get(at: indexPath.row) {
|
||||
cell?.configure(licence: licence, config: self.config)
|
||||
}
|
||||
|
||||
return cell!
|
||||
let cell: OpenSourceTableViewCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
guard let licence = self.downloadedLicence.get(at: indexPath.row) else { return cell }
|
||||
cell.configure(licence: licence, config: self.config)
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
final class OpenSourceTableViewCell: UITableViewCell {
|
||||
final class OpenSourceTableViewCell: UITableViewCell, Reusable {
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
@@ -29,15 +29,10 @@ final class OpenSourceTableViewCell: UITableViewCell {
|
||||
|
||||
// MARK: - Configure
|
||||
|
||||
/// Initialize the cell content with Licence model
|
||||
///
|
||||
/// - Parameter licence: the licence model
|
||||
func configure(licence: LicenceFile, config: OpenSourceControllerConfig) {
|
||||
// Set text
|
||||
self.textLabel?.attributedText = licence.attributedContent
|
||||
self.textLabel?.textColor = config.uiConfig.licenceTextColor
|
||||
|
||||
// Background
|
||||
if let backgroundColor = config.uiConfig.licenceBackgroundColor {
|
||||
self.backgroundColor = backgroundColor
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ final class OpenSourceViewController: UIViewController {
|
||||
|
||||
fileprivate var licences: [LicenceFile]
|
||||
|
||||
fileprivate var licenceLoader: LicenceLoader
|
||||
|
||||
fileprivate var config: OpenSourceControllerConfig
|
||||
|
||||
fileprivate lazy var loadingController = {
|
||||
@@ -28,7 +30,8 @@ final class OpenSourceViewController: UIViewController {
|
||||
|
||||
// MARK: - Lifecyle
|
||||
|
||||
init(licences: [LicenceFile], showCloseButton: Bool, configuration: OpenSourceControllerConfig) {
|
||||
init(licences: [LicenceFile], showCloseButton: Bool, configuration: OpenSourceControllerConfig, licenceLoader: LicenceLoader) {
|
||||
self.licenceLoader = licenceLoader
|
||||
self.licences = licences
|
||||
self.showCloseButton = showCloseButton
|
||||
self.config = configuration
|
||||
@@ -56,12 +59,10 @@ final class OpenSourceViewController: UIViewController {
|
||||
// MARK: - Prepare
|
||||
|
||||
fileprivate func prepareStyle() {
|
||||
// Apply navigation bar tint color if needed
|
||||
if let tintColor = self.config.uiConfig.barTintColor {
|
||||
self.navigationController?.navigationBar.barTintColor = tintColor
|
||||
}
|
||||
|
||||
// Apply navigation bar text color if needed
|
||||
if let textColor = self.config.uiConfig.titleColor {
|
||||
let attribut = [NSAttributedString.Key.foregroundColor: textColor]
|
||||
self.navigationController?.navigationBar.titleTextAttributes = attribut
|
||||
@@ -69,7 +70,7 @@ final class OpenSourceViewController: UIViewController {
|
||||
}
|
||||
|
||||
fileprivate func prepareLicences() {
|
||||
LicenceLoader.downloadLicences(licences: licences, config: config) { [weak self] in
|
||||
self.licenceLoader.downloadLicences(licences: licences, config: config) { [weak self] in
|
||||
guard let strongSelf = self else { return }
|
||||
let listController = LicenceListViewController(downloadedLicence: strongSelf.licences, config: strongSelf.config)
|
||||
strongSelf.loadingController.remove()
|
||||
|
||||
Reference in New Issue
Block a user