forked from organicmaps/organicmaps
Added name to GuideInfo and method for retrieving guide by id.
This commit is contained in:
parent
edfb433ae1
commit
f6e8f27fba
4 changed files with 67 additions and 9 deletions
|
@ -867,7 +867,7 @@ extern "C"
|
|||
{
|
||||
m_giClass = m_env->FindClass("com/mapswithme/maps/guides/GuideInfo");
|
||||
m_methodID = m_env->GetMethodID(m_giClass,
|
||||
"<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
"<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
m_lang = languages::CurrentLanguage();
|
||||
}
|
||||
|
||||
|
@ -879,7 +879,8 @@ extern "C"
|
|||
jni::ToJavaString(m_env, info.GetAppID()),
|
||||
jni::ToJavaString(m_env, info.GetURL()),
|
||||
jni::ToJavaString(m_env, info.GetAdTitle(m_lang)),
|
||||
jni::ToJavaString(m_env, info.GetAdMessage(m_lang)));
|
||||
jni::ToJavaString(m_env, info.GetAdMessage(m_lang)),
|
||||
jni::ToJavaString(m_env, info.GetName()));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -907,6 +908,38 @@ extern "C"
|
|||
return g_framework->NativeFramework()->GetGuidesManager().WasAdvertised(jni::ToNativeString(env, appId));
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_mapswithme_maps_Framework_getGuideIds(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
std::set<string> guides;
|
||||
g_framework->NativeFramework()->GetGuidesManager().GetGuidesId(guides);
|
||||
|
||||
jclass klass = env->FindClass("java/lang/String");
|
||||
ASSERT ( klass, () );
|
||||
|
||||
jobjectArray arr = env->NewObjectArray(guides.size(), klass, 0);
|
||||
|
||||
set<string>::iterator it;
|
||||
int i = 0;
|
||||
for (it = guides.begin(); it != guides.end(); ++it)
|
||||
{
|
||||
string guideId = *it;
|
||||
env->SetObjectArrayElement(arr, i++, jni::ToJavaString(env, guideId));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_Framework_getGuideById(JNIEnv * env, jclass clazz, jstring guideId)
|
||||
{
|
||||
guides::GuideInfo info;
|
||||
if (g_framework->NativeFramework()->GetGuidesManager().GetGuideInfoByAppId(jni::ToNativeString(env, guideId), info))
|
||||
return GuideNative2Java(env).GetGuide(info);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_Framework_getDrawScale(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,16 @@ string GetStringImpl(json_t * j)
|
|||
return (s ? s : "");
|
||||
}
|
||||
|
||||
GuideInfo::GuideInfo(json_struct_t * obj, const char * name)
|
||||
: m_obj(obj), m_name(name ? name : "")
|
||||
{
|
||||
}
|
||||
|
||||
string GuideInfo::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
string GuideInfo::GetString(char const * key) const
|
||||
{
|
||||
return GetStringImpl(json_object_get(m_obj.get(), key));
|
||||
|
@ -155,9 +165,9 @@ void GuidesManager::UpdateGuidesData()
|
|||
}
|
||||
}
|
||||
|
||||
bool GuidesManager::GetGuideInfo(string const & id, GuideInfo & appInfo) const
|
||||
bool GuidesManager::GetGuideInfo(string const & countryFile, GuideInfo & appInfo) const
|
||||
{
|
||||
MapT::const_iterator const it = m_file2Info.find(id);
|
||||
MapT::const_iterator const it = m_file2Info.find(countryFile);
|
||||
if (it != m_file2Info.end())
|
||||
{
|
||||
appInfo = it->second;
|
||||
|
@ -166,9 +176,20 @@ bool GuidesManager::GetGuideInfo(string const & id, GuideInfo & appInfo) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GuidesManager::GetGuideInfoByAppId(string const & id, GuideInfo & appInfo) const
|
||||
{
|
||||
for (MapT::const_iterator it = m_file2Info.begin(); it != m_file2Info.end(); ++it)
|
||||
if (it->second.GetAppID() == id)
|
||||
{
|
||||
appInfo = it->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GuidesManager::GetGuidesIds(set<string> & s)
|
||||
{
|
||||
for (MapT::iterator it = m_file2Info.begin(); it != m_file2Info.end();++it)
|
||||
for (MapT::iterator it = m_file2Info.begin(); it != m_file2Info.end(); ++it)
|
||||
s.insert(it->second.GetAppID());
|
||||
}
|
||||
|
||||
|
@ -252,7 +273,7 @@ int GuidesManager::ParseGuidesData(string const & jsonData, MapT & guidesInfo)
|
|||
version = json_integer_value(entry);
|
||||
else
|
||||
{
|
||||
GuideInfo info(entry);
|
||||
GuideInfo info(entry, json_object_iter_key(iter));
|
||||
if (info.IsValid())
|
||||
{
|
||||
json_t * keys = json_object_get(entry, "keys");
|
||||
|
@ -260,7 +281,7 @@ int GuidesManager::ParseGuidesData(string const & jsonData, MapT & guidesInfo)
|
|||
{
|
||||
char const * key = json_string_value(json_array_get(keys, i));
|
||||
if (key)
|
||||
temp[key] = info;
|
||||
temp.insert(MapT::value_type(key, info));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,15 @@ namespace guides
|
|||
class GuideInfo
|
||||
{
|
||||
my::JsonHandle m_obj;
|
||||
string m_name;
|
||||
|
||||
string GetString(char const * key) const;
|
||||
string GetAdForLang(string const & lang, char const * key) const;
|
||||
|
||||
public:
|
||||
GuideInfo(json_struct_t * obj = 0) : m_obj(obj) {}
|
||||
GuideInfo(json_struct_t * obj = 0, char const * name = 0);
|
||||
|
||||
string GetName() const;
|
||||
string GetURL() const;
|
||||
string GetAppID() const;
|
||||
string GetAdTitle(string const & lang) const;
|
||||
|
@ -50,7 +52,8 @@ public:
|
|||
static string GetDataFileFullPath();
|
||||
|
||||
/// @param[in] id MWM file name without extension as a key.
|
||||
bool GetGuideInfo(string const & id, GuideInfo & appInfo) const;
|
||||
bool GetGuideInfo(string const & countryFile, GuideInfo & appInfo) const;
|
||||
bool GetGuideInfoByAppId(string const & id, GuideInfo & appInfo) const;
|
||||
void GetGuidesIds(set<string> & s);
|
||||
|
||||
/// @param[in] appID Guide app package id.
|
||||
|
|
|
@ -37,6 +37,7 @@ UNIT_TEST(Guides_SmokeTest)
|
|||
TEST(manager.GetGuideInfo("Guernsey", info), ());
|
||||
TEST(info.IsValid(), ());
|
||||
|
||||
TEST_EQUAL(info.GetName(), "UK", ());
|
||||
TEST_EQUAL(info.GetAdTitle("en"), "UK title", ());
|
||||
TEST_EQUAL(info.GetAdMessage("en"), "UK message", ());
|
||||
TEST_EQUAL(info.GetAdTitle("ru"), "ВБ заголовок", ());
|
||||
|
|
Loading…
Add table
Reference in a new issue