diff --git a/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp b/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp index 746f655672..37162cbbcc 100644 --- a/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp +++ b/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp @@ -5,6 +5,7 @@ #include "com/mapswithme/maps/SearchEngine.hpp" #include "map/discovery/discovery_manager.hpp" +#include "map/search_product_info.hpp" #include "geometry/mercator.hpp" @@ -58,6 +59,7 @@ void PrepareClassRefs(JNIEnv * env) struct DiscoveryCallback { void operator()(uint32_t const requestId, search::Results const & results, + std::vector const & productInfo, discovery::ItemType const type, m2::PointD const & viewportCenter) const { if (g_lastRequestId != requestId) @@ -68,7 +70,6 @@ struct DiscoveryCallback auto const lat = MercatorBounds::YToLat(viewportCenter.y); auto const lon = MercatorBounds::XToLon(viewportCenter.x); - std::vector productInfo(results.GetCount()); jni::TScopedLocalObjectArrayRef jResults( env, BuildSearchResults(results, productInfo, true /* hasPosition */, lat, lon)); jobject discoveryManagerInstance = env->GetStaticObjectField(g_discoveryManagerClass, diff --git a/iphone/Maps/UI/Discovery/DiscoveryControllerViewModel.hpp b/iphone/Maps/UI/Discovery/DiscoveryControllerViewModel.hpp index 03de8f02ae..b722d289b5 100644 --- a/iphone/Maps/UI/Discovery/DiscoveryControllerViewModel.hpp +++ b/iphone/Maps/UI/Discovery/DiscoveryControllerViewModel.hpp @@ -1,6 +1,7 @@ #pragma once #include "map/discovery/discovery_client_params.hpp" +#include "map/search_product_info.hpp" #include "partners_api/locals_api.hpp" #include "partners_api/viator_api.hpp" @@ -18,8 +19,9 @@ namespace discovery class DiscoveryControllerViewModel { public: - void SetSearchResults(search::Results const & res, m2::PointD const & viewportCenter, - ItemType const type) + void SetSearchResults(search::Results const & res, + std::vector const & productInfo, + m2::PointD const & viewportCenter, ItemType const type) { switch (type) { diff --git a/iphone/Maps/UI/Discovery/MWMDiscoveryController.mm b/iphone/Maps/UI/Discovery/MWMDiscoveryController.mm index d5bd4797e6..2231d3687c 100644 --- a/iphone/Maps/UI/Discovery/MWMDiscoveryController.mm +++ b/iphone/Maps/UI/Discovery/MWMDiscoveryController.mm @@ -14,6 +14,7 @@ #include "DiscoveryControllerViewModel.hpp" #include "map/discovery/discovery_client_params.hpp" +#include "map/search_product_info.hpp" #include "partners_api/locals_api.hpp" #include "partners_api/viator_api.hpp" @@ -38,12 +39,13 @@ namespace { struct Callback { - void operator()(uint32_t const requestId, search::Results const & results, ItemType const type, + void operator()(uint32_t const requestId, search::Results const & results, + vector const & productInfo, ItemType const type, m2::PointD const & viewportCenter) const { CHECK(m_setSearchResults, ()); CHECK(m_refreshSection, ()); - m_setSearchResults(results, viewportCenter, type); + m_setSearchResults(results, productInfo, viewportCenter, type); m_refreshSection(type); } @@ -63,8 +65,9 @@ struct Callback m_refreshSection(ItemType::LocalExperts); } - using SetSearchResults = function; + using SetSearchResults = + function const & productInfo, + m2::PointD const & viewportCenter, ItemType const type)>; using SetViatorProducts = function const & viator)>; using SetLocalExperts = function const & experts)>; using RefreshSection = function; @@ -106,7 +109,7 @@ struct Callback auto & cb = m_callback; cb.m_setLocalExperts = bind(&DiscoveryControllerViewModel::SetExperts, &m_model, _1); cb.m_setSearchResults = - bind(&DiscoveryControllerViewModel::SetSearchResults, &m_model, _1, _2, _3); + bind(&DiscoveryControllerViewModel::SetSearchResults, &m_model, _1, _2, _3, _4); cb.m_setViatorProducts = bind(&DiscoveryControllerViewModel::SetViator, &m_model, _1); cb.m_refreshSection = [self](ItemType const type) { [self.tableManager reloadItem:type]; }; } diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt index cc7721c930..6227500fbc 100644 --- a/map/CMakeLists.txt +++ b/map/CMakeLists.txt @@ -39,6 +39,8 @@ set( discovery/discovery_client_params.hpp discovery/discovery_manager.cpp discovery/discovery_manager.hpp + discovery/discovery_search_callback.cpp + discovery/discovery_search_callback.hpp discovery/discovery_search_params.hpp displacement_mode_manager.cpp displacement_mode_manager.hpp @@ -87,6 +89,7 @@ set( search_api.hpp search_mark.cpp search_mark.hpp + search_product_info.hpp taxi_delegate.cpp taxi_delegate.hpp track.cpp diff --git a/map/discovery/discovery_manager.hpp b/map/discovery/discovery_manager.hpp index bb489ec202..6c3fc21cc4 100644 --- a/map/discovery/discovery_manager.hpp +++ b/map/discovery/discovery_manager.hpp @@ -5,6 +5,7 @@ #include "map/discovery/discovery_client_params.hpp" #include "map/discovery/discovery_search_params.hpp" #include "map/search_api.hpp" +#include "map/search_product_info.hpp" #include "partners_api/booking_api.hpp" #include "partners_api/locals_api.hpp" @@ -114,10 +115,12 @@ public: { auto p = GetSearchParams(params, type); auto const viewportCenter = params.m_viewportCenter; - p.m_onResults = [requestId, onResult, type, viewportCenter](search::Results const & results) { + p.m_onResults = + [requestId, onResult, type, viewportCenter](search::Results const & results, + std::vector const & productInfo) { GetPlatform().RunTask(Platform::Thread::Gui, - [requestId, onResult, type, results, viewportCenter] { - onResult(requestId, results, type, viewportCenter); + [requestId, onResult, type, results, productInfo, viewportCenter] { + onResult(requestId, results, productInfo, type, viewportCenter); }); }; m_searchApi.SearchForDiscovery(p); diff --git a/map/discovery/discovery_search_callback.cpp b/map/discovery/discovery_search_callback.cpp new file mode 100644 index 0000000000..c45e6ae590 --- /dev/null +++ b/map/discovery/discovery_search_callback.cpp @@ -0,0 +1,28 @@ +#include "map/discovery/discovery_search_callback.hpp" + +#include +#include + +namespace search +{ +DiscoverySearchCallback::DiscoverySearchCallback(ProductInfo::Delegate & delegate, + DiscoverySearchParams::OnResults onResults) + : m_delegate(delegate) + , m_onResults(std::move(onResults)) +{ +} + +void DiscoverySearchCallback::operator()(Results const & results) +{ + auto const prevSize = m_productInfo.size(); + ASSERT_LESS_OR_EQUAL(prevSize, results.GetCount(), ()); + + for (size_t i = prevSize; i < results.GetCount(); ++i) + { + m_productInfo.push_back(m_delegate.GetProductInfo(results[i])); + } + + ASSERT_EQUAL(m_productInfo.size(), results.GetCount(), ()); + m_onResults(results, m_productInfo); +} +} // namespace search diff --git a/map/discovery/discovery_search_callback.hpp b/map/discovery/discovery_search_callback.hpp new file mode 100644 index 0000000000..c603eb88e3 --- /dev/null +++ b/map/discovery/discovery_search_callback.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "map/discovery/discovery_search_params.hpp" +#include "map/search_product_info.hpp" + +#include "search/result.hpp" + +#include +#include + +namespace search +{ +class DiscoverySearchCallback +{ +public: + DiscoverySearchCallback(ProductInfo::Delegate & delegate, + DiscoverySearchParams::OnResults onResults); + + void operator()(Results const & results); + +private: + ProductInfo::Delegate & m_delegate; + DiscoverySearchParams::OnResults m_onResults; + std::vector m_productInfo; +}; +} // namespace search diff --git a/map/discovery/discovery_search_params.hpp b/map/discovery/discovery_search_params.hpp index 9a73c3d76b..328b051148 100644 --- a/map/discovery/discovery_search_params.hpp +++ b/map/discovery/discovery_search_params.hpp @@ -1,6 +1,7 @@ #pragma once #include "map/discovery/discovery_client_params.hpp" +#include "map/search_product_info.hpp" #include "search/result.hpp" @@ -10,6 +11,7 @@ #include #include #include +#include namespace search { @@ -42,7 +44,8 @@ struct DiscoverySearchParams } }; - using OnResults = std::function; + using OnResults = + std::function const & productInfo)>; std::string m_query; size_t m_itemsCount = 0; diff --git a/map/everywhere_search_callback.cpp b/map/everywhere_search_callback.cpp index 9ea7de34d5..39ad55e9d9 100644 --- a/map/everywhere_search_callback.cpp +++ b/map/everywhere_search_callback.cpp @@ -5,10 +5,11 @@ namespace search { -EverywhereSearchCallback::EverywhereSearchCallback(Delegate & delegate, - booking::filter::Tasks const & bookingFilterTasks, - EverywhereSearchParams::OnResults onResults) - : m_delegate(delegate) +EverywhereSearchCallback::EverywhereSearchCallback( + Delegate & hotelsDelegate, ProductInfo::Delegate & productInfoDelegate, + booking::filter::Tasks const & bookingFilterTasks, EverywhereSearchParams::OnResults onResults) + : m_hotelsDelegate(hotelsDelegate) + , m_productInfoDelegate(productInfoDelegate) , m_onResults(std::move(onResults)) , m_bookingFilterTasks(bookingFilterTasks) { @@ -21,13 +22,14 @@ void EverywhereSearchCallback::operator()(Results const & results) for (size_t i = prevSize; i < results.GetCount(); ++i) { - m_productInfo.push_back(m_delegate.GetProductInfo(results[i])); + m_productInfo.push_back(m_productInfoDelegate.GetProductInfo(results[i])); } if (results.IsEndedNormal() && results.GetType() == Results::Type::Hotels && !m_bookingFilterTasks.IsEmpty()) { - m_delegate.FilterResultsForHotelsQuery(m_bookingFilterTasks, results, false /* inViewport */); + m_hotelsDelegate.FilterResultsForHotelsQuery(m_bookingFilterTasks, results, + false /* inViewport */); } ASSERT_EQUAL(m_productInfo.size(), results.GetCount(), ()); diff --git a/map/everywhere_search_callback.hpp b/map/everywhere_search_callback.hpp index 0b2e49075a..743aaf7e34 100644 --- a/map/everywhere_search_callback.hpp +++ b/map/everywhere_search_callback.hpp @@ -2,6 +2,7 @@ #include "map/booking_filter_params.hpp" #include "map/everywhere_search_params.hpp" +#include "map/search_product_info.hpp" #include "search/result.hpp" @@ -20,20 +21,19 @@ public: class Delegate { public: - virtual ~Delegate() = default; - - virtual ProductInfo GetProductInfo(Result const & result) const = 0; virtual void FilterResultsForHotelsQuery(booking::filter::Tasks const & filterTasks, search::Results const & results, bool inViewport) = 0; }; - EverywhereSearchCallback(Delegate & delegate, booking::filter::Tasks const & bookingFilterTasks, + EverywhereSearchCallback(Delegate & hotelsDelegate, ProductInfo::Delegate & productInfoDelegate, + booking::filter::Tasks const & bookingFilterTasks, EverywhereSearchParams::OnResults onResults); void operator()(Results const & results); private: - Delegate & m_delegate; + Delegate & m_hotelsDelegate; + ProductInfo::Delegate & m_productInfoDelegate; EverywhereSearchParams::OnResults m_onResults; std::vector m_productInfo; booking::filter::Tasks m_bookingFilterTasks; diff --git a/map/everywhere_search_params.hpp b/map/everywhere_search_params.hpp index 4f65f7079f..f0bf43d217 100644 --- a/map/everywhere_search_params.hpp +++ b/map/everywhere_search_params.hpp @@ -1,6 +1,7 @@ #pragma once #include "map/booking_filter_params.hpp" +#include "map/search_product_info.hpp" #include "search/hotels_filter.hpp" #include "search/result.hpp" @@ -12,14 +13,6 @@ namespace search { -struct ProductInfo -{ - static auto constexpr kInvalidRating = kInvalidRatingValue; - - bool m_isLocalAdsCustomer = false; - float m_ugcRating = kInvalidRating; -}; - struct EverywhereSearchParams { std::string m_query; diff --git a/map/search_api.cpp b/map/search_api.cpp index 9eb17d287b..d091a12557 100644 --- a/map/search_api.cpp +++ b/map/search_api.cpp @@ -1,6 +1,7 @@ #include "map/search_api.hpp" #include "map/bookmarks_search_params.hpp" +#include "map/discovery/discovery_search_callback.hpp" #include "map/discovery/discovery_search_params.hpp" #include "map/everywhere_search_params.hpp" #include "map/viewport_search_params.hpp" @@ -178,6 +179,7 @@ bool SearchAPI::SearchEverywhere(EverywhereSearchParams const & params) p.m_onResults = EverywhereSearchCallback( static_cast(*this), + static_cast(*this), params.m_bookingFilterTasks, [this, params](Results const & results, std::vector const & productInfo) { if (params.m_onResults) @@ -240,31 +242,33 @@ void SearchAPI::SearchForDiscovery(DiscoverySearchParams const & params) p.m_position = params.m_position; p.m_maxNumResults = resultsCount; p.m_mode = search::Mode::Everywhere; - p.m_onResults = [params](Results const & results) { + p.m_onResults = DiscoverySearchCallback( + static_cast(*this), + [params](Results const & results, std::vector const & productInfo) { if (!results.IsEndMarker()) return; switch (params.m_sortingType) { case DiscoverySearchParams::SortingType::None: - params.m_onResults(results); + params.m_onResults(results, productInfo); break; case DiscoverySearchParams::SortingType::HotelRating: { Results r(results); r.SortBy(DiscoverySearchParams::HotelRatingComparator()); - params.m_onResults(TrimResults(move(r), params.m_itemsCount)); + params.m_onResults(TrimResults(move(r), params.m_itemsCount), productInfo); break; } case DiscoverySearchParams::SortingType::Popularity: { Results r(results); r.SortBy(DiscoverySearchParams::PopularityComparator()); - params.m_onResults(TrimResults(move(r), params.m_itemsCount)); + params.m_onResults(TrimResults(move(r), params.m_itemsCount), productInfo); break; } } - }; + }); GetEngine().Search(p); } diff --git a/map/search_api.hpp b/map/search_api.hpp index 11e39d0dbf..6fb11b306d 100644 --- a/map/search_api.hpp +++ b/map/search_api.hpp @@ -2,7 +2,9 @@ #include "map/booking_filter_params.hpp" #include "map/bookmark.hpp" +#include "map/discovery/discovery_search_callback.hpp" #include "map/everywhere_search_callback.hpp" +#include "map/search_product_info.hpp" #include "map/viewport_search_callback.hpp" #include "search/downloader_search_callback.hpp" @@ -44,7 +46,8 @@ struct DownloaderSearchParams; class SearchAPI : public search::DownloaderSearchCallback::Delegate, public search::EverywhereSearchCallback::Delegate, - public search::ViewportSearchCallback::Delegate + public search::ViewportSearchCallback::Delegate, + public search::ProductInfo::Delegate { public: struct Delegate diff --git a/map/search_product_info.hpp b/map/search_product_info.hpp new file mode 100644 index 0000000000..77d04685ad --- /dev/null +++ b/map/search_product_info.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "search/result.hpp" + +namespace search +{ +struct ProductInfo +{ + class Delegate + { + public: + virtual ~Delegate() = default; + + virtual ProductInfo GetProductInfo(Result const & result) const = 0; + }; + + static auto constexpr kInvalidRating = kInvalidRatingValue; + + bool m_isLocalAdsCustomer = false; + float m_ugcRating = kInvalidRating; +}; +} diff --git a/xcode/map/map.xcodeproj/project.pbxproj b/xcode/map/map.xcodeproj/project.pbxproj index cae3a15f6b..d6a4e07019 100644 --- a/xcode/map/map.xcodeproj/project.pbxproj +++ b/xcode/map/map.xcodeproj/project.pbxproj @@ -32,6 +32,9 @@ 3D4E99A21FB4A6410025B48C /* booking_filter_cache.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D4E999E1FB4A6400025B48C /* booking_filter_cache.hpp */; }; 3D4E99A31FB4A6410025B48C /* booking_filter_cache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D4E999F1FB4A6400025B48C /* booking_filter_cache.cpp */; }; 3D4E99A51FB4A6410025B48C /* booking_filter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D4E99A11FB4A6410025B48C /* booking_filter.hpp */; }; + 3D62CBCC20F4DFD600E7BB6E /* search_product_info.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D62CBCB20F4DFD600E7BB6E /* search_product_info.hpp */; }; + 3D62CBCF20F4DFE800E7BB6E /* discovery_search_callback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D62CBCD20F4DFE700E7BB6E /* discovery_search_callback.cpp */; }; + 3D62CBD020F4DFE800E7BB6E /* discovery_search_callback.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D62CBCE20F4DFE700E7BB6E /* discovery_search_callback.hpp */; }; 3D74ABBE1EA76F1D0063A898 /* local_ads_supported_types.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */; }; 3DA5713F20B5CC80007BDE27 /* booking_availability_filter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DA5713A20B5CC7F007BDE27 /* booking_availability_filter.hpp */; }; 3DA5714020B5CC80007BDE27 /* booking_filter_params.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DA5713B20B5CC7F007BDE27 /* booking_filter_params.hpp */; }; @@ -247,6 +250,9 @@ 3D4E999E1FB4A6400025B48C /* booking_filter_cache.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = booking_filter_cache.hpp; sourceTree = ""; }; 3D4E999F1FB4A6400025B48C /* booking_filter_cache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = booking_filter_cache.cpp; sourceTree = ""; }; 3D4E99A11FB4A6410025B48C /* booking_filter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = booking_filter.hpp; sourceTree = ""; }; + 3D62CBCB20F4DFD600E7BB6E /* search_product_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = search_product_info.hpp; sourceTree = ""; }; + 3D62CBCD20F4DFE700E7BB6E /* discovery_search_callback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = discovery_search_callback.cpp; sourceTree = ""; }; + 3D62CBCE20F4DFE700E7BB6E /* discovery_search_callback.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = discovery_search_callback.hpp; sourceTree = ""; }; 3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = local_ads_supported_types.cpp; sourceTree = ""; }; 3DA5713A20B5CC7F007BDE27 /* booking_availability_filter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = booking_availability_filter.hpp; sourceTree = ""; }; 3DA5713B20B5CC7F007BDE27 /* booking_filter_params.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = booking_filter_params.hpp; sourceTree = ""; }; @@ -698,6 +704,7 @@ 675345BD1A4054AD00A0A8C3 /* map */ = { isa = PBXGroup; children = ( + 3D62CBCB20F4DFD600E7BB6E /* search_product_info.hpp */, 56C1165E2090E5670068BBC0 /* extrapolator.cpp */, 56C1165F2090E5670068BBC0 /* extrapolator.hpp */, 675345CB1A4054E800A0A8C3 /* address_finder.cpp */, @@ -811,6 +818,8 @@ F6FC3CB11FC323420001D929 /* discovery */ = { isa = PBXGroup; children = ( + 3D62CBCD20F4DFE700E7BB6E /* discovery_search_callback.cpp */, + 3D62CBCE20F4DFE700E7BB6E /* discovery_search_callback.hpp */, F69687C7201B4A3500457650 /* discovery_search_params.hpp */, F6FC3CB21FC323420001D929 /* discovery_client_params.hpp */, F6FC3CB31FC323420001D929 /* discovery_manager.cpp */, @@ -836,6 +845,7 @@ 454649F21F2728CE00EF4064 /* local_ads_mark.hpp in Headers */, BBA014AE2073C784007402E4 /* bookmark_helpers.hpp in Headers */, F6B283061C1B03320081957A /* gps_track_filter.hpp in Headers */, + 3D62CBCC20F4DFD600E7BB6E /* search_product_info.hpp in Headers */, F69687C8201B4A3600457650 /* discovery_search_params.hpp in Headers */, 3D4E99831FB462B60025B48C /* viewport_search_params.hpp in Headers */, 34583BD01C88556800F94664 /* place_page_info.hpp in Headers */, @@ -861,6 +871,7 @@ F6B2830A1C1B03320081957A /* gps_track.hpp in Headers */, 3D4E99A21FB4A6410025B48C /* booking_filter_cache.hpp in Headers */, F6D67CE32063F4980032FD38 /* framework_light.hpp in Headers */, + 3D62CBD020F4DFE800E7BB6E /* discovery_search_callback.hpp in Headers */, 45F6EE9D1FB1C77600019892 /* search_api.hpp in Headers */, 3DA5723120C195ED007BDE27 /* everywhere_search_callback.hpp in Headers */, 3DA5723020C195ED007BDE27 /* viewport_search_callback.hpp in Headers */, @@ -1051,6 +1062,7 @@ 3DA5723320C195ED007BDE27 /* viewport_search_callback.cpp in Sources */, 675346641A4054E800A0A8C3 /* framework.cpp in Sources */, BB4E5F281FCC664A00A77250 /* transit_reader.cpp in Sources */, + 3D62CBCF20F4DFE800E7BB6E /* discovery_search_callback.cpp in Sources */, 454649F11F2728CE00EF4064 /* local_ads_mark.cpp in Sources */, F63421F81DF9BF9100A96868 /* reachable_by_taxi_checker.cpp in Sources */, 56C116602090E5670068BBC0 /* extrapolator.cpp in Sources */,