From fb70ab13e216a5eec7ce846d109943077b1f900b Mon Sep 17 00:00:00 2001 From: VladiMihaylenko Date: Tue, 17 Apr 2018 18:32:56 +0300 Subject: [PATCH] [ios] Fixed ios bug with search similar. --- .../MWMSearchHotelsFilterViewController.mm | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/iphone/Maps/UI/Search/Filters/MWMSearchHotelsFilterViewController.mm b/iphone/Maps/UI/Search/Filters/MWMSearchHotelsFilterViewController.mm index ffa533be2b..c9fc4b06f9 100644 --- a/iphone/Maps/UI/Search/Filters/MWMSearchHotelsFilterViewController.mm +++ b/iphone/Maps/UI/Search/Filters/MWMSearchHotelsFilterViewController.mm @@ -9,6 +9,8 @@ #include "base/stl_helpers.hpp" +#include + namespace { static NSTimeInterval kDayInterval = 24 * 60 * 60; @@ -18,7 +20,8 @@ static uint8_t kAdultsCount = 2; static int8_t kAgeOfChild = 5; static NSString * const kHotelTypePattern = @"search_hotel_filter_%@"; -std::array(ftypes::IsHotelChecker::Type::Count)> const kTypes = {{ + +std::array const kTypes = {{ ftypes::IsHotelChecker::Type::Hotel, ftypes::IsHotelChecker::Type::Apartment, ftypes::IsHotelChecker::Type::CampSite, @@ -29,7 +32,7 @@ std::array(ftypes::IsHotelChec ftypes::IsHotelChecker::Type::Resort }}; -unsigned makeMask(std::vector const & items) +unsigned makeMask(std::unordered_set const & items) { unsigned mask = 0; for (auto const i : items) @@ -107,7 +110,7 @@ void configButton(UIButton * button, NSString * primaryText, NSString * secondar UICollectionViewDataSource, MWMFilterCheckCellDelegate, UITableViewDataSource> { - std::vector m_selectedTypes; + std::unordered_set m_selectedTypes; } @property(nonatomic) MWMFilterCheckCell * check; @@ -142,6 +145,7 @@ void configButton(UIButton * button, NSString * primaryText, NSString * secondar if (params.m_type != ftypes::IsHotelChecker::Type::Count) { + m_selectedTypes.emplace(params.m_type); [self.type.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:my::Key(params.m_type) inSection:0] @@ -474,7 +478,14 @@ void configButton(UIButton * button, NSString * primaryText, NSString * secondar auto const type = kTypes[indexPath.row]; auto str = [NSString stringWithFormat:kHotelTypePattern, @(ftypes::IsHotelChecker::GetHotelTypeTag(type))]; cell.tagName.text = L(str); - cell.selected = find(m_selectedTypes.begin(), m_selectedTypes.end(), type) != m_selectedTypes.end(); + auto const selected = m_selectedTypes.find(type) != m_selectedTypes.end(); + cell.selected = selected; + if (selected) + { + [collectionView selectItemAtIndexPath:indexPath animated:NO + scrollPosition:UICollectionViewScrollPositionNone]; + } + return cell; } @@ -502,13 +513,14 @@ void configButton(UIButton * button, NSString * primaryText, NSString * secondar } [Statistics logEvent:kStatSearchFilterClick withParameters:@{kStatCategory: kStatHotel, kStatType: typeString}]; - m_selectedTypes.emplace_back(type); + m_selectedTypes.emplace(type); } - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { auto const type = kTypes[indexPath.row]; - m_selectedTypes.erase(remove(m_selectedTypes.begin(), m_selectedTypes.end(), type)); + if (m_selectedTypes.find(type) != m_selectedTypes.end()) + m_selectedTypes.erase(type); } #pragma mark - Properties