[android] Add custom street.

This commit is contained in:
Dmitry Yunitsky 2016-02-29 18:56:23 +03:00 committed by Sergey Yershov
parent a69580627a
commit bf045499fa
6 changed files with 143 additions and 42 deletions

View file

@ -1,28 +1,30 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/margin_base_plus">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:minWidth="300dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/margin_base_plus">
<TextView
android:id="@+id/tv__title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Title"/>
android:id="@+id/tv__title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Title"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et__input"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:singleLine="true"/>
android:id="@+id/et__input"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:singleLine="true"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</LinearLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_oneline"
android:background="?clickableBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/margin_base">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="@dimen/margin_double"
android:layout_marginRight="@dimen/margin_double"
android:scaleType="centerCrop"
android:src="@drawable/ic_plus"
android:tint="?colorAccent"/>
<TextView
android:id="@+id/street"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="@string/add_street"
android:textAppearance="@style/MwmTextAppearance.Body1"
android:textColor="?colorAccent"/>
</LinearLayout>

View file

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:gravity="center_vertical|right"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:text="@string/add_new_set"
android:textAppearance="@style/MwmTextAppearance.Button"
android:fontFamily="@string/robotoLight"/>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:fontFamily="@string/robotoLight"
android:gravity="center_vertical"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:text="@string/add_new_set"
android:textAppearance="@style/MwmTextAppearance.Button"
tools:targetApi="jelly_bean"/>

View file

@ -153,9 +153,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
editMapObject();
break;
case STREET:
final String street = ((StreetFragment) getChildFragmentManager().findFragmentByTag(StreetFragment.class.getName())).getStreet();
Editor.nativeSetStreet(street);
editMapObject();
setStreet(((StreetFragment) getChildFragmentManager().findFragmentByTag(StreetFragment.class.getName())).getStreet());
break;
case CUISINE:
String cuisine = ((CuisineFragment) getChildFragmentManager().findFragmentByTag(CuisineFragment.class.getName())).getCuisine();
@ -188,6 +186,12 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
}
}
public void setStreet(String street)
{
mEditedObject.setStreet(street);
editMapObject();
}
private void showAuthorization()
{
if (!MwmApplication.prefs().contains(PREF_LAST_AUTH_DISPLAY_TIMESTAMP))

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps.editor;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -8,28 +9,36 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.dialog.EditTextDialogFragment;
import com.mapswithme.util.UiUtils;
public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.ViewHolder>
public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.BaseViewHolder>
{
private static final int TYPE_ADD_STREET = 0;
private static final int TYPE_STREET = 1;
private final String[] mStreets;
private final StreetFragment mFragment;
private String mSelectedStreet;
public StreetAdapter(@NonNull String[] streets, @NonNull String selected)
public StreetAdapter(@NonNull StreetFragment host, @NonNull String[] streets, @NonNull String selected)
{
mFragment = host;
mStreets = streets;
mSelectedStreet = selected;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_street, parent, false));
return viewType == TYPE_STREET ? new StreetViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_street, parent, false))
: new AddViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_add_street, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position)
public void onBindViewHolder(BaseViewHolder holder, int position)
{
holder.bind(position);
}
@ -37,7 +46,13 @@ public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.ViewHolder
@Override
public int getItemCount()
{
return mStreets.length;
return mStreets.length + 1;
}
@Override
public int getItemViewType(int position)
{
return position == getItemCount() - 1 ? TYPE_ADD_STREET : TYPE_STREET;
}
public String getSelectedStreet()
@ -45,12 +60,30 @@ public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.ViewHolder
return mSelectedStreet;
}
protected class ViewHolder extends RecyclerView.ViewHolder
private void addStreet()
{
final Resources resources = MwmApplication.get().getResources();
EditTextDialogFragment.show(resources.getString(R.string.street), null,
resources.getString(R.string.ok),
resources.getString(R.string.cancel), mFragment);
}
protected abstract class BaseViewHolder extends RecyclerView.ViewHolder
{
public BaseViewHolder(View itemView)
{
super(itemView);
}
public void bind(int position) {}
}
protected class StreetViewHolder extends BaseViewHolder
{
final TextView street;
final ImageView selected;
public ViewHolder(View itemView)
public StreetViewHolder(View itemView)
{
super(itemView);
street = (TextView) itemView.findViewById(R.id.street);
@ -66,6 +99,7 @@ public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.ViewHolder
});
}
@Override
public void bind(int position)
{
final String text = mStreets[position];
@ -73,4 +107,20 @@ public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.ViewHolder
street.setText(text);
}
}
protected class AddViewHolder extends BaseViewHolder
{
public AddViewHolder(View itemView)
{
super(itemView);
itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
addStreet();
}
});
}
}
}

View file

@ -8,8 +8,9 @@ import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
import com.mapswithme.maps.dialog.EditTextDialogFragment;
public class StreetFragment extends BaseMwmRecyclerFragment
public class StreetFragment extends BaseMwmRecyclerFragment implements EditTextDialogFragment.OnTextSaveListener
{
public static final String EXTRA_CURRENT_STREET = "Street";
@ -25,7 +26,7 @@ public class StreetFragment extends BaseMwmRecyclerFragment
@Override
protected RecyclerView.Adapter createAdapter()
{
return new StreetAdapter(Editor.nativeGetNearbyStreets(), mSelectedString);
return new StreetAdapter(this, Editor.nativeGetNearbyStreets(), mSelectedString);
}
@NonNull
@ -33,4 +34,16 @@ public class StreetFragment extends BaseMwmRecyclerFragment
{
return ((StreetAdapter) getAdapter()).getSelectedStreet();
}
@Override
public void onSaveText(String text)
{
saveStreet(text);
}
protected void saveStreet(String street)
{
if (getParentFragment() instanceof EditorHostFragment)
((EditorHostFragment) getParentFragment()).setStreet(street);
}
}