From 5f466cb201eb83583fee4afdeb3d2ffe5635f451 Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Tue, 23 Aug 2016 17:09:26 +0300 Subject: [PATCH] [android, ios, core] Add a single entity for search categories. --- android/jni/Android.mk | 1 + .../mapswithme/maps/DisplayedCategories.cpp | 11 ++++ android/res/values/arrays.xml | 58 ------------------- .../maps/search/CategoriesAdapter.java | 32 ++++++---- .../maps/search/DisplayedCategories.java | 8 +++ .../MWMSearchCategoriesManager.mm | 23 +++++--- search/displayed_categories.cpp | 13 +++++ search/displayed_categories.hpp | 12 ++++ search/search.pro | 2 + xcode/search/search.xcodeproj/project.pbxproj | 8 +++ 10 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 android/jni/com/mapswithme/maps/DisplayedCategories.cpp create mode 100644 android/src/com/mapswithme/maps/search/DisplayedCategories.java create mode 100644 search/displayed_categories.cpp create mode 100644 search/displayed_categories.hpp diff --git a/android/jni/Android.mk b/android/jni/Android.mk index b2e31bb7c3..5d72693732 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -72,6 +72,7 @@ LOCAL_HEADER_FILES := \ LOCAL_SRC_FILES := \ com/mapswithme/core/jni_helper.cpp \ com/mapswithme/core/logging.cpp \ + com/mapswithme/maps/DisplayedCategories.cpp \ com/mapswithme/maps/Framework.cpp \ com/mapswithme/maps/bookmarks/data/Bookmark.cpp \ com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp \ diff --git a/android/jni/com/mapswithme/maps/DisplayedCategories.cpp b/android/jni/com/mapswithme/maps/DisplayedCategories.cpp new file mode 100644 index 0000000000..9f3fb28f0c --- /dev/null +++ b/android/jni/com/mapswithme/maps/DisplayedCategories.cpp @@ -0,0 +1,11 @@ +#include "search/displayed_categories.hpp" + +#include "../core/jni_helper.hpp" + +extern "C" { +JNIEXPORT jobjectArray JNICALL +Java_com_mapswithme_maps_search_DisplayedCategories_nativeGet(JNIEnv * env, jclass clazz) +{ + return jni::ToJavaStringArray(env, search::GetDisplayedCategories()); +} +} // extern "C" diff --git a/android/res/values/arrays.xml b/android/res/values/arrays.xml index e541c7fb5f..9a99a2cda7 100644 --- a/android/res/values/arrays.xml +++ b/android/res/values/arrays.xml @@ -1,64 +1,6 @@ - - - @drawable/ic_category_food - @drawable/ic_category_hotel - @drawable/ic_category_tourism - @drawable/ic_category_wifi - @drawable/ic_category_transport - @drawable/ic_category_fuel - @drawable/ic_category_parking - @drawable/ic_category_shop - @drawable/ic_category_atm - @drawable/ic_category_bank - @drawable/ic_category_entertainment - @drawable/ic_category_hospital - @drawable/ic_category_pharmacy - @drawable/ic_category_police - @drawable/ic_category_toilet - @drawable/ic_category_post - - - - @drawable/ic_category_food_night - @drawable/ic_category_hotel_night - @drawable/ic_category_tourism_night - @drawable/ic_category_wifi_night - @drawable/ic_category_transport_night - @drawable/ic_category_fuel_night - @drawable/ic_category_parking_night - @drawable/ic_category_shop_night - @drawable/ic_category_atm_night - @drawable/ic_category_bank_night - @drawable/ic_category_entertainment_night - @drawable/ic_category_hospital_night - @drawable/ic_category_pharmacy_night - @drawable/ic_category_police_night - @drawable/ic_category_toilet_night - @drawable/ic_category_post_night - - - - @string/food - @string/hotel - @string/tourism - @string/wifi - @string/transport - @string/fuel - @string/parking - @string/shop - @string/atm - @string/bank - @string/entertainment - @string/hospital - @string/pharmacy - @string/police - @string/toilet - @string/post - - @drawable/img_first_start_offline diff --git a/android/src/com/mapswithme/maps/search/CategoriesAdapter.java b/android/src/com/mapswithme/maps/search/CategoriesAdapter.java index 17f1a8a702..669becf2a4 100644 --- a/android/src/com/mapswithme/maps/search/CategoriesAdapter.java +++ b/android/src/com/mapswithme/maps/search/CategoriesAdapter.java @@ -32,22 +32,32 @@ class CategoriesAdapter extends RecyclerView.Adapter kCategories; +@end @implementation MWMSearchCategoriesManager +- (instancetype)init +{ + self = [super init]; + if (self) + _kCategories = search::GetDisplayedCategories(); + return self; +} + - (void)attachCell:(MWMSearchTabbedCollectionViewCell *)cell { cell.noResultsView.hidden = YES; @@ -31,7 +40,7 @@ static size_t constexpr kCategoriesCount = ARRAY_SIZE(categoriesNames); - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return kCategoriesCount; + return self.kCategories.size(); } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -49,12 +58,12 @@ static size_t constexpr kCategoriesCount = ARRAY_SIZE(categoriesNames); - (void)tableView:(UITableView *)tableView willDisplayCell:(MWMSearchCategoryCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { - [cell setCategory:@(categoriesNames[indexPath.row])]; + [cell setCategory:@(self.kCategories[indexPath.row].c_str())]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - NSString * string = @(categoriesNames[indexPath.row]); + NSString * string = @(self.kCategories[indexPath.row].c_str()); [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) withParameters:@{kStatValue : string, kStatScreen : kStatCategories}]; [self.delegate searchText:[L(string) stringByAppendingString:@" "] forInputLocale:nil]; diff --git a/search/displayed_categories.cpp b/search/displayed_categories.cpp new file mode 100644 index 0000000000..227b8f3944 --- /dev/null +++ b/search/displayed_categories.cpp @@ -0,0 +1,13 @@ +#include "search/displayed_categories.hpp" + +namespace +{ +vector const kDisplayedCategories = { + "food", "hotel", "tourism", "wifi", "transport", "fuel", "parking", "shop", + "atm", "bank", "entertainment", "hospital", "pharmacy", "police", "toilet", "post"}; +} // namespace + +namespace search +{ +vector const & GetDisplayedCategories() { return kDisplayedCategories; } +} // namespace search diff --git a/search/displayed_categories.hpp b/search/displayed_categories.hpp new file mode 100644 index 0000000000..e8f90319b6 --- /dev/null +++ b/search/displayed_categories.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "std/string.hpp" +#include "std/vector.hpp" + +namespace search +{ +// Returns a list of english names of displayed categories for a +// categories search tab. It's guaranteed that the list is the same +// during the application lifetime. +vector const & GetDisplayedCategories(); +} // namespace search diff --git a/search/search.pro b/search/search.pro index 1eabe6ec22..9a89ea2f4a 100644 --- a/search/search.pro +++ b/search/search.pro @@ -14,6 +14,7 @@ HEADERS += \ cancel_exception.hpp \ cbv.hpp \ common.hpp \ + displayed_categories.hpp \ dummy_rank_table.hpp \ engine.hpp \ everywhere_search_params.hpp \ @@ -77,6 +78,7 @@ HEADERS += \ SOURCES += \ approximate_string_match.cpp \ cbv.cpp \ + displayed_categories.cpp \ dummy_rank_table.cpp \ engine.cpp \ features_filter.cpp \ diff --git a/xcode/search/search.xcodeproj/project.pbxproj b/xcode/search/search.xcodeproj/project.pbxproj index 2a11e712cd..b68b8fb68a 100644 --- a/xcode/search/search.xcodeproj/project.pbxproj +++ b/xcode/search/search.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 0810EC361D6D9D2E00ABFEE7 /* displayed_categories.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0810EC341D6D9D2E00ABFEE7 /* displayed_categories.cpp */; }; + 0810EC371D6D9D2E00ABFEE7 /* displayed_categories.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0810EC351D6D9D2E00ABFEE7 /* displayed_categories.hpp */; }; 342D83341D5233B3000D8AEA /* hotels_classifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 342D83301D5233B3000D8AEA /* hotels_classifier.cpp */; }; 342D83351D5233B3000D8AEA /* hotels_classifier.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 342D83311D5233B3000D8AEA /* hotels_classifier.hpp */; }; 3441CE4F1CFC1D7000CF30D4 /* processor_factory.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3441CE4A1CFC1D7000CF30D4 /* processor_factory.hpp */; }; @@ -164,6 +166,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0810EC341D6D9D2E00ABFEE7 /* displayed_categories.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = displayed_categories.cpp; sourceTree = ""; }; + 0810EC351D6D9D2E00ABFEE7 /* displayed_categories.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = displayed_categories.hpp; sourceTree = ""; }; 342D83301D5233B3000D8AEA /* hotels_classifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hotels_classifier.cpp; sourceTree = ""; }; 342D83311D5233B3000D8AEA /* hotels_classifier.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = hotels_classifier.hpp; sourceTree = ""; }; 3441CE4A1CFC1D7000CF30D4 /* processor_factory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = processor_factory.hpp; sourceTree = ""; }; @@ -409,6 +413,8 @@ 675346B21A4055CF00A0A8C3 /* search */ = { isa = PBXGroup; children = ( + 0810EC341D6D9D2E00ABFEE7 /* displayed_categories.cpp */, + 0810EC351D6D9D2E00ABFEE7 /* displayed_categories.hpp */, 3469FAD01D6C5D9C00F35A88 /* everywhere_search_params.hpp */, 3469FAD11D6C5D9C00F35A88 /* nearby_points_sweeper.cpp */, 3469FAD21D6C5D9C00F35A88 /* nearby_points_sweeper.hpp */, @@ -575,6 +581,7 @@ 345C8DB41D2D15A50037E3A6 /* streets_matcher.hpp in Headers */, 345C8DB21D2D15A50037E3A6 /* geocoder_context.hpp in Headers */, 56D5456F1C74A48C00E3719C /* mode.hpp in Headers */, + 0810EC371D6D9D2E00ABFEE7 /* displayed_categories.hpp in Headers */, 347F332A1C4540A8009758CC /* search_index_values.hpp in Headers */, 34B1CB791D22905800B59423 /* ranker.hpp in Headers */, 347F33161C4540A8009758CC /* cancel_exception.hpp in Headers */, @@ -749,6 +756,7 @@ 345C8DB11D2D15A50037E3A6 /* geocoder_context.cpp in Sources */, F652D8BF1CFDE1E800FC29A0 /* engine.cpp in Sources */, 675346DD1A40560D00A0A8C3 /* approximate_string_match.cpp in Sources */, + 0810EC361D6D9D2E00ABFEE7 /* displayed_categories.cpp in Sources */, 675346E51A40560D00A0A8C3 /* intermediate_result.cpp in Sources */, F652D9021CFDE21900FC29A0 /* pre_ranking_info.cpp in Sources */, 347F33261C4540A8009758CC /* reverse_geocoder.cpp in Sources */,