Skip to content

Commit

Permalink
[types_strings] review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arsentiy Milchakov authored and beloal committed Sep 25, 2018
1 parent a7681b5 commit c85aa17
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ private void showFilter()
private MapObject createMapObject(@NonNull Items.SearchItem item)
{
String featureType = item.getFeatureType();
String subtitle = TextUtils.isEmpty(featureType)
? ""
: Utils.getLocalizedFeatureType(getContext(), featureType);
String subtitle = Utils.getLocalizedFeatureType(getContext(), featureType);

String title = TextUtils.isEmpty(item.getTitle()) ? subtitle : item.getTitle();

Expand Down
7 changes: 4 additions & 3 deletions android/src/com/mapswithme/maps/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ public static void uploadChanges()
public static native boolean nativeSaveEditedFeature();

@NonNull
public static native String[] nativeGetAllCreatableFeatureTypes(String lang);
public static native String[] nativeGetAllCreatableFeatureTypes(@NonNull String lang);
@NonNull
public static native String[] nativeSearchCreatableFeatureTypes(String query, String lang);
public static native String[] nativeSearchCreatableFeatureTypes(@NonNull String query,
@NonNull String lang);

/**
* Creates new object on the map. Places it in the center of current viewport.
Expand All @@ -153,7 +154,7 @@ public static void createMapObject(FeatureCategory category)
{
nativeCreateMapObject(category.getType());
}
public static native void nativeCreateMapObject(String type);
public static native void nativeCreateMapObject(@NonNull String type);
public static native void nativeCreateNote(String text);
public static native void nativePlaceDoesNotExist(@NonNull String comment);
public static native void nativeRollbackMapObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void setFilter(String query)
? Editor.nativeGetAllCreatableFeatureTypes(locale)
: Editor.nativeSearchCreatableFeatureTypes(query, locale);

FeatureCategory[] categories = MakeFeatureCategoriesFromTypes(creatableTypes);
FeatureCategory[] categories = makeFeatureCategoriesFromTypes(creatableTypes);

getAdapter().setCategories(categories);
}
Expand All @@ -71,13 +71,13 @@ protected FeatureCategoryAdapter createAdapter()
String locale = Language.getDefaultLocale();
String[] creatableTypes = Editor.nativeGetAllCreatableFeatureTypes(locale);

FeatureCategory[] categories = MakeFeatureCategoriesFromTypes(creatableTypes);
FeatureCategory[] categories = makeFeatureCategoriesFromTypes(creatableTypes);

return new FeatureCategoryAdapter(this, categories, mSelectedCategory);
}

@NonNull
private FeatureCategory[] MakeFeatureCategoriesFromTypes(@NonNull String[] creatableTypes)
private FeatureCategory[] makeFeatureCategoriesFromTypes(@NonNull String[] creatableTypes)
{
FeatureCategory[] categories = new FeatureCategory[creatableTypes.length];

Expand Down
8 changes: 2 additions & 6 deletions android/src/com/mapswithme/maps/gallery/Holders.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ public void bind(@NonNull Items.SearchItem item)
super.bind(item);

String featureType = item.getFeatureType();
String localizedType = TextUtils.isEmpty(featureType)
? ""
: Utils.getLocalizedFeatureType(mSubtitle.getContext(), featureType);
String localizedType = Utils.getLocalizedFeatureType(mSubtitle.getContext(), featureType);
String title = TextUtils.isEmpty(item.getTitle()) ? localizedType : item.getTitle();

UiUtils.setTextAndHideIfEmpty(mTitle, title);
Expand Down Expand Up @@ -290,9 +288,7 @@ public HotelViewHolder(@NonNull View itemView, @NonNull List<Items.SearchItem> i
public void bind(@NonNull Items.SearchItem item)
{
String featureType = item.getFeatureType();
String localizedType = TextUtils.isEmpty(featureType)
? ""
: Utils.getLocalizedFeatureType(mSubtitle.getContext(), featureType);
String localizedType = Utils.getLocalizedFeatureType(mSubtitle.getContext(), featureType);
String title = TextUtils.isEmpty(item.getTitle()) ? localizedType : item.getTitle();

UiUtils.setTextAndHideIfEmpty(mTitle, title);
Expand Down
1 change: 0 additions & 1 deletion android/src/com/mapswithme/maps/search/SearchAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ int getTintAttr()
// FIXME: Better format based on result type
private CharSequence formatDescription(SearchResult result, boolean isHotelAvailable)
{

String localizedType = Utils.getLocalizedFeatureType(mFrame.getContext(),
result.description.featureType);
final SpannableStringBuilder res = new SpannableStringBuilder(localizedType);
Expand Down
11 changes: 9 additions & 2 deletions android/src/com/mapswithme/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,12 @@ public interface Proc<T>
void invoke(@NonNull T param);
}

public static String getLocalizedFeatureType(@NonNull Context context, @NonNull String type)
@NonNull
public static String getLocalizedFeatureType(@NonNull Context context, @Nullable String type)
{
if (TextUtils.isEmpty(type))
return "";

String key = "type." + type.replace('-', '.');

@StringRes
Expand All @@ -725,12 +729,15 @@ public static String getLocalizedFeatureType(@NonNull Context context, @NonNull
}
catch (Resources.NotFoundException e)
{
LOGGER.e(TAG, "Failed to get localized string for type'" + type + "'", e);
LOGGER.e(TAG, "Failed to get localized string for type '" + type + "'", e);
}

return type;
}

// Called from JNI.
@NonNull
@SuppressWarnings("unused")
public static String getLocalizedFeatureType(String type)
{
return getLocalizedFeatureType(MwmApplication.get(), type);
Expand Down
4 changes: 2 additions & 2 deletions editor/new_feature_categories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void NewFeatureCategories::AddLanguage(string lang)
lang = "en";
langCode = CategoriesHolder::kEnglishCode;
}
if (m_addedLangs.find(lang) != m_addedLangs.end())
if (m_addedLangs.Contains(langCode))
return;

auto const & c = classif();
Expand All @@ -55,7 +55,7 @@ void NewFeatureCategories::AddLanguage(string lang)
m_index.AddCategoryByTypeAndLang(c.GetTypeByReadableObjectName(type), langCode);
}

m_addedLangs.insert(lang);
m_addedLangs.Insert(langCode);
}

NewFeatureCategories::TypeNames NewFeatureCategories::Search(string const & query) const
Expand Down
7 changes: 6 additions & 1 deletion editor/new_feature_categories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include "editor/editor_config.hpp"

#include "indexer/categories_holder.hpp"
#include "indexer/categories_index.hpp"

#include "base/macros.hpp"
#include "base/small_set.hpp"

#include "std/cstdint.hpp"
#include "std/string.hpp"
Expand Down Expand Up @@ -48,8 +50,11 @@ class NewFeatureCategories
TypeNames const & GetAllCreatableTypeNames() const;

private:
using Langs =
base::SmallSet<static_cast<uint64_t>(CategoriesHolder::kMaxSupportedLocaleIndex) + 1>;

indexer::CategoriesIndex m_index;
unordered_set<string> m_addedLangs;
Langs m_addedLangs;
TypeNames m_types;

DISALLOW_COPY(NewFeatureCategories);
Expand Down

0 comments on commit c85aa17

Please sign in to comment.