diff --git a/android/jni/com/mapswithme/maps/editor/Editor.cpp b/android/jni/com/mapswithme/maps/editor/Editor.cpp
index eb4387cee0..023973cd19 100644
--- a/android/jni/com/mapswithme/maps/editor/Editor.cpp
+++ b/android/jni/com/mapswithme/maps/editor/Editor.cpp
@@ -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)
{
diff --git a/android/res/layout/fragment_editor.xml b/android/res/layout/fragment_editor.xml
index 720d77a1e8..376ccb8784 100644
--- a/android/res/layout/fragment_editor.xml
+++ b/android/res/layout/fragment_editor.xml
@@ -74,7 +74,7 @@
android:id="@+id/cv__name"
style="@style/MwmWidget.Editor.CardView">
-
+
diff --git a/android/res/layout/item_language.xml b/android/res/layout/item_language.xml
new file mode 100644
index 0000000000..56bfb54e48
--- /dev/null
+++ b/android/res/layout/item_language.xml
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/android/res/layout/item_localized_name.xml b/android/res/layout/item_localized_name.xml
index 455ada3597..41ad2472b7 100644
--- a/android/res/layout/item_localized_name.xml
+++ b/android/res/layout/item_localized_name.xml
@@ -1,23 +1,19 @@
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
-
+
-
+
-
-
-
-
-
+
\ No newline at end of file
diff --git a/android/res/layout/localized_name.xml b/android/res/layout/localized_name.xml
new file mode 100644
index 0000000000..faa21ca64f
--- /dev/null
+++ b/android/res/layout/localized_name.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/src/com/mapswithme/maps/editor/Editor.java b/android/src/com/mapswithme/maps/editor/Editor.java
index 378c0144a4..0416c50f49 100644
--- a/android/src/com/mapswithme/maps/editor/Editor.java
+++ b/android/src/com/mapswithme/maps/editor/Editor.java
@@ -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();
diff --git a/android/src/com/mapswithme/maps/editor/EditorFragment.java b/android/src/com/mapswithme/maps/editor/EditorFragment.java
index 85b4893d78..9b521fd852 100644
--- a/android/src/com/mapswithme/maps/editor/EditorFragment.java
+++ b/android/src/com/mapswithme/maps/editor/EditorFragment.java
@@ -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);
+ }
}
diff --git a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
index 58b3cbb6fb..3da53d2748 100644
--- a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
+++ b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
@@ -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();
}
diff --git a/android/src/com/mapswithme/maps/editor/LanguagesAdapter.java b/android/src/com/mapswithme/maps/editor/LanguagesAdapter.java
new file mode 100644
index 0000000000..6f8c5c107e
--- /dev/null
+++ b/android/src/com/mapswithme/maps/editor/LanguagesAdapter.java
@@ -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
+{
+ 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);
+ }
+ }
+}
diff --git a/android/src/com/mapswithme/maps/editor/LanguagesFragment.java b/android/src/com/mapswithme/maps/editor/LanguagesFragment.java
new file mode 100644
index 0000000000..6a981f908b
--- /dev/null
+++ b/android/src/com/mapswithme/maps/editor/LanguagesFragment.java
@@ -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);
+ }
+}
diff --git a/android/src/com/mapswithme/maps/editor/MultilanguageAdapter.java b/android/src/com/mapswithme/maps/editor/MultilanguageAdapter.java
index 16eb8ba4b1..e63a40efb0 100644
--- a/android/src/com/mapswithme/maps/editor/MultilanguageAdapter.java
+++ b/android/src/com/mapswithme/maps/editor/MultilanguageAdapter.java
@@ -40,7 +40,19 @@ public class MultilanguageAdapter extends RecyclerView.Adapter names)
+ {
+ mNames = names;
+ }
+
+ public SortedList getNames()
+ {
+ return mNames;
}
@Override
@@ -64,13 +76,22 @@ public class MultilanguageAdapter extends RecyclerView.Adapter