Commit 05c77760 by Dmitriy Stepanets

Finished shorts UI on TodayViewController

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