forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
b5d7c05763
commit
d9796a3e7b
7 changed files with 55 additions and 45 deletions
|
@ -36,6 +36,7 @@ jmethodID g_descriptionConstructor;
|
|||
jobject ToJavaResult(Result & result, bool hasPosition, double lat, double lon)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
::Framework * fr = g_framework->NativeFramework();
|
||||
|
||||
jni::TScopedLocalIntArrayRef ranges(env, env->NewIntArray(result.GetHighlightRangesCount() * 2));
|
||||
jint * rawArr = env->GetIntArrayElements(ranges.get(), nullptr);
|
||||
|
@ -55,7 +56,7 @@ jobject ToJavaResult(Result & result, bool hasPosition, double lat, double lon)
|
|||
if (hasPosition)
|
||||
{
|
||||
double dummy;
|
||||
(void) g_framework->NativeFramework()->GetDistanceAndAzimut(result.GetFeatureCenter(), lat, lon, 0, distance, dummy);
|
||||
(void) fr->GetDistanceAndAzimut(result.GetFeatureCenter(), lat, lon, 0, distance, dummy);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,10 +72,11 @@ jobject ToJavaResult(Result & result, bool hasPosition, double lat, double lon)
|
|||
search::AddressInfo info;
|
||||
if (result.GetResultType() == Result::RESULT_FEATURE)
|
||||
{
|
||||
::Framework * frm = g_framework->NativeFramework();
|
||||
frm->LoadSearchResultMetadata(result);
|
||||
frm->GetSearchResultAddress(result);
|
||||
fr->LoadSearchResultMetadata(result);
|
||||
info = fr->GetFeatureAddressInfo(result.GetFeatureID());
|
||||
}
|
||||
else if (result.HasPoint())
|
||||
info = fr->GetAddressInfoAtPoint(result.GetFeatureCenter());
|
||||
|
||||
jni::TScopedLocalRef featureType(env, jni::ToJavaString(env, result.GetFeatureType()));
|
||||
jni::TScopedLocalRef region(env, jni::ToJavaString(env, info.FormatAddress(search::AddressInfo::SEARCH_RESULT)));
|
||||
|
|
|
@ -23,19 +23,19 @@ void InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, f
|
|||
}
|
||||
|
||||
jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title, string const & subtitle,
|
||||
double lat, double lon, string const & address, Metadata const & metadata)
|
||||
double lat, double lon, string const & address, Metadata const & metadata, string const & apiId)
|
||||
{
|
||||
// public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, double lat, double lon, String address, Metadata metadata)
|
||||
// public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, double lat, double lon, String address, String apiId)
|
||||
static jmethodID const ctorId =
|
||||
jni::GetConstructorID(env, g_mapObjectClazz, "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;DD)V");
|
||||
jni::GetConstructorID(env, g_mapObjectClazz, "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/String;)V");
|
||||
|
||||
jobject mapObject = env->NewObject(g_mapObjectClazz, ctorId,
|
||||
static_cast<jint>(mapObjectType),
|
||||
mapObjectType,
|
||||
jni::ToJavaString(env, title),
|
||||
jni::ToJavaString(env, subtitle),
|
||||
jni::ToJavaString(env, address),
|
||||
static_cast<jdouble>(lat),
|
||||
static_cast<jdouble>(lon));
|
||||
lat, lon,
|
||||
jni::ToJavaString(env, apiId));
|
||||
|
||||
InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
|
||||
return mapObject;
|
||||
|
@ -49,10 +49,10 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
// TODO(yunikkk): object can be POI + API + search result + bookmark simultaneously.
|
||||
// TODO(yunikkk): Should we pass localized strings here and in other methods as byte arrays?
|
||||
if (info.IsMyPosition())
|
||||
return CreateMapObject(env, kMyPosition, {}, {}, ll.lat, ll.lon, address.FormatAddress(), {});
|
||||
return CreateMapObject(env, kMyPosition, "", "", ll.lat, ll.lon, address.FormatAddress(), {}, "");
|
||||
|
||||
if (info.HasApiUrl())
|
||||
return CreateMapObject(env, kApiPoint, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon, address.FormatAddress(), info.GetMetadata());
|
||||
return CreateMapObject(env, kApiPoint, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon, address.FormatAddress(), info.GetMetadata(), info.GetApiUrl());
|
||||
|
||||
if (info.IsBookmark())
|
||||
{
|
||||
|
@ -69,6 +69,6 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
}
|
||||
|
||||
return CreateMapObject(env, kPoi, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon, address.FormatAddress(),
|
||||
info.IsFeature() ? info.GetMetadata() : Metadata());
|
||||
info.IsFeature() ? info.GetMetadata() : Metadata(), "");
|
||||
}
|
||||
} // namespace usermark_helper
|
||||
|
|
|
@ -1006,8 +1006,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
if (request == null)
|
||||
return;
|
||||
|
||||
// TODO @yunikkk get point id for api point from core.
|
||||
request.setPointData(object.getLat(), object.getLon(), object.getTitle(), "");
|
||||
request.setPointData(object.getLat(), object.getLon(), object.getTitle(), object.getApiId());
|
||||
object.setSubtitle(request.getCallerName(MwmApplication.get()).toString());
|
||||
}
|
||||
else if (MapObject.isOfType(MapObject.MY_POSITION, object) &&
|
||||
|
|
|
@ -20,7 +20,7 @@ public class Bookmark extends MapObject
|
|||
|
||||
Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId, String title)
|
||||
{
|
||||
super(BOOKMARK, title, "", "", 0, 0);
|
||||
super(BOOKMARK, title, "", "", 0, 0, "");
|
||||
|
||||
mCategoryId = categoryId;
|
||||
mBookmarkId = bookmarkId;
|
||||
|
|
|
@ -35,13 +35,14 @@ public class MapObject implements Parcelable
|
|||
protected double mLon;
|
||||
protected String mAddress;
|
||||
protected Metadata mMetadata;
|
||||
protected String mApiId;
|
||||
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, String address, double lat, double lon)
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, String address, double lat, double lon, String apiId)
|
||||
{
|
||||
this(mapObjectType, title, subtitle, address, lat, lon, new Metadata());
|
||||
this(mapObjectType, title, subtitle, address, lat, lon, new Metadata(), apiId);
|
||||
}
|
||||
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, String address, double lat, double lon, Metadata metadata)
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, String address, double lat, double lon, Metadata metadata, String apiId)
|
||||
{
|
||||
mMapObjectType = mapObjectType;
|
||||
mTitle = title;
|
||||
|
@ -50,6 +51,7 @@ public class MapObject implements Parcelable
|
|||
mLat = lat;
|
||||
mLon = lon;
|
||||
mMetadata = metadata;
|
||||
mApiId = apiId;
|
||||
}
|
||||
|
||||
protected MapObject(Parcel source)
|
||||
|
@ -61,7 +63,8 @@ public class MapObject implements Parcelable
|
|||
source.readString(), // Address
|
||||
source.readDouble(), // Lat
|
||||
source.readDouble(), // Lon
|
||||
(Metadata) source.readParcelable(Metadata.class.getClassLoader()));
|
||||
(Metadata) source.readParcelable(Metadata.class.getClassLoader()),
|
||||
source.readString()); // ApiId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,35 +116,17 @@ public class MapObject implements Parcelable
|
|||
return res == null ? "" : res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return properly formatted and translated cuisine string.
|
||||
*/
|
||||
@NonNull
|
||||
static public String formatCuisine(String rawOsmCuisineValue)
|
||||
{
|
||||
if (TextUtils.isEmpty(rawOsmCuisineValue))
|
||||
return "";
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
// search translations for each cuisine
|
||||
final Resources resources = MwmApplication.get().getResources();
|
||||
for (String rawCuisine : Metadata.splitCuisines(rawOsmCuisineValue))
|
||||
{
|
||||
int resId = resources.getIdentifier(Metadata.osmCuisineToStringName(Metadata.normalizeCuisine(rawCuisine)), "string", BuildConfig.APPLICATION_ID);
|
||||
if (result.length() > 0)
|
||||
result.append(", ");
|
||||
result.append(resId == 0 ? rawCuisine : resources.getString(resId));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@MapObjectType
|
||||
public int getMapObjectType()
|
||||
{
|
||||
return mMapObjectType;
|
||||
}
|
||||
|
||||
public String getApiId()
|
||||
{
|
||||
return mApiId;
|
||||
}
|
||||
|
||||
public void setLat(double lat)
|
||||
{
|
||||
mLat = lat;
|
||||
|
@ -204,6 +189,7 @@ public class MapObject implements Parcelable
|
|||
dest.writeDouble(mLat);
|
||||
dest.writeDouble(mLon);
|
||||
dest.writeParcelable(mMetadata, 0);
|
||||
dest.writeString(mApiId);
|
||||
}
|
||||
|
||||
public static final Creator<MapObject> CREATOR = new Creator<MapObject>()
|
||||
|
@ -220,4 +206,27 @@ public class MapObject implements Parcelable
|
|||
return new MapObject[size];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return properly formatted and translated cuisine string.
|
||||
*/
|
||||
@NonNull
|
||||
static public String formatCuisine(String rawOsmCuisineValue)
|
||||
{
|
||||
if (TextUtils.isEmpty(rawOsmCuisineValue))
|
||||
return "";
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
// search translations for each cuisine
|
||||
final Resources resources = MwmApplication.get().getResources();
|
||||
for (String rawCuisine : Metadata.splitCuisines(rawOsmCuisineValue))
|
||||
{
|
||||
int resId = resources.getIdentifier(Metadata.osmCuisineToStringName(Metadata.normalizeCuisine(rawCuisine)), "string", BuildConfig.APPLICATION_ID);
|
||||
if (result.length() > 0)
|
||||
result.append(", ");
|
||||
result.append(resId == 0 ? rawCuisine : resources.getString(resId));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ public enum LocationHelper implements SensorEventListener
|
|||
return null;
|
||||
|
||||
if (mMyPosition == null)
|
||||
mMyPosition = new MapObject(MapObject.MY_POSITION, "", "", "", mLastLocation.getLatitude(), mLastLocation.getLongitude());
|
||||
mMyPosition = new MapObject(MapObject.MY_POSITION, "", "", "", mLastLocation.getLatitude(), mLastLocation.getLongitude(), "");
|
||||
|
||||
return mMyPosition;
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
if (mFromRoutePlan)
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
final MapObject point = new MapObject(MapObject.SEARCH, result.name, result.description.featureType, "", result.lat, result.lon);
|
||||
final MapObject point = new MapObject(MapObject.SEARCH, result.name, result.description.featureType, "", result.lat, result.lon, "");
|
||||
RoutingController.get().onPoiSelected(point);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue