blob: 2fddb2ca53b8176a90e1ba49ec751f6c28c97fee (
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#import "MWMSearchHistoryManager.h"
#import "MWMCommon.h"
#import "MWMLocationManager.h"
#import "MWMSearchHistoryClearCell.h"
#import "MWMSearchHistoryRequestCell.h"
#import "MWMSearchNoResults.h"
#import "MapsAppDelegate.h"
#import "Statistics.h"
#import "SwiftBridge.h"
#include "Framework.h"
@interface MWMSearchHistoryManager ()
@property(weak, nonatomic) MWMSearchTabbedCollectionViewCell * cell;
@property(nonatomic) MWMSearchNoResults * noResultsView;
@end
@implementation MWMSearchHistoryManager
- (void)attachCell:(MWMSearchTabbedCollectionViewCell *)cell
{
self.cell = cell;
UITableView * tableView = cell.tableView;
tableView.estimatedRowHeight = 44.;
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.alpha = 1.0;
if (GetFramework().GetLastSearchQueries().empty())
{
tableView.hidden = YES;
[cell addNoResultsView:self.noResultsView];
}
else
{
[cell removeNoResultsView];
tableView.hidden = NO;
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerWithCellClass:[MWMSearchHistoryRequestCell class]];
[tableView registerWithCellClass:[MWMSearchHistoryClearCell class]];
[tableView reloadData];
}
}
- (search::QuerySaver::TSearchRequest const &)queryAtIndex:(NSInteger)index
{
Framework & f = GetFramework();
NSAssert(index >= 0 && index < f.GetLastSearchQueries().size(), @"Invalid search history index");
auto it = f.GetLastSearchQueries().cbegin();
advance(it, index);
return *it;
}
- (NSString *)stringAtIndex:(NSInteger)index
{
return @([self queryAtIndex:index].second.c_str());
}
- (BOOL)isRequestCell:(NSIndexPath *)indexPath
{
NSUInteger const row = indexPath.row;
return row < GetFramework().GetLastSearchQueries().size();
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return GetFramework().GetLastSearchQueries().size() + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self isRequestCell:indexPath])
{
auto tCell = static_cast<MWMSearchHistoryRequestCell *>([tableView
dequeueReusableCellWithCellClass:[MWMSearchHistoryRequestCell class]
indexPath:indexPath]);
[tCell config:[self stringAtIndex:indexPath.row]];
return tCell;
}
Class cls = [MWMSearchHistoryClearCell class];
return [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
id<MWMSearchTabbedViewProtocol> delegate = self.delegate;
if ([self isRequestCell:indexPath])
{
search::QuerySaver::TSearchRequest const & query = [self queryAtIndex:indexPath.row];
NSString * queryText = @(query.second.c_str());
[Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult)
withParameters:@{kStatValue : queryText, kStatScreen : kStatHistory}];
[delegate searchText:queryText forInputLocale:@(query.first.c_str())];
}
else
{
[Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult)
withParameters:@{kStatValue : kStatClear, kStatScreen : kStatHistory}];
GetFramework().ClearSearchHistory();
MWMSearchTabbedCollectionViewCell * cell = self.cell;
[UIView animateWithDuration:kDefaultAnimationDuration
animations:^{
cell.tableView.alpha = 0.0;
}
completion:^(BOOL finished) {
cell.tableView.hidden = YES;
[cell addNoResultsView:self.noResultsView];
}];
}
}
#pragma mark - Properties
- (MWMSearchNoResults *)noResultsView
{
if (!_noResultsView)
{
_noResultsView = [MWMSearchNoResults viewWithImage:[UIImage imageNamed:@"img_search_history"]
title:L(@"search_history_title")
text:L(@"search_history_text")];
}
return _noResultsView;
}
@end
|