Commit 5255d67c by Dmitriy Stepanets

Refactoring

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