[android] Added new editable fields to UI (zipcode, building levels, operator).

This commit is contained in:
Dmitry Yunitsky 2016-04-20 17:34:04 +03:00
parent d24ec76a41
commit 26977aa832
5 changed files with 227 additions and 237 deletions

View file

@ -29,11 +29,13 @@
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/margin_half_plus"
android:layout_marginLeft="@dimen/margin_quarter"
android:layout_marginRight="@dimen/margin_half_plus"
android:layout_marginStart="@dimen/margin_quarter"
tools:src="@drawable/ic_category_atm"/>
android:tint="?iconTint"
tools:src="@drawable/ic_operator"/>
<Space
android:id="@+id/anchor_center"
@ -50,8 +52,8 @@
android:layout_marginStart="@dimen/margin_quarter"
android:layout_toEndOf="@id/icon"
android:layout_toRightOf="@id/icon"
android:textAppearance="@style/MwmTextAppearance.Body4"
android:text="@string/editor_edit_place_category_title"/>
android:text="@string/editor_edit_place_category_title"
android:textAppearance="@style/MwmTextAppearance.Body4"/>
<TextView
android:id="@+id/name"
@ -84,7 +86,7 @@
android:paddingRight="@dimen/margin_base"
android:paddingStart="@dimen/margin_base">
<com.mapswithme.maps.widget.CustomTextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -94,7 +96,7 @@
android:hint="@string/editor_edit_place_name_hint"
android:singleLine="true"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/name_multilang"
@ -141,7 +143,7 @@
<ImageView
style="@style/MwmWidget.Editor.MetadataIcon"
android:src="@drawable/ic_coordinates"/>
android:src="@drawable/ic_address"/>
<TextView
android:id="@+id/street_title"
@ -173,29 +175,18 @@
android:background="?dividerHorizontal"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/building"
style="@style/MwmWidget.Editor.MetadataBlock">
<com.mapswithme.maps.widget.CustomTextInputLayout
android:id="@+id/custom_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/house_number"
tools:text="79-59"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</RelativeLayout>
<include
android:id="@+id/block_building"
layout="@layout/item_editor_input"/>
<include
android:id="@+id/block_zipcode"
layout="@layout/item_editor_input"/>
<include
android:id="@+id/block_levels"
layout="@layout/item_editor_input"/>
</LinearLayout>
@ -226,73 +217,22 @@
<include
android:id="@+id/block_opening_hours"
layout="@layout/item_opening_hours"/>
<RelativeLayout
<include
android:id="@+id/block_phone"
style="@style/MwmWidget.Editor.MetadataBlock">
<ImageView
style="@style/MwmWidget.Editor.MetadataIcon"
android:src="@drawable/ic_phone"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
style="@style/MwmWidget.Editor.FieldLayout"
android:layout_centerVertical="true">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/phone"
android:inputType="phone"
tools:text="+937 99 92"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</RelativeLayout>
<RelativeLayout
layout="@layout/item_editor_input"/>
<include
android:id="@+id/block_website"
style="@style/MwmWidget.Editor.MetadataBlock">
<ImageView
style="@style/MwmWidget.Editor.MetadataIcon"
android:src="@drawable/ic_website"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
style="@style/MwmWidget.Editor.FieldLayout"
android:layout_centerVertical="true">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/website"
tools:text="maps.me"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</RelativeLayout>
<RelativeLayout
layout="@layout/item_editor_input"/>
<include
android:id="@+id/block_email"
style="@style/MwmWidget.Editor.MetadataBlock">
<ImageView
style="@style/MwmWidget.Editor.MetadataIcon"
android:src="@drawable/ic_email"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
style="@style/MwmWidget.Editor.FieldLayout"
android:layout_centerVertical="true">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/email"
tools:text="bugs@maps.me"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</RelativeLayout>
layout="@layout/item_editor_input"/>
<include
android:id="@+id/block_operator"
layout="@layout/item_editor_input"/>
<RelativeLayout
android:id="@+id/block_cuisine"
@ -366,6 +306,56 @@
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cv__more"
style="@style/MwmWidget.Editor.CardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/margin_base">
<TextView
android:layout_width="match_parent"
android:layout_height="32dp"
android:text="@string/editor_other_info"
android:textAppearance="@style/MwmTextAppearance.Body2"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
android:id="@+id/custom_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="74dp">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/editor_detailed_description_hint"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half"
android:text="@string/editor_detailed_description"
android:textAppearance="@style/MwmTextAppearance.Body4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half"
android:text="@string/editor_more_about_osm"
android:textAppearance="@style/MwmTextAppearance.Body4"
android:textColor="?colorAccent"
android:textSize="@dimen/text_size_body_4"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/MwmWidget.Editor.MetadataBlock">
<ImageView
android:id="@+id/icon"
style="@style/MwmWidget.Editor.MetadataIcon"
tools:src="@drawable/ic_phone"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/custom_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
tools:hint="Hint"
tools:text="Input"/>
</android.support.design.widget.TextInputLayout>
</RelativeLayout>

View file

@ -12,7 +12,7 @@
<style name="MwmWidget.Editor.CardView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">@dimen/margin_base</item>
<item name="android:layout_marginBottom">@dimen/margin_half</item>
<item name="cardBackgroundColor">?cardBackground</item>
<item name="android:padding">@dimen/margin_base</item>
<item name="cardPreventCornerOverlap">false</item>

View file

@ -1,20 +1,24 @@
package com.mapswithme.maps.editor;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.SwitchCompat;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.maps.bookmarks.data.Metadata;
import com.mapswithme.maps.bookmarks.data.Metadata.MetadataType;
import com.mapswithme.maps.editor.data.TimeFormatUtils;
import com.mapswithme.maps.editor.data.Timetable;
import com.mapswithme.maps.widget.CustomTextInputLayout;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
@ -22,28 +26,27 @@ import com.mapswithme.util.UiUtils;
public class EditorFragment extends BaseMwmFragment implements View.OnClickListener
{
private TextView mCategory;
private View mNameBlock;
private View mAddressBlock;
private View mMetadataBlock;
private EditText mEtName;
private TextView mTvLocalizedNames;
private TextView mTvStreet;
private EditText mEtHouseNumber;
private CustomTextInputLayout mInputHouseNumber;
private View mPhoneBlock;
private EditText mEtPhone;
private View mWebBlock;
private EditText mEtWebsite;
private View mEmailBlock;
private EditText mEtEmail;
private View mCuisineBlock;
private TextView mTvCuisine;
private View mWifiBlock;
private SwitchCompat mSwWifi;
private View mOpeningHoursBlock;
private View mCardName;
private View mCardAddress;
private View mCardMetadata;
private EditText mName;
private TextView mLocalizedNames;
private TextView mStreet;
private EditText mHouseNumber;
private EditText mZipcode;
private EditText mLevels;
private TextInputLayout mInputHouseNumber;
private EditText mPhone;
private EditText mWebsite;
private EditText mEmail;
private TextView mCuisine;
private EditText mOperator;
private SwitchCompat mWifi;
private View mEmptyOpeningHours;
private TextView mOpeningHours;
private View mEditOpeningHours;
private EditText mDescription;
private final SparseArray<View> mMetaBlocks = new SparseArray<>(7);
protected EditorHostFragment mParent;
@ -65,11 +68,11 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mCategory.setText(Editor.nativeGetCategory());
// TODO(yunikkk): Add multilanguages support.
UiUtils.hide(mTvLocalizedNames);
mEtName.setText(Editor.nativeGetDefaultName());
mTvStreet.setText(Editor.nativeGetStreet());
mEtHouseNumber.setText(Editor.nativeGetHouseNumber());
mEtHouseNumber.addTextChangedListener(new StringUtils.SimpleTextWatcher()
UiUtils.hide(mLocalizedNames);
mName.setText(Editor.nativeGetDefaultName());
mStreet.setText(Editor.nativeGetStreet());
mHouseNumber.setText(Editor.nativeGetHouseNumber());
mHouseNumber.addTextChangedListener(new StringUtils.SimpleTextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
@ -85,13 +88,15 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mInputHouseNumber.setError(null);
}
});
mEtPhone.setText(Editor.nativeGetPhone());
mEtWebsite.setText(Editor.nativeGetWebsite());
mEtEmail.setText(Editor.nativeGetEmail());
mTvCuisine.setText(Editor.nativeGetFormattedCuisine());
mSwWifi.setChecked(Editor.nativeHasWifi());
mZipcode.setText(Editor.nativeGetZipCode());
mLevels.setText(Editor.nativeGetBuildingLevels());
mPhone.setText(Editor.nativeGetPhone());
mWebsite.setText(Editor.nativeGetWebsite());
mEmail.setText(Editor.nativeGetEmail());
mCuisine.setText(Editor.nativeGetFormattedCuisine());
mOperator.setText(Editor.nativeGetOperator());
mWifi.setChecked(Editor.nativeHasWifi());
refreshOpeningTime();
refreshEditableFields();
}
@ -107,116 +112,56 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
if (!validateFields())
return false;
Editor.nativeSetPhone(getPhone());
Editor.nativeSetWebsite(getWebsite());
Editor.nativeSetEmail(getEmail());
Editor.nativeSetHasWifi(hasWifi());
Editor.nativeSetDefaultName(getName());
Editor.nativeSetHouseNumber(getHouseNumber());
Editor.nativeSetDefaultName(mName.getText().toString());
Editor.nativeSetHouseNumber(mHouseNumber.getText().toString());
Editor.nativeSetZipCode(mZipcode.getText().toString());
Editor.nativeSetBuildingLevels(mLevels.getText().toString());
Editor.nativeSetPhone(mPhone.getText().toString());
Editor.nativeSetWebsite(mWebsite.getText().toString());
Editor.nativeSetEmail(mEmail.getText().toString());
Editor.nativeSetHasWifi(mWifi.isChecked());
return true;
}
private boolean validateFields()
{
if (!Editor.nativeIsHouseValid(getHouseNumber()))
if (!Editor.nativeIsHouseValid(mHouseNumber.getText().toString()))
{
mEtHouseNumber.requestFocus();
InputUtils.showKeyboard(mEtHouseNumber);
mHouseNumber.requestFocus();
InputUtils.showKeyboard(mHouseNumber);
return false;
}
return true;
}
public String getName()
{
// TODO add localized names
return mEtName.getText().toString();
}
public String getStreet()
{
return mTvStreet.getText().toString();
}
public String getHouseNumber()
{
return mEtHouseNumber.getText().toString();
}
public String getPhone()
{
return mEtPhone.getText().toString();
}
public String getWebsite()
{
return mEtWebsite.getText().toString();
}
public String getEmail()
{
return mEtEmail.getText().toString();
}
public String getCuisine()
{
return mTvCuisine.getText().toString();
}
public boolean hasWifi()
{
return mSwWifi.isChecked();
}
private void refreshEditableFields()
{
UiUtils.showIf(Editor.nativeIsNameEditable(), mNameBlock);
UiUtils.showIf(Editor.nativeIsAddressEditable(), mAddressBlock);
UiUtils.showIf(Editor.nativeIsNameEditable(), mCardName);
UiUtils.showIf(Editor.nativeIsAddressEditable(), mCardAddress);
final int[] editableMeta = Editor.nativeGetEditableFields();
if (editableMeta.length == 0)
{
UiUtils.hide(mMetadataBlock);
UiUtils.hide(mCardMetadata);
return;
}
UiUtils.show(mMetadataBlock);
UiUtils.hide(mOpeningHoursBlock, mPhoneBlock, mWebBlock, mEmailBlock, mCuisineBlock, mWifiBlock);
for (int i = 0; i < mMetaBlocks.size(); i++)
UiUtils.hide(mMetaBlocks.valueAt(i));
boolean anyEditableMeta = false;
for (int type : editableMeta)
{
switch (Metadata.MetadataType.fromInt(type))
{
case FMD_OPEN_HOURS:
anyEditableMeta = true;
UiUtils.show(mOpeningHoursBlock);
break;
case FMD_PHONE_NUMBER:
anyEditableMeta = true;
UiUtils.show(mPhoneBlock);
break;
case FMD_WEBSITE:
anyEditableMeta = true;
UiUtils.show(mWebBlock);
break;
case FMD_EMAIL:
anyEditableMeta = true;
UiUtils.show(mEmailBlock);
break;
case FMD_CUISINE:
anyEditableMeta = true;
UiUtils.show(mCuisineBlock);
break;
case FMD_INTERNET:
anyEditableMeta = true;
UiUtils.show(mWifiBlock);
break;
}
final View metaBlock = mMetaBlocks.get(type);
if (metaBlock == null)
continue;
anyEditableMeta = true;
UiUtils.show(metaBlock);
}
if (!anyEditableMeta)
UiUtils.hide(mMetadataBlock);
UiUtils.showIf(anyEditableMeta, mCardMetadata);
}
private void refreshOpeningTime()
@ -242,34 +187,53 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
// TODO show icon and fill it when core will implement that
UiUtils.hide(categoryBlock.findViewById(R.id.icon));
mCategory = (TextView) categoryBlock.findViewById(R.id.name);
mNameBlock = view.findViewById(R.id.cv__name);
mAddressBlock = view.findViewById(R.id.cv__address);
mMetadataBlock = view.findViewById(R.id.cv__metadata);
mEtName = findInput(mNameBlock);
mTvLocalizedNames = (TextView) view.findViewById(R.id.name_multilang);
mCardName = view.findViewById(R.id.cv__name);
mCardAddress = view.findViewById(R.id.cv__address);
mCardMetadata = view.findViewById(R.id.cv__metadata);
mName = findInput(mCardName);
mLocalizedNames = (TextView) view.findViewById(R.id.name_multilang);
// Address
view.findViewById(R.id.block_street).setOnClickListener(this);
mTvStreet = (TextView) view.findViewById(R.id.street);
mEtHouseNumber = findInput(view.findViewById(R.id.building));
mInputHouseNumber = (CustomTextInputLayout) view.findViewById(R.id.building).findViewById(R.id.custom_input);
mPhoneBlock = view.findViewById(R.id.block_phone);
mEtPhone = findInput(mPhoneBlock);
mWebBlock = view.findViewById(R.id.block_website);
mEtWebsite = findInput(mWebBlock);
mEmailBlock = view.findViewById(R.id.block_email);
mEtEmail = findInput(mEmailBlock);
mCuisineBlock = view.findViewById(R.id.block_cuisine);
mCuisineBlock.setOnClickListener(this);
mTvCuisine = (TextView) view.findViewById(R.id.cuisine);
mWifiBlock = view.findViewById(R.id.block_wifi);
mSwWifi = (SwitchCompat) view.findViewById(R.id.sw__wifi);
mWifiBlock.setOnClickListener(this);
mOpeningHoursBlock = view.findViewById(R.id.block_opening_hours);
mEditOpeningHours = mOpeningHoursBlock.findViewById(R.id.edit_opening_hours);
mStreet = (TextView) view.findViewById(R.id.street);
View blockHouseNumber = view.findViewById(R.id.block_building);
mHouseNumber = findInputAndInitBlock(blockHouseNumber, 0, R.string.house_number);
mInputHouseNumber = (TextInputLayout) blockHouseNumber.findViewById(R.id.custom_input);
View blockZipcode = view.findViewById(R.id.block_zipcode);
mZipcode = findInputAndInitBlock(blockZipcode, 0, R.string.editor_zip_code);
View blockLevels = view.findViewById(R.id.block_levels);
// TODO set levels limit (25 or more, get it from the core)
mLevels = findInputAndInitBlock(blockLevels, 0, R.string.editor_storey_number);
// Details
View blockPhone = view.findViewById(R.id.block_phone);
mPhone = findInputAndInitBlock(blockPhone, R.drawable.ic_phone, R.string.phone);
View blockWeb = view.findViewById(R.id.block_website);
mWebsite = findInputAndInitBlock(blockWeb, R.drawable.ic_website, R.string.website);
View blockEmail = view.findViewById(R.id.block_email);
mEmail = findInputAndInitBlock(blockEmail, R.drawable.ic_email, R.string.email);
View blockCuisine = view.findViewById(R.id.block_cuisine);
blockCuisine.setOnClickListener(this);
mCuisine = (TextView) view.findViewById(R.id.cuisine);
View blockOperator = view.findViewById(R.id.block_operator);
mOperator = findInputAndInitBlock(blockOperator, R.drawable.ic_operator, R.string.editor_operator);
View blockWifi = view.findViewById(R.id.block_wifi);
mWifi = (SwitchCompat) view.findViewById(R.id.sw__wifi);
blockWifi.setOnClickListener(this);
View blockOpeningHours = view.findViewById(R.id.block_opening_hours);
mEditOpeningHours = blockOpeningHours.findViewById(R.id.edit_opening_hours);
mEditOpeningHours.setOnClickListener(this);
mEmptyOpeningHours = mOpeningHoursBlock.findViewById(R.id.empty_opening_hours);
mEmptyOpeningHours = blockOpeningHours.findViewById(R.id.empty_opening_hours);
mEmptyOpeningHours.setOnClickListener(this);
mOpeningHours = (TextView) mOpeningHoursBlock.findViewById(R.id.opening_hours);
mOpeningHours = (TextView) blockOpeningHours.findViewById(R.id.opening_hours);
mOpeningHours.setOnClickListener(this);
mDescription = findInput(view.findViewById(R.id.cv__more));
mMetaBlocks.append(MetadataType.FMD_OPEN_HOURS.toInt(), blockOpeningHours);
mMetaBlocks.append(MetadataType.FMD_PHONE_NUMBER.toInt(), blockPhone);
mMetaBlocks.append(MetadataType.FMD_WEBSITE.toInt(), blockWeb);
mMetaBlocks.append(MetadataType.FMD_EMAIL.toInt(), blockEmail);
mMetaBlocks.append(MetadataType.FMD_CUISINE.toInt(), blockCuisine);
mMetaBlocks.append(MetadataType.FMD_OPERATOR.toInt(), blockOperator);
mMetaBlocks.append(MetadataType.FMD_INTERNET.toInt(), blockWifi);
}
private EditText findInput(View view)
@ -277,6 +241,14 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return (EditText) view.findViewById(R.id.input);
}
private EditText findInputAndInitBlock(View block, @DrawableRes int icon, @StringRes int hint)
{
((ImageView) block.findViewById(R.id.icon)).setImageResource(icon);
final TextInputLayout input = (TextInputLayout) block.findViewById(R.id.custom_input);
input.setHint(getString(hint));
return (EditText) input.findViewById(R.id.input);
}
@Override
public void onClick(View v)
{
@ -288,7 +260,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mParent.editTimetable();
break;
case R.id.block_wifi:
mSwWifi.toggle();
mWifi.toggle();
break;
case R.id.block_street:
mParent.editStreet();

View file

@ -47,7 +47,7 @@ public class CustomTextInputLayout extends TextInputLayout
// We have to reset the previous hint so that equals check pass
setHint(null);
// In case that hint is changed programatically
// In case that hint is changed programmatically
CharSequence currentEditTextHint = getEditText().getHint();
if (currentEditTextHint != null && currentEditTextHint.length() > 0)
mHint = currentEditTextHint;
@ -55,5 +55,4 @@ public class CustomTextInputLayout extends TextInputLayout
mIsHintSet = true;
}
}
}