Commit 5255d67c by Dmitriy Stepanets

Refactoring

parent 2cde5631
// //
// CityMoonCell.swift // MoonPhaseCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 26.02.2021. // Created by Dmitry Stepanets on 26.02.2021.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import UIKit import UIKit
class CityMoonCell: UITableViewCell { class MoonPhaseCell: UITableViewCell {
//Private //Private
private let kCircleInset:CGFloat = 55 private let kCircleInset:CGFloat = 55
private let headingLabel = UILabel() private let headingLabel = UILabel()
...@@ -131,8 +131,8 @@ class CityMoonCell: UITableViewCell { ...@@ -131,8 +131,8 @@ class CityMoonCell: UITableViewCell {
//Public //Public
public func configure(with location:Location) { public func configure(with location:Location) {
CityMoonCell.dateFormatter.timeZone = location.today?.timeZone MoonPhaseCell.dateFormatter.timeZone = location.today?.timeZone
CityMoonCell.nowDateFormatter.timeZone = location.today?.timeZone MoonPhaseCell.nowDateFormatter.timeZone = location.today?.timeZone
moonTypeLabel.text = location.today?.moonPhase?.localized moonTypeLabel.text = location.today?.moonPhase?.localized
guard guard
...@@ -142,11 +142,11 @@ class CityMoonCell: UITableViewCell { ...@@ -142,11 +142,11 @@ class CityMoonCell: UITableViewCell {
return return
} }
moonriseTimeLabel.text = CityMoonCell.dateFormatter.string(from: moonrise) moonriseTimeLabel.text = MoonPhaseCell.dateFormatter.string(from: moonrise)
moonsetTimeLabel.text = CityMoonCell.dateFormatter.string(from: moonset) moonsetTimeLabel.text = MoonPhaseCell.dateFormatter.string(from: moonset)
let moonTimePeriod = moonset.timeIntervalSince1970 - moonrise.timeIntervalSince1970 let moonTimePeriod = moonset.timeIntervalSince1970 - moonrise.timeIntervalSince1970
let nowString = CityMoonCell.nowDateFormatter.string(from: Date()) let nowString = MoonPhaseCell.nowDateFormatter.string(from: Date())
let nowDate = CityMoonCell.nowDateFormatter.date(from: nowString) ?? Date() let nowDate = MoonPhaseCell.nowDateFormatter.date(from: nowString) ?? Date()
self.moonProgress = CGFloat((nowDate.timeIntervalSince1970 - moonrise.timeIntervalSince1970) / moonTimePeriod) self.moonProgress = CGFloat((nowDate.timeIntervalSince1970 - moonrise.timeIntervalSince1970) / moonTimePeriod)
} }
...@@ -169,7 +169,7 @@ class CityMoonCell: UITableViewCell { ...@@ -169,7 +169,7 @@ class CityMoonCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityMoonCell { private extension MoonPhaseCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
......
// //
// CitySunCell.swift // SunPhaseCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 18.02.2021. // Created by Dmitry Stepanets on 18.02.2021.
...@@ -26,7 +26,7 @@ private struct CircleSegment { ...@@ -26,7 +26,7 @@ private struct CircleSegment {
} }
} }
class CitySunCell: UITableViewCell { class SunPhaseCell: UITableViewCell {
//Private //Private
//Heading //Heading
private let headingLabel = UILabel() private let headingLabel = UILabel()
...@@ -102,13 +102,13 @@ class CitySunCell: UITableViewCell { ...@@ -102,13 +102,13 @@ class CitySunCell: UITableViewCell {
return return
} }
CitySunCell.dateFormatter.timeZone = location.today?.timeZone SunPhaseCell.dateFormatter.timeZone = location.today?.timeZone
CitySunCell.nowDateFormatter.timeZone = location.today?.timeZone SunPhaseCell.nowDateFormatter.timeZone = location.today?.timeZone
sunriseTimeLabel.text = CitySunCell.dateFormatter.string(from: sunrise) sunriseTimeLabel.text = SunPhaseCell.dateFormatter.string(from: sunrise)
sunsetTimeLabel.text = CitySunCell.dateFormatter.string(from: sunset) sunsetTimeLabel.text = SunPhaseCell.dateFormatter.string(from: sunset)
let sunTimePeriod = sunset.timeIntervalSince1970 - sunrise.timeIntervalSince1970 let sunTimePeriod = sunset.timeIntervalSince1970 - sunrise.timeIntervalSince1970
let nowString = CitySunCell.nowDateFormatter.string(from: Date()) let nowString = SunPhaseCell.nowDateFormatter.string(from: Date())
let nowDate = CitySunCell.nowDateFormatter.date(from: nowString) ?? Date() let nowDate = SunPhaseCell.nowDateFormatter.date(from: nowString) ?? Date()
//For pretty dash line view setting up min and max values //For pretty dash line view setting up min and max values
let progress = CGFloat((nowDate.timeIntervalSince1970 - sunset.timeIntervalSince1970) / sunTimePeriod) let progress = CGFloat((nowDate.timeIntervalSince1970 - sunset.timeIntervalSince1970) / sunTimePeriod)
...@@ -211,7 +211,7 @@ class CitySunCell: UITableViewCell { ...@@ -211,7 +211,7 @@ class CitySunCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CitySunCell { private extension SunPhaseCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
} }
......
...@@ -54,8 +54,8 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -54,8 +54,8 @@ class ForecastCellFactory: CellFactoryProtocol {
registerCell(type: ForecastInfoCell.self, tableView: tableView) registerCell(type: ForecastInfoCell.self, tableView: tableView)
registerCell(type: PrecipitationCell.self, tableView: tableView) registerCell(type: PrecipitationCell.self, tableView: tableView)
registerCell(type: ForecastWindSpeedCell.self, tableView: tableView) registerCell(type: ForecastWindSpeedCell.self, tableView: tableView)
registerCell(type: CitySunCell.self, tableView: tableView) registerCell(type: SunPhaseCell.self, tableView: tableView)
registerCell(type: CityMoonCell.self, tableView: tableView) registerCell(type: MoonPhaseCell.self, tableView: tableView)
} }
public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell { public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell {
...@@ -69,9 +69,9 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -69,9 +69,9 @@ class ForecastCellFactory: CellFactoryProtocol {
public func willDisplay(cell:UITableViewCell) { public func willDisplay(cell:UITableViewCell) {
switch cell { switch cell {
case let sunCell as CitySunCell: case let sunCell as SunPhaseCell:
sunCell.updateSunPosition() sunCell.updateSunPosition()
case let moonCell as CityMoonCell: case let moonCell as MoonPhaseCell:
moonCell.updateMoonPosition() moonCell.updateMoonPosition()
default: default:
break break
...@@ -103,13 +103,13 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -103,13 +103,13 @@ class ForecastCellFactory: CellFactoryProtocol {
return cell return cell
case .sun: case .sun:
let cell = dequeueReusableCell(type: CitySunCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: SunPhaseCell.self, tableView: tableView, indexPath: indexPath)
if let loc = forecastViewModel.location { if let loc = forecastViewModel.location {
cell.configure(with: loc) cell.configure(with: loc)
} }
return cell return cell
case .moon: case .moon:
let cell = dequeueReusableCell(type: CityMoonCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: MoonPhaseCell.self, tableView: tableView, indexPath: indexPath)
if let loc = forecastViewModel.location { if let loc = forecastViewModel.location {
cell.configure(with: loc) cell.configure(with: loc)
} }
......
// //
// CityAirQualityCell.swift // TodayAirQualityCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 25.02.2021. // Created by Dmitry Stepanets on 25.02.2021.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import UIKit import UIKit
class CityAirQualityCell: UITableViewCell { class TodayAirQualityCell: UITableViewCell {
//Private //Private
private let headingLabel = UILabel() private let headingLabel = UILabel()
private let valueCircle = CAShapeLayer() private let valueCircle = CAShapeLayer()
...@@ -74,7 +74,7 @@ class CityAirQualityCell: UITableViewCell { ...@@ -74,7 +74,7 @@ class CityAirQualityCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityAirQualityCell { private extension TodayAirQualityCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
......
...@@ -29,15 +29,15 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -29,15 +29,15 @@ class TodayCellFactory: CellFactoryProtocol {
} }
public func registerCells(on tableView:UITableView) { public func registerCells(on tableView:UITableView) {
registerCell(type: CityForecastCell.self, tableView: tableView) registerCell(type: TodayForecastCell.self, tableView: tableView)
registerCell(type: TodayAdCell.self, tableView: tableView) registerCell(type: TodayAdCell.self, tableView: tableView)
registerCell(type: CityConditionsCell.self, tableView: tableView) registerCell(type: TodayConditionsCell.self, tableView: tableView)
registerCell(type: CityForecastTimePeriodCell.self, tableView: tableView) registerCell(type: TodayForecastTimePeriodCell.self, tableView: tableView)
registerCell(type: PrecipitationCell.self, tableView: tableView) registerCell(type: PrecipitationCell.self, tableView: tableView)
registerCell(type: CityDayTimesCell.self, tableView: tableView) registerCell(type: TodayDayTimesCell.self, tableView: tableView)
registerCell(type: CityAirQualityCell.self, tableView: tableView) registerCell(type: TodayAirQualityCell.self, tableView: tableView)
registerCell(type: CitySunCell.self, tableView: tableView) registerCell(type: SunPhaseCell.self, tableView: tableView)
registerCell(type: CityMoonCell.self, tableView: tableView) registerCell(type: MoonPhaseCell.self, tableView: tableView)
} }
public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell { public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell {
...@@ -51,18 +51,18 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -51,18 +51,18 @@ class TodayCellFactory: CellFactoryProtocol {
switch cellType { switch cellType {
case .forecast: case .forecast:
let cell = dequeueReusableCell(type: CityForecastCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayForecastCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
case .ad: case .ad:
let cell = dequeueReusableCell(type: TodayAdCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayAdCell.self, tableView: tableView, indexPath: indexPath)
return cell return cell
case .conditions: case .conditions:
let cell = dequeueReusableCell(type: CityConditionsCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayConditionsCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
case .forecastPeriod: case .forecastPeriod:
let cell = dequeueReusableCell(type: CityForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
case .precipitation: case .precipitation:
...@@ -70,15 +70,15 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -70,15 +70,15 @@ class TodayCellFactory: CellFactoryProtocol {
cell.configure(with: loc.daily) cell.configure(with: loc.daily)
return cell return cell
case .dayTime: case .dayTime:
let cell = dequeueReusableCell(type: CityDayTimesCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayDayTimesCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
case .sun: case .sun:
let cell = dequeueReusableCell(type: CitySunCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: SunPhaseCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
case .moon: case .moon:
let cell = dequeueReusableCell(type: CityMoonCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: MoonPhaseCell.self, tableView: tableView, indexPath: indexPath)
cell.configure(with: loc) cell.configure(with: loc)
return cell return cell
} }
...@@ -86,9 +86,9 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -86,9 +86,9 @@ class TodayCellFactory: CellFactoryProtocol {
public func willDisplay(cell:UITableViewCell) { public func willDisplay(cell:UITableViewCell) {
switch cell { switch cell {
case let sunCell as CitySunCell: case let sunCell as SunPhaseCell:
sunCell.updateSunPosition() sunCell.updateSunPosition()
case let moonCell as CityMoonCell: case let moonCell as MoonPhaseCell:
moonCell.updateMoonPosition() moonCell.updateMoonPosition()
default: default:
break break
......
// //
// CityConditionButton.swift // TodayConditionButton.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 12.02.2021. // Created by Dmitry Stepanets on 12.02.2021.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import UIKit import UIKit
class CityConditionButton: UIControl { class TodayConditionButton: UIControl {
//Private //Private
private let conditionType:WeatherConditionType private let conditionType:WeatherConditionType
private let imageView = UIImageView() private let imageView = UIImageView()
...@@ -51,7 +51,7 @@ class CityConditionButton: UIControl { ...@@ -51,7 +51,7 @@ class CityConditionButton: UIControl {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityConditionButton { private extension TodayConditionButton {
func prepareButton() { func prepareButton() {
self.backgroundColor = ThemeManager.currentTheme.containerBackgroundColor self.backgroundColor = ThemeManager.currentTheme.containerBackgroundColor
self.clipsToBounds = false self.clipsToBounds = false
......
// //
// CityConditionsCell.swift // TodayConditionsCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 12.02.2021. // Created by Dmitry Stepanets on 12.02.2021.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import UIKit import UIKit
import SnapKit import SnapKit
class CityConditionsCell: UITableViewCell { class TodayConditionsCell: UITableViewCell {
//Private //Private
private let kIndicatorWidth:CGFloat = 27 private let kIndicatorWidth:CGFloat = 27
private let scrollView = UIScrollView() private let scrollView = UIScrollView()
...@@ -29,7 +29,7 @@ class CityConditionsCell: UITableViewCell { ...@@ -29,7 +29,7 @@ class CityConditionsCell: UITableViewCell {
public func configure(with location:Location) { public func configure(with location:Location) {
stackView.arrangedSubviews.forEach { stackView.arrangedSubviews.forEach {
if let conditionButton = $0 as? CityConditionButton { if let conditionButton = $0 as? TodayConditionButton {
conditionButton.configure(with: location) conditionButton.configure(with: location)
} }
} }
...@@ -41,7 +41,7 @@ class CityConditionsCell: UITableViewCell { ...@@ -41,7 +41,7 @@ class CityConditionsCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityConditionsCell { private extension TodayConditionsCell {
func prepareCellStyle() { func prepareCellStyle() {
selectionStyle = .none selectionStyle = .none
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
...@@ -76,7 +76,7 @@ private extension CityConditionsCell { ...@@ -76,7 +76,7 @@ private extension CityConditionsCell {
} }
for conditionType in WeatherConditionType.allCases { for conditionType in WeatherConditionType.allCases {
let button = CityConditionButton(type: conditionType) let button = TodayConditionButton(type: conditionType)
stackView.addArrangedSubview(button) stackView.addArrangedSubview(button)
} }
} }
...@@ -107,7 +107,7 @@ private extension CityConditionsCell { ...@@ -107,7 +107,7 @@ private extension CityConditionsCell {
} }
} }
extension CityConditionsCell: UIScrollViewDelegate { extension TodayConditionsCell: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) { func scrollViewDidScroll(_ scrollView: UIScrollView) {
let totalContentWidth = scrollView.contentSize.width + scrollView.contentInset.left + scrollView.contentInset.right let totalContentWidth = scrollView.contentSize.width + scrollView.contentInset.left + scrollView.contentInset.right
let scrollProgress = (scrollView.contentOffset.x + scrollView.contentInset.left) let scrollProgress = (scrollView.contentOffset.x + scrollView.contentInset.left)
......
// //
// CityDayTimesCell.swift // TodayDayTimesCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 25.02.2021. // Created by Dmitry Stepanets on 25.02.2021.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import UIKit import UIKit
class CityDayTimesCell: UITableViewCell { class TodayDayTimesCell: UITableViewCell {
//Private //Private
private let headingLabel = UILabel() private let headingLabel = UILabel()
private let headingButton = ArrowButton() private let headingButton = ArrowButton()
...@@ -75,7 +75,7 @@ class CityDayTimesCell: UITableViewCell { ...@@ -75,7 +75,7 @@ class CityDayTimesCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityDayTimesCell { private extension TodayDayTimesCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
......
// //
// CityForecastCell.swift // TodayForecastCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 12.02.2021. // Created by Dmitry Stepanets on 12.02.2021.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import UIKit import UIKit
import SnapKit import SnapKit
class CityForecastCell: UITableViewCell { class TodayForecastCell: UITableViewCell {
//Private //Private
private let container = UIView() private let container = UIView()
private let cityImageView = UIImageView() private let cityImageView = UIImageView()
...@@ -75,7 +75,7 @@ class CityForecastCell: UITableViewCell { ...@@ -75,7 +75,7 @@ class CityForecastCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension CityForecastCell { private extension TodayForecastCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
} }
......
// //
// CityForecastTimePeriodCell.swift // TodayForecastTimePeriodCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 15.02.2021. // Created by Dmitry Stepanets on 15.02.2021.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import UIKit import UIKit
class CityForecastTimePeriodCell: UITableViewCell { class TodayForecastTimePeriodCell: UITableViewCell {
//Private //Private
private let periodSegmentedControl = ForecastTimePeriodControl(items: ["forecast.timePeriod.daily".localized(), private let periodSegmentedControl = ForecastTimePeriodControl(items: ["forecast.timePeriod.daily".localized(),
"forecast.timePeriod.hourly".localized()]) "forecast.timePeriod.hourly".localized()])
...@@ -51,7 +51,7 @@ class CityForecastTimePeriodCell: UITableViewCell { ...@@ -51,7 +51,7 @@ class CityForecastTimePeriodCell: UITableViewCell {
} }
} }
private extension CityForecastTimePeriodCell { private extension TodayForecastTimePeriodCell {
func prepareCell() { func prepareCell() {
selectionStyle = .none selectionStyle = .none
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment