Commit 05c77760 by Dmitriy Stepanets

Finished shorts UI on TodayViewController

parent 977103af
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<key>OneWeatherNotificationServiceExtension.xcscheme_^#shared#^_</key> <key>OneWeatherNotificationServiceExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>67</integer> <integer>61</integer>
</dict> </dict>
<key>PG (Playground) 1.xcscheme</key> <key>PG (Playground) 1.xcscheme</key>
<dict> <dict>
......
...@@ -3,22 +3,4 @@ ...@@ -3,22 +3,4 @@
uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6" uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6"
type = "0" type = "0"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0549A927-B58A-4D08-9945-911E661668C3"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/View controllers/Today/Shorts/ShortsCollectionViewCell.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "34"
endingLineNumber = "34"
landmarkName = "configure(shorts:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>
...@@ -16,6 +16,7 @@ import DTBiOSSDK ...@@ -16,6 +16,7 @@ import DTBiOSSDK
import OneWeatherCore import OneWeatherCore
import AppsFlyerLib import AppsFlyerLib
import OneWeatherAnalytics import OneWeatherAnalytics
import NukeWebPPlugin
#warning("Fix ASAP") #warning("Fix ASAP")
import WDTWeatherSource import WDTWeatherSource
...@@ -48,6 +49,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -48,6 +49,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.debug("Launch options: -") log.debug("Launch options: -")
} }
//Nuke WebP plugin
WebPImageDecoder.enable()
//LocationManager //LocationManager
#warning("Fix ASAP") #warning("Fix ASAP")
LocationManager.shared = LocationManager(weatherUpdateSource: WdtWeatherSource(), LocationManager.shared = LocationManager(weatherUpdateSource: WdtWeatherSource(),
......
...@@ -217,6 +217,10 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -217,6 +217,10 @@ class TodayCellFactory: CellFactoryProtocol {
rowsToHide.insert(.moon) rowsToHide.insert(.moon)
} }
if location?.countryCode != "US" || todayViewModel.shorts.isEmpty {
rowsToHide.insert(.shorts)
}
todaySection.hiddenRows = rowsToHide todaySection.hiddenRows = rowsToHide
} }
} }
...@@ -9,12 +9,19 @@ import UIKit ...@@ -9,12 +9,19 @@ import UIKit
import Nuke import Nuke
import OneWeatherCore import OneWeatherCore
protocol ShortsCollectionCellDelegate: AnyObject {
func averageColor(forImage image:UIImage, identifier:String) -> UIColor?
}
class ShortsCollectionViewCell: UICollectionViewCell { class ShortsCollectionViewCell: UICollectionViewCell {
//Private //Private
private let imageView = UIImageView() private let imageView = UIImageView()
private let footerView = UIView() private let footerView = UIView()
private let footerLabel = UILabel() private let footerLabel = UILabel()
//Public
weak var delegate: ShortsCollectionCellDelegate?
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
...@@ -23,20 +30,26 @@ class ShortsCollectionViewCell: UICollectionViewCell { ...@@ -23,20 +30,26 @@ class ShortsCollectionViewCell: UICollectionViewCell {
prepareFooter() prepareFooter()
} }
func configure(shorts: ShortsItem) { func configure(shortsItem: ShortsItem) {
footerLabel.text = shorts.title footerLabel.text = shortsItem.title
if let image = self.bestImageForCellSize(images: shorts.images) { if let image = self.bestImageForCellSize(images: shortsItem.images) {
let resizeOptions = ImageProcessors.Resize(size: self.bounds.size, crop: true) let resizeOptions = ImageProcessors.Resize(size: self.bounds.size, crop: true)
let cornerRadius = ImageProcessors.RoundedCorners(radius: 12) let cornerRadius = ImageProcessors.RoundedCorners(radius: 12)
let imageRequest = ImageRequest(url: image.url, processors: [resizeOptions, cornerRadius]) let imageRequest = ImageRequest(url: image.url, processors: [resizeOptions, cornerRadius])
Nuke.loadImage(with: imageRequest, into: imageView) {[weak self] result in Nuke.loadImage(with: imageRequest, into: imageView) {[weak self] result in
print("break")
switch result { switch result {
case .success(let imageResponse): case .success(let imageResponse):
onMain { onMain {
self?.imageView.image = imageResponse.image self?.imageView.image = imageResponse.image
self?.footerView.backgroundColor = imageResponse.image.averageColor
if let cachedColor = self?.delegate?.averageColor(forImage: imageResponse.image,
identifier: image.url.absoluteString) {
self?.footerView.backgroundColor = cachedColor
}
else {
self?.footerView.backgroundColor = ThemeManager.currentTheme.containerBackgroundColor
}
} }
default: default:
break break
...@@ -53,6 +66,11 @@ class ShortsCollectionViewCell: UICollectionViewCell { ...@@ -53,6 +66,11 @@ class ShortsCollectionViewCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
override func prepareForReuse() {
super.prepareForReuse()
self.footerView.backgroundColor = .clear
}
private func bestImageForCellSize(images:[ShortsItemImage]) -> ShortsItemImage? { private func bestImageForCellSize(images:[ShortsItemImage]) -> ShortsItemImage? {
guard !images.isEmpty && self.frame != .zero else { guard !images.isEmpty && self.frame != .zero else {
return nil return nil
...@@ -73,7 +91,9 @@ class ShortsCollectionViewCell: UICollectionViewCell { ...@@ -73,7 +91,9 @@ class ShortsCollectionViewCell: UICollectionViewCell {
//MARK:- Prepare //MARK:- Prepare
private extension ShortsCollectionViewCell { private extension ShortsCollectionViewCell {
func prepare() { func prepare() {
contentView.backgroundColor = .clear contentView.clipsToBounds = true
contentView.layer.cornerRadius = 12
contentView.backgroundColor = ThemeManager.currentTheme.containerBackgroundColor
} }
func prepareImage() { func prepareImage() {
......
...@@ -13,6 +13,7 @@ class ShortsView: UIView { ...@@ -13,6 +13,7 @@ class ShortsView: UIView {
private let headingLabel = UILabel() private let headingLabel = UILabel()
private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: ShortsCollectionViewLayout()) private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: ShortsCollectionViewLayout())
private var shorts = [ShortsItem]() private var shorts = [ShortsItem]()
private var averageColorCache = [AnyHashable:UIColor]()
init() { init() {
super.init(frame: .zero) super.init(frame: .zero)
...@@ -58,7 +59,26 @@ extension ShortsView: UICollectionViewDataSource { ...@@ -58,7 +59,26 @@ extension ShortsView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ShortsCollectionViewCell.kIdentifier, let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ShortsCollectionViewCell.kIdentifier,
for: indexPath) as! ShortsCollectionViewCell for: indexPath) as! ShortsCollectionViewCell
cell.configure(shorts: shorts[indexPath.row]) cell.delegate = self
cell.configure(shortsItem: shorts[indexPath.row])
return cell return cell
} }
} }
//MARK:- ShortsCollectionCell Delegate
extension ShortsView: ShortsCollectionCellDelegate {
func averageColor(forImage image: UIImage, identifier: String) -> UIColor? {
if let cachedColor = self.averageColorCache[identifier] {
return cachedColor
}
else {
if let color = image.averageColor {
self.averageColorCache[identifier] = color
return color
}
else {
return nil
}
}
}
}
...@@ -62,6 +62,7 @@ class TodayViewModel: ViewModelProtocol { ...@@ -62,6 +62,7 @@ class TodayViewModel: ViewModelProtocol {
self.shorts.removeAll() self.shorts.removeAll()
self.shorts = fetchedShorts self.shorts = fetchedShorts
onMain { onMain {
self.todayCellFactory.setNeedsUpdate()
self.delegate?.viewModelDidChange(model: self) self.delegate?.viewModelDidChange(model: self)
} }
case .failure(let error): case .failure(let error):
......
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