[core][android] Showing place page by feature id is added. Showing place page by mercator is removed because of incorrect behavior (building was shown instead of poi).

This commit is contained in:
Arsentiy Milchakov 2020-02-14 16:49:02 +03:00 committed by Aleksandr Zatsepin
parent e8889fbf1d
commit ebe7d5afb8
13 changed files with 85 additions and 64 deletions

View file

@ -22,6 +22,7 @@ set(
SRC
# JNI headers
../../private.h
com/mapswithme/util/FeatureIdBuilder.hpp
com/mapswithme/core/jni_helper.hpp
com/mapswithme/core/logging.hpp
com/mapswithme/core/ScopedEnv.hpp

View file

@ -4,11 +4,11 @@
#include "ScopedLocalRef.hpp"
#include "geometry/point2d.hpp"
#include "base/buffer_vector.hpp"
#include "base/logging.hpp"
#include "geometry/point2d.hpp"
#include <iterator>
#include <memory>
#include <string>

View file

@ -4,6 +4,7 @@
#include "com/mapswithme/opengl/androidoglcontextfactory.hpp"
#include "com/mapswithme/platform/Platform.hpp"
#include "com/mapswithme/util/NetworkPolicy.hpp"
#include "com/mapswithme/util/FeatureIdBuilder.hpp"
#include "com/mapswithme/vulkan/android_vulkan_context_factory.hpp"
#include "map/chart_generator.hpp"
@ -874,6 +875,13 @@ void Framework::OnPowerSchemeChanged(power_management::Scheme const actualScheme
// Dummy
// TODO: provide information for UI Properties.
}
FeatureID Framework::BuildFeatureId(JNIEnv * env, jobject featureId)
{
static FeatureIdBuilder const builder(env);
return builder.Build(env, featureId);
}
} // namespace android
//============ GLUE CODE for com.mapswithme.maps.Framework class =============//
@ -1963,7 +1971,6 @@ Java_com_mapswithme_maps_Framework_nativeGetPhoneAuthUrl(JNIEnv * env, jclass, j
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_nativeGetDefaultAuthHeaders(JNIEnv * env, jobject)
{
auto const & bm = frm()->GetBookmarkManager();
return jni::ToKeyValueArray(env, web_api::GetDefaultAuthHeaders());
}
@ -1980,10 +1987,12 @@ Java_com_mapswithme_maps_Framework_nativeGetTermsOfUseLink(JNIEnv * env, jclass)
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeShowFeatureByLatLon(JNIEnv * env, jclass,
jdouble lat, jdouble lon)
Java_com_mapswithme_maps_Framework_nativeShowFeature(JNIEnv * env, jclass, jobject featureId)
{
frm()->ShowFeatureByMercator(mercator::FromLatLon(ms::LatLon(lat, lon)));
auto const f = g_framework->BuildFeatureId(env, featureId);
if (f.IsValid())
frm()->ShowFeature(f);
}
JNIEXPORT void JNICALL

View file

@ -22,6 +22,9 @@
#include "partners_api/promo_api.hpp"
#include "partners_api/utm.hpp"
#include "indexer/feature_decl.hpp"
#include "indexer/map_style.hpp"
#include "platform/country_defines.hpp"
#include "platform/location.hpp"
@ -29,8 +32,6 @@
#include "base/timer.hpp"
#include "indexer/map_style.hpp"
#include <cstdint>
#include <map>
#include <memory>
@ -227,6 +228,8 @@ namespace android
// PowerManager::Subscriber overrides:
void OnPowerFacilityChanged(power_management::Facility const facility, bool enabled) override;
void OnPowerSchemeChanged(power_management::Scheme const actualScheme) override;
FeatureID BuildFeatureId(JNIEnv * env, jobject featureId);
};
}

View file

@ -1,5 +1,5 @@
#include <jni.h>
#include <android/jni/com/mapswithme/maps/Framework.hpp>
#include "com/mapswithme/maps/Framework.hpp"
#include "com/mapswithme/core/jni_helper.hpp"
#include "com/mapswithme/platform/Platform.hpp"

View file

@ -18,46 +18,6 @@
namespace
{
class FeatureIdBuilder
{
public:
FeatureID Build(JNIEnv * env, jobject obj)
{
Init(env);
jstring jcountryName = static_cast<jstring>(env->GetObjectField(obj, m_countryName));
jint jindex = env->GetIntField(obj, m_index);
auto const countryName = jni::ToNativeString(env, jcountryName);
auto const index = static_cast<uint32_t>(jindex);
auto const & ds = g_framework->GetDataSource();
auto const id = ds.GetMwmIdByCountryFile(platform::CountryFile(countryName));
return FeatureID(id, index);
}
private:
void Init(JNIEnv * env)
{
if (m_initialized)
return;
m_class = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/FeatureId");
m_countryName = env->GetFieldID(m_class, "mMwmName", "Ljava/lang/String;");
m_version = env->GetFieldID(m_class, "mMwmVersion", "J");
m_index = env->GetFieldID(m_class, "mFeatureIndex", "I");
m_initialized = true;
}
bool m_initialized = false;
jclass m_class;
jfieldID m_countryName;
jfieldID m_version;
jfieldID m_index;
} g_builder;
class JavaBridge
{
public:
@ -270,7 +230,7 @@ JNIEXPORT
void JNICALL Java_com_mapswithme_maps_ugc_UGC_nativeRequestUGC(JNIEnv * env, jclass /* clazz */,
jobject featureId)
{
auto const fid = g_builder.Build(env, featureId);
auto const fid = g_framework->BuildFeatureId(env, featureId);
g_framework->RequestUGC(fid, [](ugc::UGC const & ugc, ugc::UGCUpdate const & update) {
g_bridge.OnUGCReceived(jni::GetEnv(), ugc, update);
});
@ -281,7 +241,7 @@ void JNICALL Java_com_mapswithme_maps_ugc_UGC_nativeSetUGCUpdate(JNIEnv * env, j
jobject featureId,
jobject ugcUpdate)
{
auto const fid = g_builder.Build(env, featureId);
auto const fid = g_framework->BuildFeatureId(env, featureId);
ugc::UGCUpdate update = g_bridge.ToNativeUGCUpdate(env, ugcUpdate);
g_framework->SetUGCUpdate(fid, update, [](ugc::Storage::SettingResult const & result) {
g_bridge.OnUGCSaved(jni::GetEnv(), result);

View file

@ -0,0 +1,36 @@
#pragma once
#include "com/mapswithme/core/jni_helper.hpp"
#include "indexer/feature_decl.hpp"
class FeatureIdBuilder
{
public:
FeatureIdBuilder(JNIEnv * env)
{
m_class = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/FeatureId");
m_countryName = env->GetFieldID(m_class, "mMwmName", "Ljava/lang/String;");
m_version = env->GetFieldID(m_class, "mMwmVersion", "J");
m_index = env->GetFieldID(m_class, "mFeatureIndex", "I");
}
FeatureID Build(JNIEnv * env, jobject obj) const
{
jstring jcountryName = static_cast<jstring>(env->GetObjectField(obj, m_countryName));
jint jindex = env->GetIntField(obj, m_index);
auto const countryName = jni::ToNativeString(env, jcountryName);
auto const index = static_cast<uint32_t>(jindex);
auto const & ds = g_framework->GetDataSource();
auto const id = ds.GetMwmIdByCountryFile(platform::CountryFile(countryName));
return FeatureID(id, index);
}
private:
jclass m_class;
jfieldID m_countryName;
jfieldID m_version;
jfieldID m_index;
};

View file

@ -18,6 +18,7 @@ import com.mapswithme.maps.api.ParsedUrlMwmRequest;
import com.mapswithme.maps.auth.AuthorizationListener;
import com.mapswithme.maps.background.NotificationCandidate;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.DownloaderPromoBanner;
import com.mapswithme.maps.gdpr.UserBindingListener;
@ -493,7 +494,7 @@ public class Framework
@NonNull
public static native String nativeGetTermsOfUseLink();
public static native void nativeShowFeatureByLatLon(double lat, double lon);
public static native void nativeShowFeature(@NonNull FeatureId featureId);
public static native void nativeShowBookmarkCategory(long cat);
private static native int nativeGetFilterRating(float rawRating);

View file

@ -1165,7 +1165,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public boolean run(@NonNull MwmActivity target)
{
Framework.nativeShowFeatureByLatLon(object.getLat(), object.getLon());
Framework.nativeShowFeature(object.getFeatureId());
return false;
}
});

View file

@ -399,7 +399,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
String title = TextUtils.isEmpty(item.getTitle()) ? subtitle : item.getTitle();
return MapObject.createMapObject(FeatureId.EMPTY, MapObject.SEARCH, title, subtitle,
return MapObject.createMapObject(item.getFeatureId(), MapObject.SEARCH, title, subtitle,
item.getLat(), item.getLon());
}

View file

@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.search.Popularity;
import com.mapswithme.maps.search.SearchResult;
@ -135,6 +136,15 @@ public class Items
return mResult.description.featureType;
}
@NonNull
public FeatureId getFeatureId()
{
if (mResult.description == null)
return FeatureId.EMPTY;
return mResult.description.featureId == null ? FeatureId.EMPTY : mResult.description.featureId;
}
@NonNull
public Popularity getPopularity()
{

View file

@ -1136,17 +1136,20 @@ void Framework::ShowBookmarkCategory(kml::MarkGroupId categoryId, bool animation
ShowRect(rect, -1 /* maxScale */, animation);
}
void Framework::ShowFeatureByMercator(m2::PointD const & pt)
void Framework::ShowFeature(FeatureID const & featureId)
{
StopLocationFollow();
place_page::BuildInfo info;
info.m_mercator = pt;
info.m_featureId = featureId;
info.m_match = place_page::BuildInfo::Match::FeatureOnly;
m_currentPlacePageInfo = BuildPlacePageInfo(info);
if (m_drapeEngine != nullptr)
{
m_drapeEngine->SetModelViewCenter(pt, scales::GetUpperComfortScale(), true /* isAnim */,
true /* trackVisibleViewport */);
auto const pt = m_currentPlacePageInfo->GetMercator();
auto const scale = scales::GetUpperComfortScale();
m_drapeEngine->SetModelViewCenter(pt, scale, true /* isAnim */, true /* trackVisibleViewport */);
}
ActivateMapSelection(m_currentPlacePageInfo);
}
@ -3124,20 +3127,18 @@ bool Framework::ParseEditorDebugCommand(search::SearchParams const & params)
auto const features = FindFeaturesByIndex(index);
for (auto const & fid : features)
{
FeaturesLoaderGuard guard(m_featuresFetcher.GetDataSource(), fid.m_mwmId);
auto ft = guard.GetFeatureByIndex(fid.m_index);
if (!ft)
if (!fid.IsValid())
continue;
// Show the first feature on the map.
if (!isShown)
{
ShowFeatureByMercator(feature::GetCenter(*ft));
ShowFeature(fid);
isShown = true;
}
// Log found features.
LOG(LINFO, ("Feature found:", fid, mercator::ToLatLon(feature::GetCenter(*ft))));
LOG(LINFO, ("Feature found:", fid));
}
}
return true;

View file

@ -351,7 +351,7 @@ public:
void ShowBookmark(kml::MarkId id);
void ShowBookmark(Bookmark const * bookmark);
void ShowTrack(kml::TrackId trackId);
void ShowFeatureByMercator(m2::PointD const & pt);
void ShowFeature(FeatureID const & featureId);
void ShowBookmarkCategory(kml::MarkGroupId categoryId, bool animation = true);
void AddBookmarksFile(std::string const & filePath, bool isTemporaryFile);