Merge pull request #3264 from trashkalmar/editor-vaidate-floors

[android][editor] fix: Validate floor count in editor.
This commit is contained in:
Ilya Zverev 2016-05-19 13:37:10 +04:00
commit 84c4be2d77
6 changed files with 36 additions and 16 deletions

View file

@ -510,6 +510,13 @@ Java_com_mapswithme_maps_editor_Editor_nativeIsHouseValid(JNIEnv * env, jclass c
return osm::EditableMapObject::ValidateHouseNumber(jni::ToNativeString(env, houseNumber));
}
// static boolean nativeIsLevelValid(String level);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeIsLevelValid(JNIEnv * env, jclass clazz, jstring level)
{
return osm::EditableMapObject::ValidateBuildingLevels(jni::ToNativeString(env, level));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetCategory(JNIEnv * env, jclass clazz)
{

View file

@ -836,7 +836,7 @@
<string name="download_over_mobile_message">This could be considerably expensive with some plans or if roaming.</string>
<string name="error_enter_correct_house_number">Enter correct house number</string>
<string name="editor_storey_number">Building levels (max %d)</string>
<string name="error_enter_correct_storey_number">Buildigns at highest of 25 levels can be edited</string>
<string name="error_enter_correct_storey_number">Buildings at highest of 25 levels can be edited</string>
<string name="editor_zip_code">ZIP Code</string>
<string name="error_enter_correct_zip_code">Enter the correct ZIP Code</string>
<!-- Place Page title for long tap -->

View file

@ -112,6 +112,7 @@ public final class Editor
public static native String nativeGetHouseNumber();
public static native void nativeSetHouseNumber(String houseNumber);
public static native boolean nativeIsHouseValid(String houseNumber);
public static native boolean nativeIsLevelValid(String level);
public static native boolean nativeHasSomethingToUpload();
@WorkerThread

View file

@ -43,7 +43,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private EditText mName;
private RecyclerView mLocalizedNames;
private RecyclerView.AdapterDataObserver mLocalizedNamesObserver = new RecyclerView.AdapterDataObserver()
private final RecyclerView.AdapterDataObserver mLocalizedNamesObserver = new RecyclerView.AdapterDataObserver()
{
@Override
public void onChanged()
@ -85,6 +85,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private View mBlockLevels;
private EditText mBuildingLevels;
private TextInputLayout mInputHouseNumber;
private TextInputLayout mInputBuildingLevels;
private EditText mPhone;
private EditText mWebsite;
private EditText mEmail;
@ -120,25 +121,28 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mName.setText(Editor.nativeGetDefaultName());
final LocalizedStreet street = Editor.nativeGetStreet();
mStreet.setText(street.defaultName);
mHouseNumber.setText(Editor.nativeGetHouseNumber());
mHouseNumber.addTextChangedListener(new StringUtils.SimpleTextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
final String text = s.toString();
if (!Editor.nativeIsHouseValid(text))
{
UiUtils.setInputError(mInputHouseNumber, R.string.error_enter_correct_house_number);
return;
}
UiUtils.setInputError(mInputHouseNumber, 0);
UiUtils.setInputError(mInputHouseNumber, Editor.nativeIsHouseValid(s.toString()) ? 0 : R.string.error_enter_correct_house_number);
}
});
mZipcode.setText(Editor.nativeGetZipCode());
mBuildingLevels.setText(Editor.nativeGetBuildingLevels());
mBuildingLevels.addTextChangedListener(new StringUtils.SimpleTextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
UiUtils.setInputError(mInputBuildingLevels, Editor.nativeIsLevelValid(s.toString()) ? 0 : R.string.error_enter_correct_storey_number);
}
});
mPhone.setText(Editor.nativeGetPhone());
mWebsite.setText(Editor.nativeGetWebsite());
mEmail.setText(Editor.nativeGetEmail());
@ -157,7 +161,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
setEdits();
}
protected boolean setEdits()
boolean setEdits()
{
if (!validateFields())
return false;
@ -191,6 +195,13 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return false;
}
if (!Editor.nativeIsLevelValid(mBuildingLevels.getText().toString()))
{
mBuildingLevels.requestFocus();
InputUtils.showKeyboard(mBuildingLevels);
return false;
}
return true;
}
@ -271,6 +282,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
View blockZipcode = view.findViewById(R.id.block_zipcode);
mZipcode = findInputAndInitBlock(blockZipcode, 0, R.string.editor_zip_code);
mBlockLevels = view.findViewById(R.id.block_levels);
mInputBuildingLevels = (TextInputLayout) mBlockLevels.findViewById(R.id.custom_input);
// TODO set level limits from core
mBuildingLevels = findInputAndInitBlock(mBlockLevels, 0, getString(R.string.editor_storey_number, 25));
// Details
@ -310,7 +322,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mMetaBlocks.append(MetadataType.FMD_INTERNET.toInt(), blockWifi);
}
private EditText findInput(View blockWithInput)
private static EditText findInput(View blockWithInput)
{
return (EditText) blockWithInput.findViewById(R.id.input);
}
@ -320,7 +332,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return findInputAndInitBlock(blockWithInput, icon, getString(hint));
}
private EditText findInputAndInitBlock(View blockWithInput, @DrawableRes int icon, String hint)
private static EditText findInputAndInitBlock(View blockWithInput, @DrawableRes int icon, String hint)
{
((ImageView) blockWithInput.findViewById(R.id.icon)).setImageResource(icon);
final TextInputLayout input = (TextInputLayout) blockWithInput.findViewById(R.id.custom_input);

View file

@ -1378,7 +1378,7 @@
"editor_storey_number" = "Building levels (max %d)";
"error_enter_correct_storey_number" = "Buildigns at highest of 25 levels can be edited";
"error_enter_correct_storey_number" = "Buildings at highest of 25 levels can be edited";
"editor_zip_code" = "ZIP Code";

View file

@ -16275,7 +16275,7 @@
[error_enter_correct_storey_number]
tags = ios, android
en = Buildigns at highest of 25 levels can be edited
en = Buildings at highest of 25 levels can be edited
ru = Редактируйте здания высотой максимум 25 этажей
fr = Modifier l'immeuble avec un maximum de 25 étages
da = Rediger bygningen med maksimum 25 etager