forked from organicmaps/organicmaps
[android] Implemented JNI to get rating categories and convert it to java rating list
This commit is contained in:
parent
5617d65095
commit
8052cec4de
7 changed files with 72 additions and 25 deletions
|
@ -24,6 +24,7 @@ jclass g_httpHeaderClazz;
|
|||
jclass g_platformSocketClazz;
|
||||
jclass g_utilsClazz;
|
||||
jclass g_bannerClazz;
|
||||
jclass g_ratingClazz;
|
||||
jclass g_arrayListClazz;
|
||||
jclass g_loggerFactoryClazz;
|
||||
|
||||
|
@ -47,6 +48,7 @@ JNI_OnLoad(JavaVM * jvm, void *)
|
|||
g_platformSocketClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/location/PlatformSocket");
|
||||
g_utilsClazz = jni::GetGlobalClassRef(env, "com/mapswithme/util/Utils");
|
||||
g_bannerClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ads/Banner");
|
||||
g_ratingClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Rating");
|
||||
g_loggerFactoryClazz = jni::GetGlobalClassRef(env, "com/mapswithme/util/log/LoggerFactory");
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
|
@ -67,6 +69,7 @@ JNI_OnUnload(JavaVM *, void *)
|
|||
env->DeleteGlobalRef(g_platformSocketClazz);
|
||||
env->DeleteGlobalRef(g_utilsClazz);
|
||||
env->DeleteGlobalRef(g_bannerClazz);
|
||||
env->DeleteGlobalRef(g_ratingClazz);
|
||||
env->DeleteGlobalRef(g_loggerFactoryClazz);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -21,6 +21,7 @@ extern jclass g_httpHeaderClazz;
|
|||
extern jclass g_platformSocketClazz;
|
||||
extern jclass g_utilsClazz;
|
||||
extern jclass g_bannerClazz;
|
||||
extern jclass g_ratingClazz;
|
||||
extern jclass g_loggerFactoryClazz;
|
||||
|
||||
namespace jni
|
||||
|
|
|
@ -31,8 +31,16 @@ jobject CreateBanner(JNIEnv * env, std::string const & id, jint type)
|
|||
{
|
||||
static jmethodID const bannerCtorId =
|
||||
jni::GetConstructorID(env, g_bannerClazz, "(Ljava/lang/String;I)V");
|
||||
jni::TScopedLocalRef idRef(env, jni::ToJavaString(env, id));
|
||||
return env->NewObject(g_bannerClazz, bannerCtorId, idRef.get(), type);
|
||||
}
|
||||
|
||||
return env->NewObject(g_bannerClazz, bannerCtorId, jni::ToJavaString(env, id), type);
|
||||
jobject CreateRating(JNIEnv * env, std::string const & name)
|
||||
{
|
||||
static jmethodID const ratingCtorId =
|
||||
jni::GetConstructorID(env, g_ratingClazz, "(Ljava/lang/String;F)V");
|
||||
jni::TScopedLocalRef nameRef(env, jni::ToJavaString(env, name));
|
||||
return env->NewObject(g_ratingClazz, ratingCtorId, nameRef.get(), place_page::kIncorrectRating);
|
||||
}
|
||||
|
||||
jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion,
|
||||
|
@ -42,7 +50,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
|
|||
string const & apiId, jobjectArray jbanners, jintArray jTaxiTypes,
|
||||
string const & bookingSearchUrl, jobject const & localAdInfo,
|
||||
jobject const & routingPointInfo, bool isExtendedView, bool shouldShowUGC,
|
||||
bool canBeRated, bool canBeReviewed)
|
||||
bool canBeRated, bool canBeReviewed, jobjectArray jratings)
|
||||
{
|
||||
// public MapObject(@NonNull FeatureId featureId,
|
||||
// @MapObjectType int mapObjectType, String title, @Nullable String
|
||||
|
@ -57,7 +65,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
|
|||
"String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/"
|
||||
"String;[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;"
|
||||
"Lcom/mapswithme/maps/ads/LocalAdInfo;"
|
||||
"Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZZ)V");
|
||||
"Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZZ[Lcom/mapswithme/maps/ugc/UGC$Rating;)V");
|
||||
//public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex)
|
||||
static jmethodID const featureCtorId =
|
||||
jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V");
|
||||
|
@ -77,7 +85,8 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
|
|||
jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), lat, lon, jApiId.get(),
|
||||
jbanners, jTaxiTypes, jBookingSearchUrl.get(), localAdInfo, routingPointInfo,
|
||||
static_cast<jboolean>(isExtendedView), static_cast<jboolean>(shouldShowUGC),
|
||||
static_cast<jboolean>(canBeRated), static_cast<jboolean>(canBeReviewed));
|
||||
static_cast<jboolean>(canBeRated), static_cast<jboolean>(canBeReviewed),
|
||||
jratings);
|
||||
|
||||
InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
|
||||
return mapObject;
|
||||
|
@ -89,6 +98,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
if (info.HasBanner())
|
||||
jbanners.reset(ToBannersArray(env, info.GetBanners()));
|
||||
|
||||
jni::TScopedLocalObjectArrayRef jratings(env, ToRatingArray(env, info.GetRatingCategories()));
|
||||
|
||||
jni::TScopedLocalIntArrayRef jTaxiTypes(env, ToReachableByTaxiProvidersArray(env, info.ReachableByTaxiProviders()));
|
||||
|
||||
jni::TScopedLocalRef localAdInfo(env, CreateLocalAdInfo(env, info));
|
||||
|
@ -111,7 +122,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;"
|
||||
"Lcom/mapswithme/maps/ads/LocalAdInfo;"
|
||||
"Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZZ)V");
|
||||
"Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZZ[Lcom/mapswithme/maps/ugc/UGC$Rating;)V");
|
||||
// public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex)
|
||||
static jmethodID const featureCtorId =
|
||||
jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V");
|
||||
|
@ -135,7 +146,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
static_cast<jint>(bac.m_bookmarkIndex), jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(),
|
||||
jAddress.get(), jbanners.get(), jTaxiTypes.get(), jBookingSearchUrl.get(),
|
||||
localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), info.ShouldShowUGC(),
|
||||
info.CanBeRated(), info.CanBeReviewed());
|
||||
info.CanBeRated(), info.CanBeReviewed(), jratings.get());
|
||||
|
||||
if (info.IsFeature())
|
||||
InjectMetadata(env, g_mapObjectClazz, mapObject, info.GetMetadata());
|
||||
|
@ -153,7 +164,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
info.GetAddress(), {}, "", jbanners.get(), jTaxiTypes.get(),
|
||||
info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(),
|
||||
info.IsPreviewExtended(), info.ShouldShowUGC(), info.CanBeRated(),
|
||||
info.CanBeReviewed());
|
||||
info.CanBeReviewed(), jratings.get());
|
||||
}
|
||||
|
||||
if (info.HasApiUrl())
|
||||
|
@ -163,7 +174,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
kApiPoint, info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon,
|
||||
info.GetAddress(), info.GetMetadata(), info.GetApiUrl(), jbanners.get(), jTaxiTypes.get(),
|
||||
info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(),
|
||||
info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed());
|
||||
info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed(), jratings.get());
|
||||
}
|
||||
|
||||
return CreateMapObject(
|
||||
|
@ -171,7 +182,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon,
|
||||
info.GetAddress(), info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanners.get(),
|
||||
jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(),
|
||||
info.IsPreviewExtended(), info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed());
|
||||
info.IsPreviewExtended(), info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed(),
|
||||
jratings.get());
|
||||
}
|
||||
|
||||
jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners)
|
||||
|
@ -182,6 +194,17 @@ jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners)
|
|||
});
|
||||
}
|
||||
|
||||
jobjectArray ToRatingArray(JNIEnv * env, vector<std::string> const & ratingCategories)
|
||||
{
|
||||
if (ratingCategories.empty())
|
||||
return nullptr;
|
||||
|
||||
return jni::ToJavaArray(env, g_ratingClazz, ratingCategories,
|
||||
[](JNIEnv * env, std::string const & item) {
|
||||
return CreateRating(env, item);
|
||||
});
|
||||
}
|
||||
|
||||
jintArray ToReachableByTaxiProvidersArray(JNIEnv * env, vector<taxi::Provider::Type> const & types)
|
||||
{
|
||||
if (types.size() == 0)
|
||||
|
|
|
@ -32,6 +32,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info);
|
|||
|
||||
jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners);
|
||||
|
||||
jobjectArray ToRatingArray(JNIEnv * env, vector<std::string> const & ratingCategories);
|
||||
|
||||
jintArray ToReachableByTaxiProvidersArray(JNIEnv * env, vector<taxi::Provider::Type> const & types);
|
||||
|
||||
jobject CreateLocalAdInfo(JNIEnv * env, place_page::Info const & info);
|
||||
|
|
|
@ -136,7 +136,7 @@ private:
|
|||
jobjectArray ToJavaRatings(JNIEnv * env, std::vector<ugc::RatingRecord> const & ratings)
|
||||
{
|
||||
size_t const n = ratings.size();
|
||||
jobjectArray result = env->NewObjectArray(n, m_ratingClass, nullptr);
|
||||
jobjectArray result = env->NewObjectArray(n, g_ratingClazz, nullptr);
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
jni::TScopedLocalRef rating(env, ToJavaRating(env, ratings[i]));
|
||||
|
@ -160,7 +160,7 @@ private:
|
|||
jobject ToJavaRating(JNIEnv * env, ugc::RatingRecord const & ratingRecord)
|
||||
{
|
||||
jni::TScopedLocalRef name(env, jni::ToJavaString(env, ratingRecord.m_key.m_key));
|
||||
jobject result = env->NewObject(m_ratingClass, m_ratingCtor, name.get(), ratingRecord.m_value);
|
||||
jobject result = env->NewObject(g_ratingClazz, m_ratingCtor, name.get(), ratingRecord.m_value);
|
||||
ASSERT(result, ());
|
||||
return result;
|
||||
}
|
||||
|
@ -188,8 +188,7 @@ private:
|
|||
m_onResult = jni::GetStaticMethodID(env, m_ugcClass, "onUGCReceived",
|
||||
"(Lcom/mapswithme/maps/ugc/UGC;Lcom/mapswithme/maps/ugc/UGCUpdate;ILjava/lang/String;)V");
|
||||
|
||||
m_ratingClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Rating");
|
||||
m_ratingCtor = jni::GetConstructorID(env, m_ratingClass, "(Ljava/lang/String;F)V");
|
||||
m_ratingCtor = jni::GetConstructorID(env, g_ratingClazz, "(Ljava/lang/String;F)V");
|
||||
|
||||
m_reviewClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Review");
|
||||
m_reviewCtor =
|
||||
|
@ -201,8 +200,8 @@ private:
|
|||
m_ratingArrayFieldId = env->GetFieldID(m_ugcUpdateClass, "mRatings", "[Lcom/mapswithme/maps/ugc/UGC$Rating;");
|
||||
m_ratingTextFieldId = env->GetFieldID(m_ugcUpdateClass, "mText", "Ljava/lang/String;");
|
||||
m_updateTimeFieldId = env->GetFieldID(m_ugcUpdateClass, "mTimeMillis", "J");
|
||||
m_ratingNameFieldId = env->GetFieldID(m_ratingClass, "mName", "Ljava/lang/String;");
|
||||
m_ratingValueFieldId = env->GetFieldID(m_ratingClass, "mValue", "F");
|
||||
m_ratingNameFieldId = env->GetFieldID(g_ratingClazz, "mName", "Ljava/lang/String;");
|
||||
m_ratingValueFieldId = env->GetFieldID(g_ratingClazz, "mValue", "F");
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
@ -221,7 +220,6 @@ private:
|
|||
|
||||
jmethodID m_onResult;
|
||||
|
||||
jclass m_ratingClass;
|
||||
jmethodID m_ratingCtor;
|
||||
|
||||
jclass m_reviewClass;
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.mapswithme.maps.ads.Banner;
|
|||
import com.mapswithme.maps.ads.LocalAdInfo;
|
||||
import com.mapswithme.maps.routing.RoutePointInfo;
|
||||
import com.mapswithme.maps.taxi.TaxiManager;
|
||||
import com.mapswithme.maps.ugc.UGC;
|
||||
import com.mapswithme.util.Constants;
|
||||
|
||||
// TODO consider refactoring to remove hack with MapObject unmarshalling itself and Bookmark at the same time.
|
||||
|
@ -29,11 +30,12 @@ public class Bookmark extends MapObject
|
|||
@TaxiManager.TaxiType int[] reachableByTaxiTypes,
|
||||
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo,
|
||||
@Nullable RoutePointInfo routePointInfo, boolean isExtendedView,
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed)
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed,
|
||||
@Nullable UGC.Rating[] ratings)
|
||||
{
|
||||
super(featureId, BOOKMARK, title, secondaryTitle, subtitle, address, 0, 0, "",
|
||||
banners, reachableByTaxiTypes, bookingSearchUrl, localAdInfo, routePointInfo,
|
||||
isExtendedView, shouldShowUGC, canBeRated, canBeReviewed);
|
||||
isExtendedView, shouldShowUGC, canBeRated, canBeReviewed, ratings);
|
||||
|
||||
mCategoryId = categoryId;
|
||||
mBookmarkId = bookmarkId;
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.mapswithme.maps.ads.Banner;
|
|||
import com.mapswithme.maps.ads.LocalAdInfo;
|
||||
import com.mapswithme.maps.routing.RoutePointInfo;
|
||||
import com.mapswithme.maps.taxi.TaxiManager;
|
||||
import com.mapswithme.maps.ugc.UGC;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -60,6 +61,8 @@ public class MapObject implements Parcelable
|
|||
private boolean mShouldShowUGC;
|
||||
private boolean mCanBeRated;
|
||||
private boolean mCanBeReviewed;
|
||||
@Nullable
|
||||
private List<UGC.Rating> mRatings;
|
||||
|
||||
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title,
|
||||
@Nullable String secondaryTitle, String subtitle, String address,
|
||||
|
@ -67,12 +70,13 @@ public class MapObject implements Parcelable
|
|||
@Nullable Banner[] banners, @Nullable @TaxiManager.TaxiType int[] types,
|
||||
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo,
|
||||
@Nullable RoutePointInfo routePointInfo, boolean isExtendedView,
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed)
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed,
|
||||
@Nullable UGC.Rating[] ratings)
|
||||
{
|
||||
this(featureId, mapObjectType, title, secondaryTitle,
|
||||
subtitle, address, lat, lon, new Metadata(), apiId, banners,
|
||||
types, bookingSearchUrl, localAdInfo, routePointInfo, isExtendedView, shouldShowUGC,
|
||||
canBeRated, canBeReviewed);
|
||||
canBeRated, canBeReviewed, ratings);
|
||||
}
|
||||
|
||||
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType,
|
||||
|
@ -81,7 +85,8 @@ public class MapObject implements Parcelable
|
|||
String apiId, @Nullable Banner[] banners, @Nullable @TaxiManager.TaxiType int[] taxiTypes,
|
||||
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo,
|
||||
@Nullable RoutePointInfo routePointInfo, boolean isExtendedView,
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed)
|
||||
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed,
|
||||
@Nullable UGC.Rating[] ratings)
|
||||
{
|
||||
mFeatureId = featureId;
|
||||
mMapObjectType = mapObjectType;
|
||||
|
@ -105,9 +110,11 @@ public class MapObject implements Parcelable
|
|||
if (taxiTypes != null)
|
||||
{
|
||||
mReachableByTaxiTypes = new ArrayList<>();
|
||||
for (int type: taxiTypes)
|
||||
for (int type : taxiTypes)
|
||||
mReachableByTaxiTypes.add(type);
|
||||
}
|
||||
if (ratings != null)
|
||||
mRatings = new ArrayList<>(Arrays.asList(ratings));
|
||||
}
|
||||
|
||||
protected MapObject(@MapObjectType int type, Parcel source)
|
||||
|
@ -131,11 +138,12 @@ public class MapObject implements Parcelable
|
|||
source.readInt() == 1, // mExtendedView
|
||||
source.readInt() == 1, // mShouldShowUGC
|
||||
source.readInt() == 1, // mCanBeRated;
|
||||
source.readInt() == 1); // mCanBeReviewed
|
||||
source.readInt() == 1, // mCanBeReviewed
|
||||
null); // mRatings
|
||||
|
||||
mBanners = readBanners(source);
|
||||
mReachableByTaxiTypes = readTaxiTypes(source);
|
||||
|
||||
mRatings = readRatings(source);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -145,7 +153,8 @@ public class MapObject implements Parcelable
|
|||
return new MapObject(featureId, mapObjectType, title,
|
||||
"", subtitle, "", lat, lon, "", null,
|
||||
null, "", null, null, false /* isExtendedView */,
|
||||
false /* shouldShowUGC */, false /* canBeRated */, false /* canBeReviewed */);
|
||||
false /* shouldShowUGC */, false /* canBeRated */, false /* canBeReviewed */,
|
||||
null /* ratings */);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -156,6 +165,14 @@ public class MapObject implements Parcelable
|
|||
return banners.isEmpty() ? null : banners;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<UGC.Rating> readRatings(@NonNull Parcel source)
|
||||
{
|
||||
List<UGC.Rating> ratings = new ArrayList<>();
|
||||
source.readTypedList(ratings, UGC.Rating.CREATOR);;
|
||||
return ratings.isEmpty() ? null : ratings;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<Integer> readTaxiTypes(@NonNull Parcel source)
|
||||
{
|
||||
|
@ -364,6 +381,7 @@ public class MapObject implements Parcelable
|
|||
dest.writeInt(mCanBeRated ? 1 : 0);
|
||||
dest.writeTypedList(mBanners);
|
||||
dest.writeList(mReachableByTaxiTypes);
|
||||
dest.writeTypedList(mRatings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue