blob: 7ce28c4ae97afb221f868d54ed6ff079d24fdd66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#import "MWMMapDownloaderExtendedDataSourceWithAds.h"
#import "MWMMapDownloaderAdsTableViewCell.h"
#import "MWMMyTarget.h"
#include "Framework.h"
namespace
{
auto constexpr extraSection = MWMMapDownloaderDataSourceExtraSection::Ads;
} // namespace
@interface MWMMapDownloaderExtendedDataSource ()
- (void)load;
- (void)addExtraSection:(MWMMapDownloaderDataSourceExtraSection)extraSection;
- (void)removeExtraSection:(MWMMapDownloaderDataSourceExtraSection)extraSection;
- (BOOL)isExtraSection:(MWMMapDownloaderDataSourceExtraSection)extraSection
atIndex:(NSInteger)sectionIndex;
@end
@implementation MWMMapDownloaderExtendedDataSourceWithAds
- (void)load
{
[super load];
if (self.mode == MWMMapDownloaderModeAvailable)
[self configAdsSection];
}
- (void)configAdsSection
{
[self removeExtraSection:extraSection];
if ([UIColor isNightMode] || !GetFramework().GetStorage().HaveDownloadedCountries())
return;
if ([MWMMyTarget manager].bannersCount != 0)
[self addExtraSection:extraSection];
}
- (MTRGAppwallBannerAdView *)viewForBannerAtIndex:(NSUInteger)index
{
MTRGAppwallBannerAdView * adView = [[MTRGAppwallBannerAdView alloc] initWithDelegate:nil];
adView.paddings = {.top = 12, .left = 16, .bottom = 12, .right = 16};
adView.touchColor = [UIColor white];
adView.normalColor = [UIColor white];
adView.iconSize = {24, 24};
UIEdgeInsets iconMargins = adView.iconMargins;
iconMargins.right += 8;
adView.iconMargins = iconMargins;
adView.showTopBorder = NO;
adView.showGotoAppIcon = NO;
adView.showRating = NO;
adView.showStatusIcon = NO;
adView.showBubbleIcon = NO;
adView.showCoins = NO;
adView.showCrossNotifIcon = NO;
adView.titleFont = [UIFont regular17];
adView.titleColor = [UIColor blackPrimaryText];
adView.descriptionColor = [UIColor blackSecondaryText];
adView.descriptionFont = [UIFont regular13];
[adView setAppWallBanner:[[MWMMyTarget manager] bannerAtIndex:index]];
return adView;
}
#pragma mark - MWMMapDownloaderDataSource
- (Class)cellClassForIndexPath:(NSIndexPath *)indexPath
{
if ([self isExtraSection:extraSection atIndex:indexPath.section])
return [MWMMapDownloaderAdsTableViewCell class];
return [super cellClassForIndexPath:indexPath];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self isExtraSection:extraSection atIndex:indexPath.section])
return NO;
return [super tableView:tableView canEditRowAtIndexPath:indexPath];
}
#pragma mark - Fill cells with data
- (void)fillCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
if (![self isExtraSection:extraSection atIndex:indexPath.section])
return [super fillCell:cell atIndexPath:indexPath];
MWMMapDownloaderAdsTableViewCell * tCell = static_cast<MWMMapDownloaderAdsTableViewCell *>(cell);
tCell.adView = [self viewForBannerAtIndex:indexPath.row];
[[MWMMyTarget manager] handleBannerShowAtIndex:indexPath.row];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self isExtraSection:extraSection atIndex:section])
return [MWMMyTarget manager].bannersCount;
return [super tableView:tableView numberOfRowsInSection:section];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if ([self isExtraSection:extraSection atIndex:section])
return L(@"MY.COM");
return [super tableView:tableView titleForHeaderInSection:section];
}
@end
|