Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
fda52da8
Commit
fda52da8
authored
Jun 10, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS-73: hide adviews when there are no ads.
parent
dc0d546b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
158 additions
and
35 deletions
+158
-35
1Weather/Ads/AdView.swift
+19
-7
1Weather/Common/CellFactory.swift
+13
-8
1Weather/UI/SharedCells/AdCells/BannerAdCell.swift
+2
-0
1Weather/UI/SharedCells/AdCells/MRECAdCell.swift
+3
-2
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
+0
-0
1Weather/UI/View controllers/Forecast/ForecastViewController.swift
+11
-1
1Weather/UI/View controllers/Locations/Cells/LocationCellFactory.swift
+1
-1
1Weather/UI/View controllers/Menu/Cells/MenuCellFactory.swift
+1
-1
1Weather/UI/View controllers/NWSAlert/Cells/NWSAlertCellFactory.swift
+47
-8
1Weather/UI/View controllers/NWSAlert/NWSAlertViewController.swift
+1
-1
1Weather/UI/View controllers/Radar/Cells/RadarLayersCellFactory.swift
+1
-1
1Weather/UI/View controllers/Settings/Cells/SettingsCellFactory.swift
+1
-1
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCellFactory.swift
+1
-1
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+34
-1
1Weather/UI/View controllers/Today/TodayViewController.swift
+4
-1
1Weather/ViewModels/NWSAlertViewModel.swift
+9
-0
1Weather/ViewModels/TodayViewModel.swift
+10
-1
No files found.
1Weather/Ads/AdView.swift
View file @
fda52da8
...
...
@@ -10,13 +10,22 @@ import Foundation
import
GoogleMobileAds
import
UIKit
@objc
public
protocol
AdViewDelegate
:
AnyObject
{
func
succeeded
(
adView
:
AdView
)
func
failed
(
adView
:
AdView
)
func
succeeded
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
func
failed
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
func
closeButtonTapped
(
adView
:
AdView
)
/// Return the view controller, that will present the interstitial.
func
adTopViewController
()
->
UIViewController
func
adTopViewController
()
->
UIViewController
?
}
// MARK: - Default methods implementation
extension
AdViewDelegate
{
func
closeButtonTapped
(
adView
:
AdView
)
{
// do nothing
}
func
adTopViewController
()
->
UIViewController
?
{
return
nil
}
}
@objcMembers
...
...
@@ -324,22 +333,25 @@ extension AdView {
extension
AdView
:
NativeBannerContainerViewDelegate
{
func
adLoader
(
_
adLoader
:
GADAdLoader
,
didReceived
bannerView
:
GAMBannerView
)
{
log
.
info
(
"ad request succeeded"
)
let
hadAdBefore
=
adReady
adReady
=
true
analytics
(
log
:
.
ANALYTICS_AD_RECEIVED
,
params
:
self
.
analyticsParams
)
self
.
delegate
?
.
succeeded
(
adView
:
self
)
self
.
delegate
?
.
succeeded
(
adView
:
self
,
hadAdBefore
:
hadAdBefore
)
}
func
adLoader
(
_
adLoader
:
GADAdLoader
,
didReceive
nativeAd
:
GADNativeAd
)
{
log
.
info
(
"ad request succeeded"
)
let
hadAdBefore
=
adReady
adReady
=
true
analytics
(
log
:
.
ANALYTICS_AD_RECEIVED
,
params
:
self
.
analyticsParams
)
self
.
delegate
?
.
succeeded
(
adView
:
self
)
self
.
delegate
?
.
succeeded
(
adView
:
self
,
hadAdBefore
:
hadAdBefore
)
}
public
func
adLoader
(
_
adLoader
:
GADAdLoader
,
didFailToReceiveAdWithError
error
:
Error
)
{
log
.
error
(
"ad request failed"
)
let
hadAdBefore
=
adReady
adReady
=
false
self
.
delegate
?
.
failed
(
adView
:
self
)
self
.
delegate
?
.
failed
(
adView
:
self
,
hadAdBefore
:
hadAdBefore
)
}
}
...
...
1Weather/Common/CellFactory.swift
View file @
fda52da8
...
...
@@ -7,7 +7,19 @@
import
UIKit
extension
CellFactoryProtocol
{
public
protocol
CellFactory
{
var
numberOfSections
:
Int
{
get
}
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
func
registerCells
(
on
tableView
:
UITableView
)
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
}
public
protocol
CellFactoryDelegate
{
func
cellFactoryCellsChanged
(
_
factory
:
CellFactory
)
}
// MARK: - Default methods implementation
extension
CellFactory
{
func
dequeueReusableCell
<
T
:
ReusableCellProtocol
>
(
type
:
T
.
Type
,
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
T
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
T
.
kIdentifier
,
for
:
indexPath
)
as!
T
return
cell
...
...
@@ -17,10 +29,3 @@ extension CellFactoryProtocol {
tableView
.
register
(
type
,
forCellReuseIdentifier
:
T
.
kIdentifier
)
}
}
public
protocol
CellFactoryProtocol
{
var
numberOfSections
:
Int
{
get
}
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
func
registerCells
(
on
tableView
:
UITableView
)
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
}
1Weather/UI/SharedCells/AdCells/BannerAdCell.swift
View file @
fda52da8
...
...
@@ -64,10 +64,12 @@ class BannerAdCell: UITableViewCell, AdCell {
private
extension
BannerAdCell
{
func
prepareCellStyle
()
{
selectionStyle
=
.
none
clipsToBounds
=
true
}
func
prepareContainer
()
{
container
.
layer
.
cornerRadius
=
6
container
.
clipsToBounds
=
true
contentView
.
addSubview
(
container
)
container
.
snp
.
makeConstraints
{
(
make
)
in
...
...
1Weather/UI/SharedCells/AdCells/MRECAdCell.swift
View file @
fda52da8
...
...
@@ -26,7 +26,7 @@ class MRECAdCell: UITableViewCell, AdCell {
override
init
(
style
:
UITableViewCell
.
CellStyle
,
reuseIdentifier
:
String
?)
{
super
.
init
(
style
:
style
,
reuseIdentifier
:
reuseIdentifier
)
prepareCell
Style
()
prepareCell
()
prepareContainer
()
prepareAd
()
prepareGradient
()
...
...
@@ -58,8 +58,9 @@ class MRECAdCell: UITableViewCell, AdCell {
//MARK:- Prepare
private
extension
MRECAdCell
{
func
prepareCell
Style
()
{
func
prepareCell
()
{
selectionStyle
=
.
none
clipsToBounds
=
true
}
func
prepareContainer
()
{
...
...
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
View file @
fda52da8
This diff is collapsed.
Click to expand it.
1Weather/UI/View controllers/Forecast/ForecastViewController.swift
View file @
fda52da8
...
...
@@ -30,6 +30,7 @@ class ForecastViewController: UIViewController {
self
.
coordinator
=
coordinator
self
.
forecastCellFactory
=
ForecastCellFactory
(
viewModel
:
viewModel
)
super
.
init
(
nibName
:
nil
,
bundle
:
nil
)
self
.
forecastCellFactory
.
delegate
=
self
}
required
init
?(
coder
:
NSCoder
)
{
...
...
@@ -159,7 +160,6 @@ private extension ForecastViewController {
tableView
.
separatorStyle
=
.
none
tableView
.
tableFooterView
=
UIView
()
tableView
.
estimatedRowHeight
=
UITableView
.
automaticDimension
tableView
.
rowHeight
=
UITableView
.
automaticDimension
tableView
.
delegate
=
self
tableView
.
dataSource
=
self
view
.
addSubview
(
tableView
)
...
...
@@ -247,6 +247,10 @@ extension ForecastViewController: UITableViewDataSource {
return
forecastCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
}
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
forecastCellFactory
.
height
(
for
:
indexPath
)
}
}
//MARK:- ViewModel Delegate
...
...
@@ -278,3 +282,9 @@ extension ForecastViewController: DaysControlViewDelegate {
viewModel
.
offsetHolder
.
update
(
offset
:
offset
)
}
}
extension
ForecastViewController
:
CellFactoryDelegate
{
func
cellFactoryCellsChanged
(
_
factory
:
CellFactory
)
{
self
.
tableView
.
reloadData
()
}
}
1Weather/UI/View controllers/Locations/Cells/LocationCellFactory.swift
View file @
fda52da8
...
...
@@ -8,7 +8,7 @@
import
UIKit
import
OneWeatherCore
class
LocationCellFactory
:
CellFactory
Protocol
{
class
LocationCellFactory
:
CellFactory
{
//Private
private
let
locationsViewModel
:
LocationsViewModel
...
...
1Weather/UI/View controllers/Menu/Cells/MenuCellFactory.swift
View file @
fda52da8
...
...
@@ -91,7 +91,7 @@ private struct SectionItem {
let
rows
:[
MenuRow
]
}
class
MenuCellFactory
<
T
>
:
CellFactory
Protocol
{
class
MenuCellFactory
<
T
>
:
CellFactory
{
//Private
private
let
menuViewModel
:
MenuViewModel
private
let
sections
:[
SectionItem
]
=
[
SectionItem
(
type
:
.
info
,
rows
:
[
.
settings
]),
...
...
1Weather/UI/View controllers/NWSAlert/Cells/NWSAlertCellFactory.swift
View file @
fda52da8
...
...
@@ -72,8 +72,13 @@ fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection {
let
rows
:
[
NWSAlertCellType
]
=
[
.
extendedInfoBlock
]
}
class
NWSAlertCellFactory
:
CellFactoryProtocol
{
var
alert
:
NWSAlert
{
class
NWSAlertCellFactory
:
CellFactory
{
fileprivate
var
sections
:
[
NWSAlertTableViewSection
]
private
var
adViewCache
=
[
IndexPath
:
AdView
]()
public
var
delegate
:
CellFactoryDelegate
?
public
var
alert
:
NWSAlert
{
didSet
{
for
i
in
0
..<
sections
.
count
{
sections
[
i
]
.
update
(
with
:
alert
)
...
...
@@ -81,19 +86,28 @@ class NWSAlertCellFactory: CellFactoryProtocol {
}
}
init
(
alert
:
NWSAlert
)
{
public
init
(
alert
:
NWSAlert
)
{
self
.
alert
=
alert
self
.
sections
=
[
HeaderSection
(
alert
:
alert
),
ExtendedInfoSection
(
alert
:
alert
)]
}
fileprivate
var
sections
:
[
NWSAlertTableViewSection
]
private
var
adViewCache
=
[
IndexPath
:
AdView
]()
public
func
height
(
for
indexPath
:
IndexPath
)
->
CGFloat
{
let
cellType
=
cellType
(
at
:
indexPath
)
switch
cellType
{
case
.
adBanner
:
fallthrough
case
.
adMREC
:
let
adView
=
adView
(
for
:
indexPath
)
return
adView
.
adReady
?
UITableView
.
automaticDimension
:
0
default
:
return
UITableView
.
automaticDimension
}
}
var
numberOfSections
:
Int
{
public
var
numberOfSections
:
Int
{
return
sections
.
count
}
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
{
public
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
{
sections
[
section
]
.
numberOfRows
}
...
...
@@ -102,6 +116,7 @@ class NWSAlertCellFactory: CellFactoryProtocol {
return
adView
}
let
adView
=
adViewCache
[
indexPath
]
??
AdView
()
adView
.
delegate
=
self
adView
.
loggingAlias
=
"⚠️ Alert Banner"
adView
.
set
(
placementName
:
placementNameNWSAlertBanner
,
adType
:
.
banner
)
adViewCache
[
indexPath
]
=
adView
...
...
@@ -116,9 +131,14 @@ class NWSAlertCellFactory: CellFactoryProtocol {
registerCell
(
type
:
MRECAdCell
.
self
,
tableView
:
tableView
)
}
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
private
func
cellType
(
at
indexPath
:
IndexPath
)
->
NWSAlertCellType
{
let
section
=
sections
[
indexPath
.
section
]
let
type
=
section
.
type
(
forRow
:
indexPath
.
row
)
return
type
}
public
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
let
type
=
cellType
(
at
:
indexPath
)
switch
type
{
case
.
header
:
let
alertCell
=
dequeueReusableCell
(
type
:
NWSAlertCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
...
...
@@ -165,3 +185,22 @@ class NWSAlertCellFactory: CellFactoryProtocol {
}
}
}
// MARK: - AdViewDelegate
extension
NWSAlertCellFactory
:
AdViewDelegate
{
func
succeeded
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
{
onMain
{
if
hadAdBefore
!=
adView
.
adReady
{
self
.
delegate
?
.
cellFactoryCellsChanged
(
self
)
}
}
}
func
failed
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
{
onMain
{
if
hadAdBefore
!=
adView
.
adReady
{
self
.
delegate
?
.
cellFactoryCellsChanged
(
self
)
}
}
}
}
1Weather/UI/View controllers/NWSAlert/NWSAlertViewController.swift
View file @
fda52da8
...
...
@@ -109,7 +109,7 @@ extension NWSAlertViewController: UITableViewDelegate, UITableViewDataSource {
}
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
UITableView
.
automaticDimension
return
viewModel
.
cellFactory
.
height
(
for
:
indexPath
)
}
func
tableView
(
_
tableView
:
UITableView
,
estimatedHeightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
...
...
1Weather/UI/View controllers/Radar/Cells/RadarLayersCellFactory.swift
View file @
fda52da8
...
...
@@ -18,7 +18,7 @@ private struct LayerSection {
let
rowsCount
:
Int
}
class
RadarLayersCellFactory
:
CellFactory
Protocol
{
class
RadarLayersCellFactory
:
CellFactory
{
//Private
private
let
radarViewModel
:
RadarViewModel
private
let
sections
:[
LayerSection
]
...
...
1Weather/UI/View controllers/Settings/Cells/SettingsCellFactory.swift
View file @
fda52da8
...
...
@@ -84,7 +84,7 @@ private struct SettingsDataSource {
let
rows
:[
SettingsRow
]
}
class
SettingsCellFactory
:
CellFactory
Protocol
{
class
SettingsCellFactory
:
CellFactory
{
//Private
private
let
viewModel
:
SettingsViewModel
private
let
sections
:
[
SettingsDataSource
]
=
{
...
...
1Weather/UI/View controllers/Settings/Cells/SettingsDetailsCellFactory.swift
View file @
fda52da8
...
...
@@ -9,7 +9,7 @@ import UIKit
import
Localize_Swift
import
OneWeatherCore
class
SettingsDetailsCellFactory
:
CellFactory
Protocol
{
class
SettingsDetailsCellFactory
:
CellFactory
{
//Private
private
let
viewModel
:
SettingsDetailsViewModel
...
...
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
fda52da8
...
...
@@ -50,7 +50,7 @@ private struct TodaySection {
}
}
class
TodayCellFactory
:
CellFactory
Protocol
{
class
TodayCellFactory
:
CellFactory
{
//Private
private
var
cellsToUpdate
:
CellsToUpdate
=
[
.
condition
,
.
timePeriod
,
.
precipitation
,
.
dayTime
]
private
let
todayViewModel
:
TodayViewModel
...
...
@@ -62,6 +62,7 @@ class TodayCellFactory: CellFactoryProtocol {
private
var
adViewCache
=
[
IndexPath
:
AdView
]()
//Public
public
var
delegate
:
CellFactoryDelegate
?
init
(
viewModel
:
TodayViewModel
)
{
self
.
todayViewModel
=
viewModel
}
...
...
@@ -93,6 +94,7 @@ class TodayCellFactory: CellFactoryProtocol {
return
adView
}
let
adView
=
AdView
()
adView
.
delegate
=
self
adView
.
loggingAlias
=
"📍 Today Banner"
var
adType
=
AdType
.
banner
if
cellType
(
at
:
indexPath
)
==
.
adMREC
{
...
...
@@ -172,6 +174,18 @@ class TodayCellFactory: CellFactoryProtocol {
}
}
public
func
height
(
for
indexPath
:
IndexPath
)
->
CGFloat
{
let
cellType
=
cellType
(
at
:
indexPath
)
switch
cellType
{
case
.
adBanner
:
fallthrough
case
.
adMREC
:
let
adView
=
adView
(
for
:
indexPath
)
return
adView
.
adReady
?
UITableView
.
automaticDimension
:
0
default
:
return
UITableView
.
automaticDimension
}
}
public
func
setNeedsUpdate
()
{
cellsToUpdate
=
[
.
condition
,
.
timePeriod
,
.
precipitation
,
.
dayTime
]
setupHiddenRows
()
...
...
@@ -223,3 +237,22 @@ class TodayCellFactory: CellFactoryProtocol {
todaySection
.
hiddenRows
=
rowsToHide
}
}
// MARK: - AdViewDelegate
extension
TodayCellFactory
:
AdViewDelegate
{
func
succeeded
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
{
onMain
{
if
hadAdBefore
!=
adView
.
adReady
{
self
.
delegate
?
.
cellFactoryCellsChanged
(
self
)
}
}
}
func
failed
(
adView
:
AdView
,
hadAdBefore
:
Bool
)
{
onMain
{
if
hadAdBefore
!=
adView
.
adReady
{
self
.
delegate
?
.
cellFactoryCellsChanged
(
self
)
}
}
}
}
1Weather/UI/View controllers/Today/TodayViewController.swift
View file @
fda52da8
...
...
@@ -106,7 +106,6 @@ private extension TodayViewController {
tableView
.
separatorStyle
=
.
none
tableView
.
tableFooterView
=
UIView
()
tableView
.
estimatedRowHeight
=
UITableView
.
automaticDimension
tableView
.
rowHeight
=
UITableView
.
automaticDimension
tableView
.
delegate
=
self
tableView
.
dataSource
=
self
view
.
addSubview
(
tableView
)
...
...
@@ -126,6 +125,10 @@ extension TodayViewController: UITableViewDataSource {
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
return
viewModel
.
todayCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
}
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
return
viewModel
.
todayCellFactory
.
height
(
for
:
indexPath
)
}
}
//MARK:- UITableView Delegate
...
...
1Weather/ViewModels/NWSAlertViewModel.swift
View file @
fda52da8
...
...
@@ -25,6 +25,7 @@ class NWSAlertViewModel: ViewModelProtocol {
cellFactory
=
NWSAlertCellFactory
(
alert
:
alert
)
alertsManager
.
delegates
.
add
(
delegate
:
self
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handlePremiumStateChange
)
,
name
:
Notification
.
Name
(
rawValue
:
kEventInAppPurchasedCompleted
),
object
:
nil
)
cellFactory
.
delegate
=
self
}
@objc
...
...
@@ -35,6 +36,7 @@ class NWSAlertViewModel: ViewModelProtocol {
}
}
//MARK: - NWSAlertsManagerDelegate
extension
NWSAlertViewModel
:
NWSAlertsManagerDelegate
{
func
alertsListDidChange
(
in
alertsManager
:
NWSAlertsManager
)
{
// do nothing
...
...
@@ -48,3 +50,10 @@ extension NWSAlertViewModel: NWSAlertsManagerDelegate {
}
}
}
extension
NWSAlertViewModel
:
CellFactoryDelegate
{
func
cellFactoryCellsChanged
(
_
factory
:
CellFactory
)
{
delegate
?
.
viewModelDidChange
(
model
:
self
)
}
}
1Weather/ViewModels/TodayViewModel.swift
View file @
fda52da8
...
...
@@ -23,7 +23,9 @@ class TodayViewModel: ViewModelProtocol {
private(set)
var
location
:
Location
?
public
lazy
var
todayCellFactory
:
TodayCellFactory
=
{
TodayCellFactory
(
viewModel
:
self
)
let
factory
=
TodayCellFactory
(
viewModel
:
self
)
factory
.
delegate
=
self
return
factory
}()
deinit
{
...
...
@@ -129,3 +131,10 @@ extension TodayViewModel: SettingsDelegate {
delegate
?
.
viewModelDidChange
(
model
:
self
)
}
}
// MARK: CellFactoryDelegate
extension
TodayViewModel
:
CellFactoryDelegate
{
func
cellFactoryCellsChanged
(
_
factory
:
CellFactory
)
{
delegate
?
.
viewModelDidChange
(
model
:
self
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment