[android] Add localized language for name.

This commit is contained in:
Dmitry Yunitsky 2016-04-27 15:08:39 +03:00 committed by Alex Zolotarev
parent e9a0c9e53c
commit 4396417146
12 changed files with 334 additions and 69 deletions

View file

@ -311,6 +311,18 @@ Java_com_mapswithme_maps_editor_Editor_nativeSetLocalizedStreet(JNIEnv * env, jc
g_editableMapObject.SetStreet({jni::ToNativeString(env, street), jni::ToNativeString(env, localizedStreet)});
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetSupportedLanguages(JNIEnv * env, jclass clazz)
{
// TODO (yunikkk) implement
//public Language(@NonNull String code, @NonNull String name)
// static jclass const langClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/editor/data/Language");
// static jmethodID const langCtor = jni::GetConstructorID(env, langClass, "(Ljava/lang/String;Ljava/lang/String;)V");
// return jni::ToJavaArray(env, langClass, g_editableMapObject.GetBuildingLevels(), );
return nullptr;
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetHouseNumber(JNIEnv * env, jclass)
{

View file

@ -74,7 +74,7 @@
android:id="@+id/cv__name"
style="@style/MwmWidget.Editor.CardView">
<include layout="@layout/item_localized_name"/>
<include layout="@layout/localized_name"/>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_oneline"
android:layout_weight="1"
android:background="?clickableBackground"
android:padding="@dimen/margin_base"
android:singleLine="true"
android:textAppearance="@style/MwmTextAppearance.Body1"/>

View file

@ -1,23 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base"
android:layout_height="@dimen/editor_height_field"
android:animateLayoutChanges="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingEnd="@dimen/margin_base"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:paddingStart="@dimen/margin_base">
android:gravity="center_vertical"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.mapswithme.maps.widget.CustomTextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/input"
@ -25,32 +21,15 @@
android:hint="@string/editor_edit_place_name_hint"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
</com.mapswithme.maps.widget.CustomTextInputLayout>
<TextView
android:id="@+id/show_langs"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:fontFamily="@string/robotoMedium"
android:gravity="center_vertical"
android:text="@string/other_languages"
android:textAppearance="@style/MwmTextAppearance.Body3"
tools:drawableRight="@drawable/ic_expand_more"
tools:ignore="UnusedAttribute"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/names"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/add_langs"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:gravity="center_vertical"
android:text="@string/add_language"
android:textAppearance="@style/MwmTextAppearance.Button"/>
<ImageButton
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/margin_half"
android:src="@drawable/ic_close"
android:tint="@color/base_red"/>
</LinearLayout>

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO set attr android:animateLayoutChanges="true"
when recyclerview-v7:23.2.1+ will be used.
RecyclerView of earlier versions doesn't have scrollTo method and hence crashes.-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingEnd="@dimen/margin_base"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:paddingStart="@dimen/margin_base">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/input"
style="@style/MwmWidget.Editor.FieldLayout.EditText"
android:hint="@string/editor_edit_place_name_hint"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/show_langs"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:fontFamily="@string/robotoMedium"
android:gravity="center_vertical"
android:text="@string/other_languages"
android:textAppearance="@style/MwmTextAppearance.Body3"
tools:drawableRight="@drawable/ic_expand_more"
tools:ignore="UnusedAttribute"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/names"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/add_langs"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:background="?clickableBackground"
android:gravity="center_vertical"
android:text="@string/add_language"
android:textAppearance="@style/MwmTextAppearance.Button"/>
</LinearLayout>

View file

@ -10,6 +10,7 @@ import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.background.AppBackgroundTracker;
import com.mapswithme.maps.background.WorkerService;
import com.mapswithme.maps.editor.data.FeatureCategory;
import com.mapswithme.maps.editor.data.Language;
import com.mapswithme.maps.editor.data.LocalizedName;
@ -86,6 +87,7 @@ public final class Editor
public static native void nativeSetDefaultName(String name);
public static native @NonNull LocalizedName[] nativeGetLocalizedNames();
public static native void nativeSetLocalizedNames(@NonNull LocalizedName[] names);
public static native Language[] nativeGetSupportedLanguages();
public static native String nativeGetStreet();
public static native String nativeGetLocalizedStreet();

View file

@ -21,6 +21,7 @@ import com.mapswithme.maps.base.BaseMwmFragment;
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.util.Graphics;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
@ -33,9 +34,44 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private View mCardAddress;
private View mCardMetadata;
private EditText mName;
private RecyclerView mLocalizedNames;
private View mLocalizedAdd;
private View mLocalizedShow;
private RecyclerView.AdapterDataObserver mLocalizedNamesObserver = new RecyclerView.AdapterDataObserver()
{
@Override
public void onChanged()
{
refreshLocalizedNames();
}
@Override
public void onItemRangeChanged(int positionStart, int itemCount)
{
refreshLocalizedNames();
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount)
{
refreshLocalizedNames();
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount)
{
refreshLocalizedNames();
}
@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount)
{
refreshLocalizedNames();
}
};
private MultilanguageAdapter mLocalizedNamesAdapter;
private TextView mLocalizedShow;
private boolean mIsLocalizedShown;
private TextView mStreet;
private EditText mHouseNumber;
private EditText mZipcode;
@ -124,6 +160,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
Editor.nativeSetWebsite(mWebsite.getText().toString());
Editor.nativeSetEmail(mEmail.getText().toString());
Editor.nativeSetHasWifi(mWifi.isChecked());
// TODO set localizated names
return true;
}
@ -202,11 +239,18 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mCardAddress = view.findViewById(R.id.cv__address);
mCardMetadata = view.findViewById(R.id.cv__metadata);
mName = findInput(mCardName);
mLocalizedAdd = view.findViewById(R.id.add_langs);
mLocalizedShow = view.findViewById(R.id.show_langs);
// TODO uncomment and finish localized name
// view.findViewById(R.id.add_langs).setOnClickListener(this);
UiUtils.hide(view.findViewById(R.id.add_langs));
mLocalizedShow = (TextView) view.findViewById(R.id.show_langs);
mLocalizedShow.setOnClickListener(this);
mLocalizedNames = (RecyclerView) view.findViewById(R.id.names);
mLocalizedNames.setLayoutManager(new LinearLayoutManager(getActivity()));
mLocalizedNames.setAdapter(new MultilanguageAdapter(Editor.nativeGetLocalizedNames()));
mLocalizedNamesAdapter = new MultilanguageAdapter(Editor.nativeGetLocalizedNames());
mLocalizedNames.setAdapter(mLocalizedNamesAdapter);
mLocalizedNamesAdapter.registerAdapterDataObserver(mLocalizedNamesObserver);
refreshLocalizedNames();
showLocalizedNames(false);
// Address
view.findViewById(R.id.block_street).setOnClickListener(this);
mStreet = (TextView) view.findViewById(R.id.street);
@ -285,6 +329,40 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
break;
case R.id.category:
mParent.editCategory();
break;
case R.id.show_langs:
showLocalizedNames(!mIsLocalizedShown);
break;
case R.id.add_langs:
mParent.addLocalizedLanguage();
break;
}
}
private void refreshLocalizedNames()
{
// TODO uncomment and finish localized names
// UiUtils.showIf(mLocalizedNamesAdapter.getItemCount() > 0, mLocalizedShow);
UiUtils.hide(mLocalizedNames, mLocalizedShow);
}
private void showLocalizedNames(boolean show)
{
mIsLocalizedShown = show;
if (show)
{
UiUtils.show(mLocalizedNames);
setLocalizedShowDrawable(R.drawable.ic_expand_less);
}
else
{
UiUtils.hide(mLocalizedNames);
setLocalizedShowDrawable(R.drawable.ic_expand_more);
}
}
private void setLocalizedShowDrawable(@DrawableRes int right)
{
mLocalizedShow.setCompoundDrawablesWithIntrinsicBounds(null, null, Graphics.tint(getActivity(), right, R.attr.iconTint), null);
}
}

View file

@ -33,7 +33,8 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
MAP_OBJECT,
OPENING_HOURS,
STREET,
CUISINE
CUISINE,
LANGUAGE
}
private Mode mMode;
@ -114,43 +115,37 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
protected void editTimetable()
{
if (!setEdits())
return;
mMode = Mode.OPENING_HOURS;
mToolbarController.setTitle(R.string.editor_time_title);
final Bundle args = new Bundle();
args.putString(TimetableFragment.EXTRA_TIME, Editor.nativeGetOpeningHours());
final Fragment editorFragment = Fragment.instantiate(getActivity(), TimetableFragment.class.getName(), args);
getChildFragmentManager().beginTransaction()
.replace(R.id.fragment_container, editorFragment, TimetableFragment.class.getName())
.commit();
editWithFragment(Mode.OPENING_HOURS, R.string.editor_time_title, args, TimetableFragment.class, false);
}
protected void editStreet()
{
if (!setEdits())
return;
mMode = Mode.STREET;
mToolbarController.setTitle(R.string.choose_street);
final Fragment streetFragment = Fragment.instantiate(getActivity(), StreetFragment.class.getName());
getChildFragmentManager().beginTransaction()
.replace(R.id.fragment_container, streetFragment, StreetFragment.class.getName())
.commit();
editWithFragment(Mode.STREET, R.string.choose_street, null, StreetFragment.class, false);
}
protected void editCuisine()
{
editWithFragment(Mode.CUISINE, 0, null, CuisineFragment.class, true);
}
protected void addLocalizedLanguage()
{
editWithFragment(Mode.LANGUAGE, 0, null, LanguagesFragment.class, false);
}
private void editWithFragment(Mode newMode, @StringRes int toolbarTitle, @Nullable Bundle args, Class<? extends Fragment> fragmentClass, boolean showSearch)
{
if (!setEdits())
return;
mMode = Mode.CUISINE;
mToolbarController.setTitle("");
((SearchToolbarController) mToolbarController).showControls(true);
final Fragment cuisineFragment = Fragment.instantiate(getActivity(), CuisineFragment.class.getName());
mMode = newMode;
mToolbarController.setTitle(toolbarTitle);
((SearchToolbarController) mToolbarController).showControls(showSearch);
final Fragment fragment = Fragment.instantiate(getActivity(), fragmentClass.getName(), args);
getChildFragmentManager().beginTransaction()
.replace(R.id.fragment_container, cuisineFragment, CuisineFragment.class.getName())
.replace(R.id.fragment_container, fragment, fragmentClass.getName())
.commit();
}

View file

@ -0,0 +1,65 @@
package com.mapswithme.maps.editor;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.editor.data.Language;
public class LanguagesAdapter extends RecyclerView.Adapter<LanguagesAdapter.Holder>
{
private final Language[] mLanguages;
private final LanguagesFragment mFragment;
public LanguagesAdapter(@NonNull LanguagesFragment host, @NonNull Language[] languages)
{
mFragment = host;
mLanguages = languages;
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType)
{
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_language, parent, false));
}
@Override
public void onBindViewHolder(Holder holder, int position)
{
holder.bind(position);
}
@Override
public int getItemCount()
{
return mLanguages.length;
}
protected class Holder extends RecyclerView.ViewHolder
{
TextView name;
public Holder(View itemView)
{
super(itemView);
name = (TextView) itemView;
itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mFragment.onLanguageSelected(mLanguages[getAdapterPosition()]);
}
});
}
public void bind(int position)
{
name.setText(mLanguages[position].name);
}
}
}

View file

@ -0,0 +1,28 @@
package com.mapswithme.maps.editor;
import android.support.v7.widget.RecyclerView;
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
import com.mapswithme.maps.editor.data.Language;
public class LanguagesFragment extends BaseMwmRecyclerFragment
{
public interface Listener
{
void onLanguageSelected(Language language);
}
@Override
protected RecyclerView.Adapter createAdapter()
{
return new LanguagesAdapter(this, Editor.nativeGetSupportedLanguages());
}
protected void onLanguageSelected(Language language)
{
if (getActivity() instanceof Listener)
((Listener) getActivity()).onLanguageSelected(language);
else if (getParentFragment() instanceof Listener)
((Listener) getParentFragment()).onLanguageSelected(language);
}
}

View file

@ -40,7 +40,19 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
},
names.length);
mNames.addAll(names);
// skip default name
for (int i = 1; i < names.length; i++)
mNames.add(names[i]);
}
public void setNames(SortedList<LocalizedName> names)
{
mNames = names;
}
public SortedList<LocalizedName> getNames()
{
return mNames;
}
@Override
@ -64,13 +76,22 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
return mNames.size();
}
public static class Holder extends RecyclerView.ViewHolder
public class Holder extends RecyclerView.ViewHolder
{
EditText input;
public Holder(View itemView)
{
super(itemView);
input = (EditText) itemView.findViewById(R.id.input);
itemView.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mNames.removeItemAt(getAdapterPosition());
}
});
}
}
}

View file

@ -0,0 +1,16 @@
package com.mapswithme.maps.editor.data;
import android.support.annotation.NonNull;
// Corresponds to StringUtf8Multilang::Lang in core.
public class Language
{
public final String code;
public final String name;
public Language(@NonNull String code, @NonNull String name)
{
this.code = code;
this.name = name;
}
}