[MAPSME-4213] Review fixes.

This commit is contained in:
Ilya Grechuhin 2017-04-17 16:45:11 +03:00 committed by Sergey Yershov
parent d09064eff5
commit af83a489b9
4 changed files with 25 additions and 23 deletions

View file

@ -15,8 +15,8 @@
+ (void)showResult:(search::Result const &)result;
+ (MWMSearchItemType)resultTypeWithIndex:(NSUInteger)index;
+ (NSUInteger)containerIndexWithIndex:(NSUInteger)index;
+ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row;
+ (NSUInteger)containerIndexWithRow:(NSUInteger)row;
+ (search::Result const &)resultWithContainerIndex:(NSUInteger)index;
+ (id<MWMBanner>)adWithContainerIndex:(NSUInteger)index;

View file

@ -227,16 +227,16 @@ using TObservers = NSHashTable<__kindof TObserver>;
return [[MWMSearch manager].banners bannerAtIndex:index];
}
+ (MWMSearchItemType)resultTypeWithIndex:(NSUInteger)index
+ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row
{
auto itemsIndex = [MWMSearch manager].itemsIndex;
return [itemsIndex resultTypeWithIndex:index];
return [itemsIndex resultTypeWithRow:row];
}
+ (NSUInteger)containerIndexWithIndex:(NSUInteger)index
+ (NSUInteger)containerIndexWithRow:(NSUInteger)row
{
auto itemsIndex = [MWMSearch manager].itemsIndex;
return [itemsIndex resultContainerIndexWithIndex:index];
return [itemsIndex resultContainerIndexWithRow:row];
}
+ (void)update { [[MWMSearch manager] update]; }
@ -300,9 +300,9 @@ using TObservers = NSHashTable<__kindof TObserver>;
- (void)updateItemsIndex
{
auto resultsCount = self->m_everywhereResults.GetCount();
auto itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount
resultsCount:resultsCount];
auto const resultsCount = self->m_everywhereResults.GetCount();
auto const itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount
resultsCount:resultsCount];
auto bannersCache = [MWMBannersCache cache];
if (resultsCount > 0)
{

View file

@ -20,14 +20,16 @@ final class SearchIndex: NSObject {
init(suggestionsCount: Int, resultsCount: Int) {
for index in 0..<resultsCount {
let type: MWMSearchItemType = index < suggestionsCount ? .suggestion : .regular
positionItems.append(PositionItem(item: Item(type: type, containerIndex: index), position: index))
let item = Item(type: type, containerIndex: index)
positionItems.append(PositionItem(item: item, position: index))
}
super.init()
}
func addItem(type: MWMSearchItemType, prefferedPosition: Int, containerIndex: Int) {
assert(type != .suggestion && type != .regular)
positionItems.append(PositionItem(item: Item(type: type, containerIndex: containerIndex), position: prefferedPosition))
let item = Item(type: type, containerIndex: containerIndex)
positionItems.append(PositionItem(item: item, position: prefferedPosition))
}
func build() {
@ -51,12 +53,12 @@ final class SearchIndex: NSObject {
}
}
func resultType(index: Int) -> MWMSearchItemType {
return items[index].type
func resultType(row: Int) -> MWMSearchItemType {
return items[row].type
}
func resultContainerIndex(index: Int) -> Int {
return items[index].containerIndex
func resultContainerIndex(row: Int) -> Int {
return items[row].containerIndex
}
}

View file

@ -75,15 +75,15 @@
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
auto const row = indexPath.row;
auto const containerIndex = [MWMSearch containerIndexWithIndex:row];
switch ([MWMSearch resultTypeWithIndex:row])
auto const containerIndex = [MWMSearch containerIndexWithRow:row];
switch ([MWMSearch resultTypeWithRow:row])
{
case MWMSearchItemTypeRegular:
{
auto cell = static_cast<MWMSearchSuggestionCell *>([tableView
dequeueReusableCellWithCellClass:[MWMSearchCommonCell class]
indexPath:indexPath]);
auto result = [MWMSearch resultWithContainerIndex:containerIndex];
auto const & result = [MWMSearch resultWithContainerIndex:containerIndex];
[cell config:result];
return cell;
}
@ -100,7 +100,7 @@
auto cell = static_cast<MWMSearchSuggestionCell *>([tableView
dequeueReusableCellWithCellClass:[MWMSearchSuggestionCell class]
indexPath:indexPath]);
auto suggestion = [MWMSearch resultWithContainerIndex:containerIndex];
auto const & suggestion = [MWMSearch resultWithContainerIndex:containerIndex];
[cell config:suggestion];
cell.isLastCell = row == [MWMSearch suggestionsCount] - 1;
return cell;
@ -114,21 +114,21 @@
{
id<MWMSearchTableViewProtocol> delegate = self.delegate;
auto const row = indexPath.row;
auto const containerIndex = [MWMSearch containerIndexWithIndex:row];
switch ([MWMSearch resultTypeWithIndex:row])
auto const containerIndex = [MWMSearch containerIndexWithRow:row];
switch ([MWMSearch resultTypeWithRow:row])
{
case MWMSearchItemTypeRegular:
{
MWMSearchTextField * textField = delegate.searchTextField;
[MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage];
auto result = [MWMSearch resultWithContainerIndex:containerIndex];
auto const & result = [MWMSearch resultWithContainerIndex:containerIndex];
[delegate processSearchWithResult:result];
break;
}
case MWMSearchItemTypeMopub: break;
case MWMSearchItemTypeSuggestion:
{
auto suggestion = [MWMSearch resultWithContainerIndex:containerIndex];
auto const & suggestion = [MWMSearch resultWithContainerIndex:containerIndex];
NSString * suggestionString = @(suggestion.GetSuggestionString());
[Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult)
withParameters:@{kStatValue : suggestionString, kStatScreen : kStatSearch}];