Commit 3b01922f by Demid Merzlyakov

IOS-106: MREC support.

parent cc6ee399
...@@ -124,17 +124,11 @@ public class AdManager { ...@@ -124,17 +124,11 @@ public class AdManager {
a9Cache.addToPreload(placementName: placementNameTodayBanner, adType: .banner, count: 1) a9Cache.addToPreload(placementName: placementNameTodayBanner, adType: .banner, count: 1)
a9Cache.addToPreload(placementName: placementNameTodaySquare, adType: .square, count: 1) a9Cache.addToPreload(placementName: placementNameTodaySquare, adType: .square, count: 1)
a9Cache.addToPreload(placementName: placementNameDiscussionSquare, adType: .square, count: 1)
a9Cache.addToPreload(placementName: placementNameExtendedSquare, adType: .square, count: 1)
a9Cache.addToPreload(placementName: placementName12WeekInterstitial, adType: .interstitial, count: 1)
a9Cache.addToPreload(placementName: placementNameForecastHourlyBanner, adType: .banner, count: 1) a9Cache.addToPreload(placementName: placementNameForecastHourlyBanner, adType: .banner, count: 1)
a9Cache.addToPreload(placementName: placementNameForecastHourlySquare, adType: .square, count: 1) a9Cache.addToPreload(placementName: placementNameForecastHourlySquare, adType: .square, count: 1)
a9Cache.addToPreload(placementName: placementNameForecastExtendedBanner, adType: .banner, count: 1) a9Cache.addToPreload(placementName: placementNameForecastDailyBanner, adType: .banner, count: 1)
a9Cache.addToPreload(placementName: placementNameForecastExtendedSquare, adType: .square, count: 1) a9Cache.addToPreload(placementName: placementNameForecastDailySquare, adType: .square, count: 1)
a9Cache.addToPreload(placementName: placementNameForecast12WeekSquare, adType: .square, count: 1) a9Cache.addToPreload(placementName: placementNameNWSAlertBanner, adType: .banner, count: 1)
a9Cache.addToPreload(placementName: placementNamePrecipitationBanner, adType: .banner, count: 1)
a9Cache.addToPreload(placementName: placementNameRadarInterstitial, adType: .interstitial, count: 1)
a9Cache.addToPreload(placementName: placementNameSunMoonBanner, adType: .banner, count: 1)
a9Cache.startPreloadingBids() a9Cache.startPreloadingBids()
} }
......
...@@ -127,7 +127,7 @@ public class AdView: UIView { ...@@ -127,7 +127,7 @@ public class AdView: UIView {
log.warning("failed to guess the top view controller.") log.warning("failed to guess the top view controller.")
return return
} }
bannerView = NativeBannerContainerView(adUnitId: placement.adUnitId, rootViewController: topViewController) bannerView = NativeBannerContainerView(adUnitId: placement.adUnitId, adType: adType, rootViewController: topViewController)
if let bannerView = bannerView { if let bannerView = bannerView {
......
...@@ -14,19 +14,13 @@ extension Notification.Name { ...@@ -14,19 +14,13 @@ extension Notification.Name {
typealias AdPlacementName = String typealias AdPlacementName = String
let placementNameTodayBanner: AdPlacementName = "1W_iOS_Native_Banner_ForD_ATF" //TODO: wrong? let placementNameTodayBanner: AdPlacementName = "today_banner"
let placementNameTodaySquare: AdPlacementName = "1W_iOS_Native_MREC_Today_BTF2" let placementNameTodaySquare: AdPlacementName = "today_square"
let placementNameDiscussionSquare: AdPlacementName = "1W_iOS_Native_MREC_Forecast_discussion" let placementNameForecastHourlyBanner: AdPlacementName = "forecast_hourly_banner"
let placementNameExtendedSquare: AdPlacementName = "1W_iOS_Native_MREC_Forecast_discussion" // TODO: wrong? let placementNameForecastHourlySquare: AdPlacementName = "forecast_hourly_square"
let placementName12WeekInterstitial: AdPlacementName = "1W_iOS_Int" //TODO: definitely wrong let placementNameForecastDailyBanner: AdPlacementName = "forecast_daily_banner"
let placementNameForecastHourlyBanner: AdPlacementName = "1W_iOS_Native_Banner_Hourly_ATF" let placementNameForecastDailySquare: AdPlacementName = "forecast_daily_square"
let placementNameForecastHourlySquare: AdPlacementName = "1W_iOS_Native_MREC_Forecast_Hourly_BTF1" let placementNameNWSAlertBanner: AdPlacementName = "nws_alert_banner"
let placementNameForecastExtendedBanner: AdPlacementName = "1W_iOS_Native_Banner_ForD_ATF" // TODO: definitely wrong
let placementNameForecastExtendedSquare: AdPlacementName = "1W_iOS_Native_MREC_Forecast_discussion" // TODO: definitely wrong
let placementNameForecast12WeekSquare: AdPlacementName = "1W_iOS_Native_MREC_Today_Details" //TODO: definitely wrong
let placementNamePrecipitationBanner: AdPlacementName = "1W_iOS_Native_Banner_Precipitation_ATF"
let placementNameRadarInterstitial: AdPlacementName = "1W_iOS_Int" //TODO: definitely wrong
let placementNameSunMoonBanner: AdPlacementName = "1W_iOS_Native_Banner_Sunmoon_ATF"
class AdConfigManager: NSObject { class AdConfigManager: NSObject {
@objc @objc
......
...@@ -98,12 +98,12 @@ extension NativeAdItem: GADNativeAdDelegate { ...@@ -98,12 +98,12 @@ extension NativeAdItem: GADNativeAdDelegate {
} }
extension NativeAdItem: GADBannerViewDelegate { extension NativeAdItem: GADBannerViewDelegate {
func adViewDidRecordImpression(_ bannerView: GADBannerView) { func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
log.info("Impression recorded (banner)") log.info("Impression recorded (banner)")
analytics(log: .ANALYTICS_AD_IMPRESSION) analytics(log: .ANALYTICS_AD_IMPRESSION)
} }
func adViewWillPresentScreen(_ bannerView: GADBannerView) { func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
log.info("Click recorded (will present screen)") log.info("Click recorded (will present screen)")
analytics(log: .ANALYTICS_AD_CLICKED) analytics(log: .ANALYTICS_AD_CLICKED)
} }
......
// //
// NativeBannerView.swift // NativeAdView.swift
// BaconReader // 1Weather
// //
// Created by Rishab Dutta on 24/07/20. // Created by Demid Merzlyakov on 07.06.2021.
// Copyright © 2020 OneLouder Apps. All rights reserved.
// //
import Foundation import Foundation
import GoogleMobileAds import GoogleMobileAds
class NativeBannerView: GADNativeAdView { class NativeAdView: GADNativeAdView {
@IBOutlet weak var sponsoredLabel: UILabel! @IBOutlet weak var sponsoredLabel: UILabel?
@IBOutlet weak var adChoicesViewCustomOutlet: GADAdChoicesView! @IBOutlet weak var adChoicesViewCustomOutlet: GADAdChoicesView?
var headlineLabel: UILabel? { var headlineLabel: UILabel? {
headlineView as? UILabel headlineView as? UILabel
...@@ -22,6 +20,10 @@ class NativeBannerView: GADNativeAdView { ...@@ -22,6 +20,10 @@ class NativeBannerView: GADNativeAdView {
advertiserView as? UILabel advertiserView as? UILabel
} }
var bodyLabel: UILabel? {
bodyView as? UILabel
}
var iconImageView: UIImageView? { var iconImageView: UIImageView? {
iconView as? UIImageView iconView as? UIImageView
} }
...@@ -30,14 +32,28 @@ class NativeBannerView: GADNativeAdView { ...@@ -30,14 +32,28 @@ class NativeBannerView: GADNativeAdView {
callToActionView as? UILabel callToActionView as? UILabel
} }
class func instantiateWithXib() -> NativeBannerView? { var mainImageView: UIImageView? {
let nib = UINib(nibName: "\(NativeBannerView.self)", bundle: nil) imageView as? UIImageView
let bView = nib.instantiate(withOwner: self, options: nil).first as? NativeBannerView }
public class func instantiateWithXib(adType: AdType) -> NativeAdView? {
var xibName: String!
switch adType {
case .banner:
xibName = "NativeBannerView"
case .square:
xibName = "NativeMRECView"
case .interstitial:
assertionFailure("Incorrect ad type - interstitial")
return nil
}
let nib = UINib(nibName: xibName, bundle: nil)
let bView = nib.instantiate(withOwner: self, options: nil).first as? NativeAdView
bView?.setupPostXib() bView?.setupPostXib()
return bView return bView
} }
private func setupPostXib() { func setupPostXib() {
let currentTheme = ThemeManager.currentTheme let currentTheme = ThemeManager.currentTheme
callToActionLabel?.backgroundColor = currentTheme.nativeAdCallToActionColor callToActionLabel?.backgroundColor = currentTheme.nativeAdCallToActionColor
callToActionLabel?.layer.cornerRadius = 2 callToActionLabel?.layer.cornerRadius = 2
...@@ -47,17 +63,20 @@ class NativeBannerView: GADNativeAdView { ...@@ -47,17 +63,20 @@ class NativeBannerView: GADNativeAdView {
advertiserLabel?.textColor = currentTheme.primaryTextColor advertiserLabel?.textColor = currentTheme.primaryTextColor
self.adChoicesView = self.adChoicesViewCustomOutlet self.adChoicesView = self.adChoicesViewCustomOutlet
sponsoredLabel.text = "ads.native.sponsored".localized() sponsoredLabel?.text = "ads.native.sponsored".localized()
sponsoredLabel.textColor = currentTheme.primaryTextColor sponsoredLabel?.textColor = currentTheme.primaryTextColor
bodyLabel?.textColor = currentTheme.secondaryTextColor
setupFonts() setupFonts()
} }
private func setupFonts() { private func setupFonts() {
callToActionLabel?.font = AppFont.SFCompactDisplay.regular(size: 10) callToActionLabel?.font = AppFont.SFCompactDisplay.regular(size: 10)
sponsoredLabel.font = AppFont.SFCompactDisplay.regular(size: 10) sponsoredLabel?.font = AppFont.SFCompactDisplay.regular(size: 10)
headlineLabel?.font = AppFont.SFCompactDisplay.semibold(size: 18) headlineLabel?.font = AppFont.SFCompactDisplay.semibold(size: 18)
advertiserLabel?.font = AppFont.SFCompactDisplay.regular(size: 12) advertiserLabel?.font = AppFont.SFCompactDisplay.regular(size: 12)
callToActionLabel?.font = AppFont.SFCompactDisplay.light(size: 10) callToActionLabel?.font = AppFont.SFCompactDisplay.light(size: 10)
bodyLabel?.font = AppFont.SFCompactDisplay.regular(size: 10)
} }
var nativeAdItem: NativeAdItem? { var nativeAdItem: NativeAdItem? {
...@@ -75,9 +94,10 @@ class NativeBannerView: GADNativeAdView { ...@@ -75,9 +94,10 @@ class NativeBannerView: GADNativeAdView {
iconImageView?.image = nativeAd?.icon?.image iconImageView?.image = nativeAd?.icon?.image
advertiserLabel?.text = nativeAd?.advertiser advertiserLabel?.text = nativeAd?.advertiser
callToActionLabel?.text = nativeAd?.callToAction callToActionLabel?.text = nativeAd?.callToAction
bodyLabel?.text = nativeAd?.body
mainImageView?.image = nativeAd?.images?.first?.image
setupPostXib() setupPostXib()
} }
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="NativeBannerView" customModule="_Weather" customModuleProvider="target"> <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="NativeAdView" customModule="_Weather" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="64"/> <rect key="frame" x="0.0" y="0.0" width="320" height="64"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="GADNativeAdView"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="A8i-el-bXZ" customClass="NativeAdView" customModule="_Weather" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="300" height="250"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="TNc-iz-mnZ">
<rect key="frame" x="0.0" y="0.0" width="300" height="155"/>
<constraints>
<constraint firstAttribute="height" constant="155" id="2of-WV-KVU"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Headline" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ALU-9y-yCS">
<rect key="frame" x="10" y="160" width="280" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Body" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="b9r-uH-Qrr">
<rect key="frame" x="10" y="180" width="222" height="11"/>
<fontDescription key="fontDescription" type="system" pointSize="9"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CTA" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7po-us-Uyw">
<rect key="frame" x="10" y="210" width="78" height="26"/>
<color key="backgroundColor" red="0.066666666669999999" green="0.49803921569999998" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="26" id="5wk-Js-TvA"/>
<constraint firstAttribute="width" constant="78" id="mQK-sj-eIi"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="k7n-sU-yPp">
<rect key="frame" x="236" y="184" width="54" height="54"/>
<constraints>
<constraint firstAttribute="width" constant="54" id="DaG-29-Yci"/>
<constraint firstAttribute="height" constant="54" id="Ol9-Ch-SAu"/>
</constraints>
</imageView>
</subviews>
<viewLayoutGuide key="safeArea" id="4vU-qI-YDI"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="k7n-sU-yPp" firstAttribute="leading" secondItem="b9r-uH-Qrr" secondAttribute="trailing" constant="4" id="42b-ug-6to"/>
<constraint firstItem="TNc-iz-mnZ" firstAttribute="leading" secondItem="A8i-el-bXZ" secondAttribute="leading" id="5EK-gf-w66"/>
<constraint firstItem="7po-us-Uyw" firstAttribute="leading" secondItem="A8i-el-bXZ" secondAttribute="leading" constant="10" id="5FJ-Je-u1p"/>
<constraint firstItem="b9r-uH-Qrr" firstAttribute="top" secondItem="ALU-9y-yCS" secondAttribute="bottom" id="7uv-BN-qIz"/>
<constraint firstAttribute="bottom" secondItem="7po-us-Uyw" secondAttribute="bottom" constant="14" id="Apu-0q-oJC"/>
<constraint firstAttribute="bottom" secondItem="k7n-sU-yPp" secondAttribute="bottom" constant="12" id="CRP-vK-rgT"/>
<constraint firstAttribute="trailing" secondItem="k7n-sU-yPp" secondAttribute="trailing" constant="10" id="IBC-YR-xho"/>
<constraint firstItem="b9r-uH-Qrr" firstAttribute="leading" secondItem="ALU-9y-yCS" secondAttribute="leading" id="aoN-Pv-cUM"/>
<constraint firstItem="ALU-9y-yCS" firstAttribute="leading" secondItem="A8i-el-bXZ" secondAttribute="leading" constant="10" id="dBl-Mj-Bmh"/>
<constraint firstItem="ALU-9y-yCS" firstAttribute="top" secondItem="TNc-iz-mnZ" secondAttribute="bottom" constant="5" id="j1x-NM-1zu"/>
<constraint firstAttribute="trailing" secondItem="TNc-iz-mnZ" secondAttribute="trailing" id="o1v-BR-AAi"/>
<constraint firstAttribute="trailing" secondItem="ALU-9y-yCS" secondAttribute="trailing" constant="10" id="tNs-jB-g7c"/>
<constraint firstItem="TNc-iz-mnZ" firstAttribute="top" secondItem="A8i-el-bXZ" secondAttribute="top" id="u0g-go-6RF"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="bodyView" destination="b9r-uH-Qrr" id="mHO-sW-gX7"/>
<outlet property="callToActionView" destination="7po-us-Uyw" id="VBG-Fk-Pn7"/>
<outlet property="headlineView" destination="ALU-9y-yCS" id="pHO-sW-gXV"/>
<outlet property="iconView" destination="k7n-sU-yPp" id="4P6-sq-Gob"/>
<outlet property="imageView" destination="TNc-iz-mnZ" id="TN6-iz-mnZ"/>
</connections>
<point key="canvasLocation" x="214.49275362318843" y="-94.419642857142847"/>
</view>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
...@@ -21,6 +21,7 @@ class NativeBannerContainerView: UIView { ...@@ -21,6 +21,7 @@ class NativeBannerContainerView: UIView {
private let log = AdLogger(componentName: "NativeBannerContainerView") private let log = AdLogger(componentName: "NativeBannerContainerView")
private var adLoader: NativeAdLoader private var adLoader: NativeAdLoader
private let adType: AdType
weak var delegate: NativeBannerContainerViewDelegate? weak var delegate: NativeBannerContainerViewDelegate?
...@@ -30,7 +31,8 @@ class NativeBannerContainerView: UIView { ...@@ -30,7 +31,8 @@ class NativeBannerContainerView: UIView {
} }
} }
init(adUnitId: String, rootViewController: UIViewController) { init(adUnitId: String, adType: AdType, rootViewController: UIViewController) {
self.adType = adType
self.adLoader = NativeAdLoader(adUnitId: adUnitId, rootViewController: rootViewController, adTypes: [.native, .gamBanner]) self.adLoader = NativeAdLoader(adUnitId: adUnitId, rootViewController: rootViewController, adTypes: [.native, .gamBanner])
super.init(frame: .zero) super.init(frame: .zero)
self.adLoader.delegate = self self.adLoader.delegate = self
...@@ -76,17 +78,12 @@ private extension NativeBannerContainerView { ...@@ -76,17 +78,12 @@ private extension NativeBannerContainerView {
extension NativeBannerContainerView: NativeAdLoaderDelegate { extension NativeBannerContainerView: NativeAdLoaderDelegate {
func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) { func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
log.debug("Banner ad recieved (native_banner) by: \(String(describing: nativeAd.responseInfo.adNetworkClassName))") log.debug("Banner ad recieved (native_banner) by: \(String(describing: nativeAd.responseInfo.adNetworkClassName))")
guard let adView = NativeAdView.instantiateWithXib(adType: adType) else { return }
guard let nativeBannerView = NativeBannerView.instantiateWithXib() else { return }
let nativeAdItem = NativeAdItem(nativeAd: nativeAd, adUnitId: adLoader.adUnitID) let nativeAdItem = NativeAdItem(nativeAd: nativeAd, adUnitId: adLoader.adUnitID)
adView.nativeAdItem = nativeAdItem
nativeBannerView.nativeAdItem = nativeAdItem addAsSubview(view: adView)
addAsSubview(view: nativeBannerView)
print("native ad loader: \(String(describing: nativeAd.headline))") print("native ad loader: \(String(describing: nativeAd.headline))")
delegate?.adLoader(adLoader, didReceive: nativeAd) delegate?.adLoader(adLoader, didReceive: nativeAd)
} }
func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) { func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) {
......
...@@ -271,3 +271,4 @@ ...@@ -271,3 +271,4 @@
// Ads // Ads
"ads.native.sponsored" = "Sponsored"; "ads.native.sponsored" = "Sponsored";
"ads.placeholder" = "Advertisment";
...@@ -165,7 +165,6 @@ class ForecastTimePeriodView: UIView { ...@@ -165,7 +165,6 @@ class ForecastTimePeriodView: UIView {
} }
private func updateGraphLayout() { private func updateGraphLayout() {
print("[ForecastTimePeriod] Update graph layout")
graphRect = (stackView.arrangedSubviews.first as? PeriodButtonProtocol)?.graphRect ?? .zero graphRect = (stackView.arrangedSubviews.first as? PeriodButtonProtocol)?.graphRect ?? .zero
graphView.frame = .init(x: 0, graphView.frame = .init(x: 0,
y: graphRect.origin.y, y: graphRect.origin.y,
...@@ -299,8 +298,6 @@ class ForecastTimePeriodView: UIView { ...@@ -299,8 +298,6 @@ class ForecastTimePeriodView: UIView {
self.graphView.drawAdditionalGraph(with: [CGPoint]()) self.graphView.drawAdditionalGraph(with: [CGPoint]())
self.tintGraphAt(button: selectedButton) self.tintGraphAt(button: selectedButton)
} }
print("[ForecastTimePeriod] Draw graph")
} }
private func tintGraphAt(button:PeriodButtonProtocol) { private func tintGraphAt(button:PeriodButtonProtocol) {
......
//
// TodayAdCell.swift
// 1Weather
//
// Created by Dmitry Stepanets on 12.02.2021.
//
import UIKit
protocol AdCell {
var adView: AdView? { get set }
}
// //
// TodayAdCell.swift // BannerAdCell.swift
// 1Weather // 1Weather
// //
// Created by Dmitry Stepanets on 12.02.2021. // Created by Dmitry Stepanets on 12.02.2021.
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
import UIKit import UIKit
class AdCell: UITableViewCell { class BannerAdCell: UITableViewCell, AdCell {
//Private //Private
private let container = UIView() private let container = UIView()
private let label = UILabel() private let label = UILabel()
...@@ -60,7 +61,7 @@ class AdCell: UITableViewCell { ...@@ -60,7 +61,7 @@ class AdCell: UITableViewCell {
} }
//MARK:- Prepare //MARK:- Prepare
private extension AdCell { private extension BannerAdCell {
func prepareCellStyle() { func prepareCellStyle() {
selectionStyle = .none selectionStyle = .none
} }
...@@ -82,7 +83,7 @@ private extension AdCell { ...@@ -82,7 +83,7 @@ private extension AdCell {
subview.removeFromSuperview() subview.removeFromSuperview()
} }
label.text = "Advertisment" label.text = "ads.placeholder".localized()
label.font = AppFont.SFPro.regular(size: 14) label.font = AppFont.SFPro.regular(size: 14)
container.addSubview(label) container.addSubview(label)
......
//
// MRECAdCell.swift
// 1Weather
//
// Created by Demid Merzlyakov on 08.06.2021.
//
import UIKit
class MRECAdCell: UITableViewCell, AdCell {
//Private
private let container = UIView()
private let label = UILabel()
public var adView: AdView? = nil {
didSet {
guard adView != oldValue else {
return
}
prepareAd()
}
}
private let gradientView = GradientView(startColor: UIColor.white.withAlphaComponent(0),
endColor: UIColor(hex: 0xdaddec),
opacity: 0.5)
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareCellStyle()
prepareContainer()
prepareAd()
prepareGradient()
updateUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateUI()
}
private func updateUI() {
contentView.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
container.backgroundColor = ThemeManager.currentTheme.containerBackgroundColor
label.textColor = ThemeManager.currentTheme.secondaryTextColor
switch interfaceStyle {
case .light:
gradientView.isHidden = false
container.layer.borderWidth = 1 / UIScreen.main.scale
container.layer.borderColor = UIColor(hex: 0xc7c7c7).cgColor
case .dark:
gradientView.isHidden = true
container.layer.borderWidth = 0
}
}
}
//MARK:- Prepare
private extension MRECAdCell {
func prepareCellStyle() {
selectionStyle = .none
}
func prepareContainer() {
label.text = "ads.placeholder".localized()
label.font = AppFont.SFPro.regular(size: 10)
label.textColor = ThemeManager.currentTheme.secondaryTextColor
contentView.addSubview(label)
contentView.addSubview(container)
label.snp.makeConstraints { make in
make.top.equalToSuperview().inset(18)
make.trailing.equalTo(container.snp.trailing)
}
container.snp.makeConstraints { (make) in
make.top.equalTo(label.snp.bottom).offset(6)
make.height.equalTo(250)
make.bottom.equalToSuperview().inset(18)
make.centerX.equalToSuperview()
make.width.equalTo(300)
}
}
func prepareAd() {
for subview in container.subviews {
subview.removeFromSuperview()
}
label.snp.makeConstraints { (make) in
make.center.equalToSuperview()
}
if let adView = adView {
container.addSubview(adView)
adView.snp.makeConstraints { (make) in
make.center.equalToSuperview()
make.size.equalToSuperview()
}
}
}
func prepareGradient() {
contentView.addSubview(gradientView)
contentView.bringSubviewToFront(container)
gradientView.snp.makeConstraints { (make) in
make.left.bottom.right.equalToSuperview()
make.height.equalToSuperview().multipliedBy(0.5)
}
}
}
...@@ -10,11 +10,8 @@ import UIKit ...@@ -10,11 +10,8 @@ import UIKit
private enum DailyForecastCellType:Int, CaseIterable { private enum DailyForecastCellType:Int, CaseIterable {
case forecast = 0 case forecast = 0
case forecastInfo case forecastInfo
case ad case adBanner
// case forecast case adMREC
// case conditions
// case precipitation
// case dayTime
case sun case sun
case moon case moon
} }
...@@ -22,7 +19,8 @@ private enum DailyForecastCellType:Int, CaseIterable { ...@@ -22,7 +19,8 @@ private enum DailyForecastCellType:Int, CaseIterable {
private enum HourlyForecastCellType: Int, CaseIterable { private enum HourlyForecastCellType: Int, CaseIterable {
case day case day
case forecastHourly case forecastHourly
case ad case adBanner
case adMREC
case precipitation case precipitation
case wind case wind
} }
...@@ -66,7 +64,8 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -66,7 +64,8 @@ class ForecastCellFactory: CellFactoryProtocol {
registerCell(type: ForecastWindSpeedCell.self, tableView: tableView) registerCell(type: ForecastWindSpeedCell.self, tableView: tableView)
registerCell(type: SunPhaseCell.self, tableView: tableView) registerCell(type: SunPhaseCell.self, tableView: tableView)
registerCell(type: MoonPhaseCell.self, tableView: tableView) registerCell(type: MoonPhaseCell.self, tableView: tableView)
registerCell(type: AdCell.self, tableView: tableView) registerCell(type: BannerAdCell.self, tableView: tableView)
registerCell(type: MRECAdCell.self, tableView: tableView)
} }
public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell { public func cellFromTableView(tableView:UITableView, indexPath:IndexPath) -> UITableViewCell {
...@@ -117,7 +116,7 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -117,7 +116,7 @@ class ForecastCellFactory: CellFactoryProtocol {
var timePeriodString: String! var timePeriodString: String!
switch timePeriod { switch timePeriod {
case .daily: case .daily:
placementName = placementNameForecastExtendedBanner placementName = placementNameForecastDailyBanner
timePeriodString = "D" timePeriodString = "D"
case .hourly: case .hourly:
placementName = placementNameForecastHourlyBanner placementName = placementNameForecastHourlyBanner
...@@ -175,8 +174,12 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -175,8 +174,12 @@ class ForecastCellFactory: CellFactoryProtocol {
cell.configure(with: loc) cell.configure(with: loc)
} }
return cell return cell
case .ad: case .adBanner:
let cell = dequeueReusableCell(type: AdCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: BannerAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: timePeriod, indexPath: indexPath)
return cell
case .adMREC:
let cell = dequeueReusableCell(type: MRECAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: timePeriod, indexPath: indexPath) cell.adView = adView(for: timePeriod, indexPath: indexPath)
return cell return cell
} }
...@@ -221,8 +224,12 @@ class ForecastCellFactory: CellFactoryProtocol { ...@@ -221,8 +224,12 @@ class ForecastCellFactory: CellFactoryProtocol {
} }
} }
return cell return cell
case .ad: case .adBanner:
let cell = dequeueReusableCell(type: AdCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: BannerAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: timePeriod, indexPath: indexPath)
return cell
case .adMREC:
let cell = dequeueReusableCell(type: MRECAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: timePeriod, indexPath: indexPath) cell.adView = adView(for: timePeriod, indexPath: indexPath)
return cell return cell
} }
......
...@@ -12,7 +12,8 @@ fileprivate enum NWSAlertCellType: Int { ...@@ -12,7 +12,8 @@ fileprivate enum NWSAlertCellType: Int {
case header = 0 case header = 0
case forecastOffice case forecastOffice
case extendedInfoBlock case extendedInfoBlock
case ad case adBanner
case adMREC
} }
fileprivate protocol NWSAlertTableViewSection { fileprivate protocol NWSAlertTableViewSection {
...@@ -67,11 +68,11 @@ fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection { ...@@ -67,11 +68,11 @@ fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection {
return .extendedInfoBlock return .extendedInfoBlock
} }
if numberOfRows == 1 { if numberOfRows == 1 {
return .ad return .adBanner
} }
else { else {
if row == 1 { if row == 1 {
return .ad return .adBanner
} }
else { else {
return .extendedInfoBlock return .extendedInfoBlock
...@@ -115,7 +116,7 @@ class NWSAlertCellFactory: CellFactoryProtocol { ...@@ -115,7 +116,7 @@ class NWSAlertCellFactory: CellFactoryProtocol {
} }
let adView = adViewCache[indexPath] ?? AdView() let adView = adViewCache[indexPath] ?? AdView()
adView.loggingAlias = "⚠️ Alert Banner" adView.loggingAlias = "⚠️ Alert Banner"
adView.set(placementName: placementNamePrecipitationBanner, adType: .banner) adView.set(placementName: placementNameNWSAlertBanner, adType: .banner)
adViewCache[indexPath] = adView adViewCache[indexPath] = adView
return adView return adView
} }
...@@ -124,7 +125,8 @@ class NWSAlertCellFactory: CellFactoryProtocol { ...@@ -124,7 +125,8 @@ class NWSAlertCellFactory: CellFactoryProtocol {
registerCell(type: NWSAlertCell.self, tableView: tableView) registerCell(type: NWSAlertCell.self, tableView: tableView)
registerCell(type: NWSForecastOfficeTableViewCell.self, tableView: tableView) registerCell(type: NWSForecastOfficeTableViewCell.self, tableView: tableView)
registerCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView) registerCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView)
registerCell(type: AdCell.self, tableView: tableView) registerCell(type: BannerAdCell.self, tableView: tableView)
registerCell(type: MRECAdCell.self, tableView: tableView)
} }
func cellFromTableView(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell { func cellFromTableView(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
...@@ -147,10 +149,14 @@ class NWSAlertCellFactory: CellFactoryProtocol { ...@@ -147,10 +149,14 @@ class NWSAlertCellFactory: CellFactoryProtocol {
let extendedInfoBlockCell = dequeueReusableCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView, indexPath: indexPath) let extendedInfoBlockCell = dequeueReusableCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView, indexPath: indexPath)
extendedInfoBlockCell.configure(with: info) extendedInfoBlockCell.configure(with: info)
return extendedInfoBlockCell return extendedInfoBlockCell
case .ad: case .adBanner:
let adCell = dequeueReusableCell(type: AdCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: BannerAdCell.self, tableView: tableView, indexPath: indexPath)
adCell.adView = adView(for: indexPath) cell.adView = adView(for: indexPath)
return adCell return cell
case .adMREC:
let cell = dequeueReusableCell(type: MRECAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: indexPath)
return cell
} }
} }
......
...@@ -11,7 +11,8 @@ import OneWeatherCore ...@@ -11,7 +11,8 @@ import OneWeatherCore
public enum TodayCellType:Int { public enum TodayCellType:Int {
case alert = 0 case alert = 0
case forecast case forecast
case ad case adBanner
case adMREC
case conditions case conditions
case forecastPeriod case forecastPeriod
case precipitation case precipitation
...@@ -54,9 +55,9 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -54,9 +55,9 @@ class TodayCellFactory: CellFactoryProtocol {
private var cellsToUpdate:CellsToUpdate = [.condition, .timePeriod, .precipitation, .dayTime] private var cellsToUpdate:CellsToUpdate = [.condition, .timePeriod, .precipitation, .dayTime]
private let todayViewModel:TodayViewModel private let todayViewModel:TodayViewModel
private var todaySection = TodaySection(allRows: [.alert, .forecast, .ad, private var todaySection = TodaySection(allRows: [.alert, .forecast, .adBanner,
.conditions, .forecastPeriod, .precipitation, .conditions, .forecastPeriod, .precipitation,
.airQuality, .dayTime, .sun, .moon]) .airQuality, .dayTime, .sun, .moon, .adMREC])
private var adViewCache = [IndexPath: AdView]() private var adViewCache = [IndexPath: AdView]()
...@@ -76,7 +77,8 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -76,7 +77,8 @@ class TodayCellFactory: CellFactoryProtocol {
public func registerCells(on tableView:UITableView) { public func registerCells(on tableView:UITableView) {
registerCell(type: TodayAlertCell.self, tableView: tableView) registerCell(type: TodayAlertCell.self, tableView: tableView)
registerCell(type: TodayForecastCell.self, tableView: tableView) registerCell(type: TodayForecastCell.self, tableView: tableView)
registerCell(type: AdCell.self, tableView: tableView) registerCell(type: BannerAdCell.self, tableView: tableView)
registerCell(type: MRECAdCell.self, tableView: tableView)
registerCell(type: TodayConditionsCell.self, tableView: tableView) registerCell(type: TodayConditionsCell.self, tableView: tableView)
registerCell(type: TodayForecastTimePeriodCell.self, tableView: tableView) registerCell(type: TodayForecastTimePeriodCell.self, tableView: tableView)
registerCell(type: PrecipitationCell.self, tableView: tableView) registerCell(type: PrecipitationCell.self, tableView: tableView)
...@@ -92,7 +94,11 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -92,7 +94,11 @@ class TodayCellFactory: CellFactoryProtocol {
} }
let adView = AdView() let adView = AdView()
adView.loggingAlias = "📍 Today Banner" adView.loggingAlias = "📍 Today Banner"
adView.set(placementName: placementNameTodayBanner, adType: .banner) var adType = AdType.banner
if cellType(at: indexPath) == .adMREC {
adType = .square
}
adView.set(placementName: placementNameTodayBanner, adType: adType)
adViewCache[indexPath] = adView adViewCache[indexPath] = adView
return adView return adView
} }
...@@ -117,16 +123,17 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -117,16 +123,17 @@ class TodayCellFactory: CellFactoryProtocol {
let cell = dequeueReusableCell(type: TodayForecastCell.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 .adBanner:
let cell = dequeueReusableCell(type: AdCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: BannerAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: indexPath)
return cell
case .adMREC:
let cell = dequeueReusableCell(type: MRECAdCell.self, tableView: tableView, indexPath: indexPath)
cell.adView = adView(for: indexPath) cell.adView = adView(for: indexPath)
return cell return cell
case .conditions: case .conditions:
let cell = dequeueReusableCell(type: TodayConditionsCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayConditionsCell.self, tableView: tableView, indexPath: indexPath)
// if cellsToUpdate.contains(.condition) {
cell.configure(with: loc) cell.configure(with: loc)
// cellsToUpdate.remove(.condition)
// }
return cell return cell
case .forecastPeriod: case .forecastPeriod:
let cell = dequeueReusableCell(type: TodayForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath) let cell = dequeueReusableCell(type: TodayForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath)
...@@ -195,7 +202,8 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -195,7 +202,8 @@ class TodayCellFactory: CellFactoryProtocol {
var rowsToHide = Set<TodayCellType>() var rowsToHide = Set<TodayCellType>()
if isAppPro() || !AdConfigManager.shared.adConfig.adsEnabled { if isAppPro() || !AdConfigManager.shared.adConfig.adsEnabled {
rowsToHide.insert(.ad) rowsToHide.insert(.adBanner)
rowsToHide.insert(.adMREC)
} }
let location = self.todayViewModel.location let location = self.todayViewModel.location
......
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