mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
[android] Fixed category search for unsupported translations.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
12dbfc6622
commit
d649e46ef2
@@ -17,7 +17,7 @@ JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Router_nativeSet(JNIEnv *, jclas
|
|||||||
case 2: type = Type::Bicycle; break;
|
case 2: type = Type::Bicycle; break;
|
||||||
case 3: type = Type::Transit; break;
|
case 3: type = Type::Transit; break;
|
||||||
case 4: type = Type::Ruler; break;
|
case 4: type = Type::Ruler; break;
|
||||||
default: assert(false); break;
|
default: ASSERT(false, (routerType)); return;
|
||||||
}
|
}
|
||||||
frm()->GetRoutingManager().SetRouter(type);
|
frm()->GetRoutingManager().SetRouter(type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,13 @@ JNIEXPORT jobjectArray JNICALL Java_app_organicmaps_sdk_search_DisplayedCategori
|
|||||||
{
|
{
|
||||||
::Framework * fr = g_framework->NativeFramework();
|
::Framework * fr = g_framework->NativeFramework();
|
||||||
ASSERT(fr, ());
|
ASSERT(fr, ());
|
||||||
search::DisplayedCategories categories = fr->GetDisplayedCategories();
|
search::DisplayedCategories const & categories = fr->GetDisplayedCategories();
|
||||||
return jni::ToJavaStringArray(env, categories.GetKeys());
|
return jni::ToJavaStringArray(env, categories.GetKeys());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_search_DisplayedCategories_nativeIsLangSupported(
|
||||||
|
JNIEnv * env, jclass, jstring langCode)
|
||||||
|
{
|
||||||
|
return search::DisplayedCategories::IsLanguageSupported(jni::ToNativeString(env, langCode));
|
||||||
|
}
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ import androidx.annotation.NonNull;
|
|||||||
public class DisplayedCategories
|
public class DisplayedCategories
|
||||||
{
|
{
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String[] getKeys()
|
public static native String[] nativeGetKeys();
|
||||||
{
|
public static native boolean nativeIsLangSupported(String langCode);
|
||||||
return nativeGetKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private static native String[] nativeGetKeys();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package app.organicmaps.search;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -20,9 +21,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import app.organicmaps.R;
|
import app.organicmaps.R;
|
||||||
import app.organicmaps.sdk.search.DisplayedCategories;
|
import app.organicmaps.sdk.search.DisplayedCategories;
|
||||||
import app.organicmaps.util.ThemeUtils;
|
import app.organicmaps.util.ThemeUtils;
|
||||||
|
import app.organicmaps.util.Language;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolder>
|
class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolder>
|
||||||
{
|
{
|
||||||
@@ -45,14 +48,25 @@ class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolde
|
|||||||
void onSearchCategorySelected(@Nullable String category);
|
void onSearchCategorySelected(@Nullable String category);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CategoriesUiListener mListener;
|
private CategoriesUiListener mListener = null;
|
||||||
|
private boolean mIsLangSupported;
|
||||||
|
private Resources mEnglishResources;
|
||||||
|
|
||||||
CategoriesAdapter(@NonNull Fragment fragment)
|
CategoriesAdapter(@NonNull Fragment fragment)
|
||||||
{
|
{
|
||||||
if (fragment instanceof CategoriesUiListener)
|
|
||||||
mListener = (CategoriesUiListener) fragment;
|
|
||||||
mResources = fragment.getResources();
|
mResources = fragment.getResources();
|
||||||
mInflater = LayoutInflater.from(fragment.requireActivity());
|
mInflater = LayoutInflater.from(fragment.requireActivity());
|
||||||
|
|
||||||
|
if (fragment instanceof CategoriesUiListener)
|
||||||
|
{
|
||||||
|
mListener = (CategoriesUiListener) fragment;
|
||||||
|
mIsLangSupported = DisplayedCategories.nativeIsLangSupported(Language.getDefaultLocale());
|
||||||
|
|
||||||
|
Configuration config = new Configuration(mResources.getConfiguration());
|
||||||
|
config.setLocale(new Locale("en"));
|
||||||
|
Context localizedContext = fragment.getContext().createConfigurationContext(config);
|
||||||
|
mEnglishResources = localizedContext.getResources();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCategories(@NonNull Fragment fragment)
|
void updateCategories(@NonNull Fragment fragment)
|
||||||
@@ -82,7 +96,7 @@ class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolde
|
|||||||
@NonNull
|
@NonNull
|
||||||
private static String[] getAllCategories()
|
private static String[] getAllCategories()
|
||||||
{
|
{
|
||||||
String[] searchCategories = DisplayedCategories.getKeys();
|
String[] searchCategories = DisplayedCategories.nativeGetKeys();
|
||||||
int amountSize = searchCategories.length;
|
int amountSize = searchCategories.length;
|
||||||
String[] allCategories = new String[amountSize];
|
String[] allCategories = new String[amountSize];
|
||||||
|
|
||||||
@@ -190,7 +204,12 @@ class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolde
|
|||||||
{
|
{
|
||||||
@StringRes
|
@StringRes
|
||||||
int categoryId = mCategoryResIds[position];
|
int categoryId = mCategoryResIds[position];
|
||||||
mListener.onSearchCategorySelected(mResources.getString(categoryId) + " ");
|
|
||||||
|
String category = mIsLangSupported ? mResources.getString(categoryId) : mEnglishResources.getString(categoryId);
|
||||||
|
|
||||||
|
/// @todo Pass the correct input language. Now the Core always matches "en" together with "m_inputLocale".
|
||||||
|
/// We expect that Language.getDefaultLocale() will be called further inside.
|
||||||
|
mListener.onSearchCategorySelected(category + " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public:
|
|||||||
fn(name.m_name, CategoriesHolder::MapIntegerToLocale(name.m_locale));
|
fn(name.m_name, CategoriesHolder::MapIntegerToLocale(name.m_locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsLanguageSupported(std::string_view locale)
|
||||||
|
{
|
||||||
|
return CategoriesHolder::MapLocaleToInteger(locale) != CategoriesHolder::kUnsupportedLocaleCode;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CategoriesHolder const & m_holder;
|
CategoriesHolder const & m_holder;
|
||||||
Keys m_keys;
|
Keys m_keys;
|
||||||
|
|||||||
Reference in New Issue
Block a user