forked from organicmaps/organicmaps
[android] Search by categories UI.
This commit is contained in:
parent
9c12757d30
commit
19356223bf
7 changed files with 81 additions and 24 deletions
|
@ -53,8 +53,8 @@ jobject GetNewPoint(JNIEnv * env, m2::PointI const & point);
|
|||
template<typename TValue, typename TToJavaFn>
|
||||
jobjectArray ToJavaArray(JNIEnv * env, jclass clazz, vector<TValue> const & src, TToJavaFn && toJavaFn)
|
||||
{
|
||||
int const size = src.size();
|
||||
jobjectArray jArray = env->NewObjectArray(size, clazz, 0);
|
||||
size_t const size = src.size();
|
||||
jobjectArray jArray = env->NewObjectArray((jint) size, clazz, 0);
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
TScopedLocalRef jItem(env, toJavaFn(env, src[i]));
|
||||
|
|
|
@ -32,9 +32,10 @@ jmethodID g_localStreetCtor;
|
|||
jfieldID g_localStreetFieldDef;
|
||||
jfieldID g_localStreetFieldLoc;
|
||||
|
||||
jobject ToJavaFeatureCategory(JNIEnv * env, osm::Category const & category)
|
||||
jobject ToJavaFeatureCategory(JNIEnv * env, osm::NewFeatureCategories::TName const & category)
|
||||
{
|
||||
return env->NewObject(g_featureCategoryClazz, g_featureCtor, category.m_type, jni::TScopedLocalRef(env, jni::ToJavaString(env, category.m_name)).get());
|
||||
return env->NewObject(g_featureCategoryClazz, g_featureCtor, category.second,
|
||||
jni::TScopedLocalRef(env, jni::ToJavaString(env, category.first)).get());
|
||||
}
|
||||
|
||||
jobject ToJavaName(JNIEnv * env, osm::LocalizedName const & name)
|
||||
|
@ -52,6 +53,12 @@ jobject ToJavaStreet(JNIEnv * env, osm::LocalizedStreet const & street)
|
|||
jni::TScopedLocalRef(env, jni::ToJavaString(env, street.m_defaultName)).get(),
|
||||
jni::TScopedLocalRef(env, jni::ToJavaString(env, street.m_localizedName)).get());
|
||||
}
|
||||
|
||||
osm::NewFeatureCategories & GetFeatureCategories()
|
||||
{
|
||||
static osm::NewFeatureCategories categories = g_framework->NativeFramework()->GetEditorCategories();
|
||||
return categories;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
|
@ -395,16 +402,22 @@ Java_com_mapswithme_maps_editor_Editor_nativeCreateMapObject(JNIEnv *, jclass, j
|
|||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_mapswithme_maps_editor_Editor_nativeGetNewFeatureCategories(JNIEnv * env, jclass clazz)
|
||||
Java_com_mapswithme_maps_editor_Editor_nativeGetAllFeatureCategories(JNIEnv * env, jclass clazz, jstring jLang)
|
||||
{
|
||||
return jni::ToJavaArray(env, g_featureCategoryClazz, g_framework->NativeFramework()->GetEditorCategories().m_allSorted,
|
||||
string const & lang = jni::ToNativeString(env, jLang);
|
||||
GetFeatureCategories().AddLanguage(lang);
|
||||
return jni::ToJavaArray(env, g_featureCategoryClazz,
|
||||
GetFeatureCategories().GetAllCategoryNames(lang),
|
||||
ToJavaFeatureCategory);
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_mapswithme_maps_editor_Editor_nativeGetUsedFeatureCategories(JNIEnv * env, jclass clazz)
|
||||
Java_com_mapswithme_maps_editor_Editor_nativeSearchFeatureCategories(JNIEnv * env, jclass clazz, jstring query, jstring jLang)
|
||||
{
|
||||
return jni::ToJavaArray(env, g_featureCategoryClazz, g_framework->NativeFramework()->GetEditorCategories().m_lastUsed,
|
||||
string const & lang = jni::ToNativeString(env, jLang);
|
||||
GetFeatureCategories().AddLanguage(lang);
|
||||
return jni::ToJavaArray(env, g_featureCategoryClazz,
|
||||
GetFeatureCategories().Search(jni::ToNativeString(env, query), lang),
|
||||
ToJavaFeatureCategory);
|
||||
}
|
||||
|
||||
|
|
12
android/res/layout/fragment_categories.xml
Normal file
12
android/res/layout/fragment_categories.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?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="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/toolbar_with_search"/>
|
||||
|
||||
<include layout="@layout/recycler_default"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -119,8 +119,10 @@ public final class Editor
|
|||
*/
|
||||
public static native boolean nativeSaveEditedFeature();
|
||||
|
||||
public static native FeatureCategory[] nativeGetNewFeatureCategories();
|
||||
public static native FeatureCategory[] nativeGetUsedFeatureCategories();
|
||||
@NonNull
|
||||
public static native FeatureCategory[] nativeGetAllFeatureCategories(String lang);
|
||||
@NonNull
|
||||
public static native FeatureCategory[] nativeSearchFeatureCategories(String query, String lang);
|
||||
|
||||
/**
|
||||
* Creates new object on the map. Places it in the center of current viewport.
|
||||
|
|
|
@ -1,30 +1,28 @@
|
|||
package com.mapswithme.maps.editor;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseToolbarActivity;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.editor.data.FeatureCategory;
|
||||
|
||||
public class FeatureCategoryActivity extends BaseToolbarActivity implements FeatureCategoryFragment.FeatureCategoryListener
|
||||
public class FeatureCategoryActivity extends BaseMwmFragmentActivity implements FeatureCategoryFragment.FeatureCategoryListener
|
||||
{
|
||||
public static final String EXTRA_FEATURE_CATEGORY = "FeatureCategory";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return FeatureCategoryFragment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getToolbarTitle()
|
||||
{
|
||||
return R.string.editor_add_select_category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFeatureCategorySelected(FeatureCategory category)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.mapswithme.util.UiUtils;
|
|||
|
||||
public class FeatureCategoryAdapter extends RecyclerView.Adapter<FeatureCategoryAdapter.FeatureViewHolder>
|
||||
{
|
||||
private final FeatureCategory[] mCategories;
|
||||
private FeatureCategory[] mCategories;
|
||||
private final FeatureCategoryFragment mFragment;
|
||||
private FeatureCategory mSelectedCategory;
|
||||
|
||||
|
@ -25,6 +25,12 @@ public class FeatureCategoryAdapter extends RecyclerView.Adapter<FeatureCategory
|
|||
mSelectedCategory = category;
|
||||
}
|
||||
|
||||
public void setCategories(FeatureCategory[] categories)
|
||||
{
|
||||
mCategories = categories;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
|
|
|
@ -6,12 +6,17 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.editor.data.FeatureCategory;
|
||||
import com.mapswithme.maps.widget.SearchToolbarController;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
import com.mapswithme.util.Language;
|
||||
|
||||
public class FeatureCategoryFragment extends BaseMwmRecyclerFragment
|
||||
{
|
||||
private FeatureCategory mSelectedCategory;
|
||||
protected ToolbarController mToolbarController;
|
||||
|
||||
public interface FeatureCategoryListener
|
||||
{
|
||||
|
@ -21,15 +26,36 @@ public class FeatureCategoryFragment extends BaseMwmRecyclerFragment
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.fragment_categories, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getArguments() != null && getArguments().containsKey(FeatureCategoryActivity.EXTRA_FEATURE_CATEGORY))
|
||||
mSelectedCategory = getArguments().getParcelable(FeatureCategoryActivity.EXTRA_FEATURE_CATEGORY);
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
mToolbarController = new SearchToolbarController(view, getActivity())
|
||||
{
|
||||
@Override
|
||||
protected void onTextChanged(String query)
|
||||
{
|
||||
setFilter(query);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setFilter(String query)
|
||||
{
|
||||
((FeatureCategoryAdapter) getAdapter()).setCategories(query.isEmpty() ? Editor.nativeGetAllFeatureCategories(Language.getKeyboardLocale())
|
||||
: Editor.nativeSearchFeatureCategories(query, Language.getKeyboardLocale()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
return new FeatureCategoryAdapter(this, Editor.nativeGetNewFeatureCategories(), mSelectedCategory);
|
||||
return new FeatureCategoryAdapter(this, Editor.nativeGetAllFeatureCategories(Language.getKeyboardLocale()), mSelectedCategory);
|
||||
}
|
||||
|
||||
public void selectCategory(FeatureCategory category)
|
||||
|
|
Loading…
Add table
Reference in a new issue