[core][android][ios] native name fix

This commit is contained in:
Arsentiy Milchakov 2017-01-27 10:47:33 +03:00 committed by Илья Гречухин
parent df9dcf693e
commit ed83b39589
6 changed files with 33 additions and 16 deletions

View file

@ -304,9 +304,9 @@ Java_com_mapswithme_maps_editor_Editor_nativeIsBuilding(JNIEnv * env, jclass cla
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetNamesDataSource(JNIEnv * env, jclass)
Java_com_mapswithme_maps_editor_Editor_nativeGetNamesDataSource(JNIEnv * env, jclass, jboolean needFakes)
{
auto const namesDataSource = g_editableMapObject.GetNamesDataSource();
auto const namesDataSource = g_editableMapObject.GetNamesDataSource(needFakes);
jobjectArray names = jni::ToJavaArray(env, g_localNameClazz, namesDataSource.names, ToJavaName);
jint mandatoryNamesCount = namesDataSource.mandatoryNamesCount;

View file

@ -102,7 +102,7 @@ public final class Editor
public static native boolean nativeIsNameEditable();
public static native boolean nativeIsBuilding();
public static native NamesDataSource nativeGetNamesDataSource();
public static native NamesDataSource nativeGetNamesDataSource(boolean needFakes);
public static native String nativeGetDefaultName();
public static native void nativeEnableNamesAdvancedMode();
public static native void nativeSetNames(@NonNull LocalizedName[] names);

View file

@ -103,6 +103,14 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
mMandatoryNamesCount = mandatoryNamesCount;
}
private void fillNames(boolean needFakes)
{
NamesDataSource namesDataSource = Editor.nativeGetNamesDataSource(needFakes);
setNames(namesDataSource.getNames());
setMandatoryNamesCount(namesDataSource.getMandatoryNamesCount());
editMapObject();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
@ -128,10 +136,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
mIsNewObject = getArguments().getBoolean(EditorActivity.EXTRA_NEW_OBJECT, false);
mToolbarController.setTitle(getTitle());
NamesDataSource namesDataSource = Editor.nativeGetNamesDataSource();
setNames(namesDataSource.getNames());
setMandatoryNamesCount(namesDataSource.getMandatoryNamesCount());
editMapObject();
fillNames(true /* addFakes */);
}
@StringRes
@ -373,6 +378,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
String name = "";
if (lang.code.equals(Language.DEFAULT_LANG_CODE))
{
fillNames(false /* addFakes */);
name = Editor.nativeGetDefaultName();
Editor.nativeEnableNamesAdvancedMode();
}

View file

@ -212,7 +212,7 @@ vector<feature::Metadata::EType> const & EditableMapObject::GetEditableFields()
StringUtf8Multilang const & EditableMapObject::GetName() const { return m_name; }
NamesDataSource EditableMapObject::GetNamesDataSource()
NamesDataSource EditableMapObject::GetNamesDataSource(bool needFakes /* = true */)
{
auto const mwmInfo = GetID().m_mwmId.GetInfo();
@ -224,13 +224,20 @@ NamesDataSource EditableMapObject::GetNamesDataSource()
auto const userLangCode = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
StringUtf8Multilang fakeSource;
m_fakeNames = MakeFakeSource(m_name, mwmLanguages, fakeSource);
if (m_fakeNames.m_names.empty())
return GetNamesDataSource(m_name, mwmLanguages, userLangCode);
if (needFakes)
{
StringUtf8Multilang fakeSource;
m_fakeNames = MakeFakeSource(m_name, mwmLanguages, fakeSource);
return GetNamesDataSource(fakeSource, mwmLanguages, userLangCode);
if (!m_fakeNames.m_names.empty())
return GetNamesDataSource(fakeSource, mwmLanguages, userLangCode);
}
else
{
RemoveFakeNames(m_fakeNames, m_name);
}
return GetNamesDataSource(m_name, mwmLanguages, userLangCode);
}
// static

View file

@ -103,7 +103,7 @@ public:
StringUtf8Multilang const & GetName() const;
/// See comment for NamesDataSource class.
NamesDataSource GetNamesDataSource();
NamesDataSource GetNamesDataSource(bool addFakes = true);
LocalizedStreet const & GetStreet() const;
vector<LocalizedStreet> const & GetNearbyStreets() const;
string const & GetHouseNumber() const;

View file

@ -538,7 +538,11 @@ void registerCellsForTableView(vector<MWMPlacePageCellType> const & cells, UITab
MWMEditorAdditionalNameTableViewCell * tCell =
static_cast<MWMEditorAdditionalNameTableViewCell *>(cell);
auto const & localizedNames = m_mapObject.GetNamesDataSource().names;
// When default name is added - remove fake names from datasource.
auto const it = std::find(m_newAdditionalLanguages.begin(), m_newAdditionalLanguages.end(),
StringUtf8Multilang::kDefaultCode);
auto const needFakes = it == m_newAdditionalLanguages.end();
auto const & localizedNames = m_mapObject.GetNamesDataSource(needFakes).names;
if (indexPath.row < localizedNames.size())
{