[android] Renamed user mark activiation listener to place page activation listener and java interface about it

This commit is contained in:
Александр Зацепин 2020-03-16 17:08:45 +03:00 committed by Daria Volvenkova
parent 9f2a8183bf
commit 9fa326386c
12 changed files with 69 additions and 70 deletions

View file

@ -93,7 +93,7 @@ namespace
return g_framework->NativeFramework();
}
jobject g_userMarkActivationListener = nullptr;
jobject g_placePageActivationListener = nullptr;
int const kUndefinedTip = -1;
android::AndroidVulkanContextFactory * CastFactory(drape_ptr<dp::GraphicsContextFactory> const & f)
@ -1016,52 +1016,52 @@ Java_com_mapswithme_maps_Framework_nativeGetParsedSearchRequest(JNIEnv * env, jc
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeSetUserMarkActivationListener(JNIEnv *env, jclass clazz,
jobject jListener)
Java_com_mapswithme_maps_Framework_nativePlacePageActivationListener(JNIEnv *env, jclass clazz,
jobject jListener)
{
LOG(LINFO, ("Set global map object listener"));
g_userMarkActivationListener = env->NewGlobalRef(jListener);
// void onUserMarkActivated(MapObject object);
jmethodID const activatedId = jni::GetMethodID(env, g_userMarkActivationListener,
"onUserMarkActivated",
"(Lcom/mapswithme/maps/widget/placepage/UserMarkInterface;)V");
// void onUserMarkDeactivated(boolean switchFullScreenMode);
jmethodID const deactivateId = jni::GetMethodID(env, g_userMarkActivationListener,
"onUserMarkDeactivated", "(Z)V");
g_placePageActivationListener = env->NewGlobalRef(jListener);
// void onPlacePageActivated(MapObject object);
jmethodID const activatedId = jni::GetMethodID(env, g_placePageActivationListener,
"onPlacePageActivated",
"(Lcom/mapswithme/maps/widget/placepage/PlacePageData;)V");
// void onPlacePageDeactivated(boolean switchFullScreenMode);
jmethodID const deactivateId = jni::GetMethodID(env, g_placePageActivationListener,
"onPlacePageDeactivated", "(Z)V");
auto const fillPlacePage = [activatedId]()
{
JNIEnv * env = jni::GetEnv();
auto const & info = frm()->GetCurrentPlacePageInfo();
jni::TScopedLocalRef userMarkRef(env, nullptr);
jni::TScopedLocalRef placePageDataRef(env, nullptr);
if (info.IsTrack())
{
auto const elevationInfo = frm()->GetBookmarkManager().MakeElevationInfo(info.GetTrackId());
userMarkRef.reset(usermark_helper::CreateElevationInfo(env, elevationInfo));
placePageDataRef.reset(usermark_helper::CreateElevationInfo(env, elevationInfo));
}
else
{
userMarkRef.reset(usermark_helper::CreateMapObject(env, info));
placePageDataRef.reset(usermark_helper::CreateMapObject(env, info));
}
env->CallVoidMethod(g_userMarkActivationListener, activatedId, userMarkRef.get());
env->CallVoidMethod(g_placePageActivationListener, activatedId, placePageDataRef.get());
};
auto const closePlacePage = [deactivateId](bool switchFullScreenMode)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(g_userMarkActivationListener, deactivateId, switchFullScreenMode);
env->CallVoidMethod(g_placePageActivationListener, deactivateId, switchFullScreenMode);
};
frm()->SetPlacePageListeners(fillPlacePage, closePlacePage, fillPlacePage);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeRemoveUserMarkActivationListener(JNIEnv *env, jclass)
Java_com_mapswithme_maps_Framework_nativeRemovePlacePageActivationListener(JNIEnv *env, jclass)
{
if (g_userMarkActivationListener == nullptr)
if (g_placePageActivationListener == nullptr)
return;
frm()->SetPlacePageListeners({} /* onOpen */, {} /* onClose */, {} /* onUpdate */);
LOG(LINFO, ("Remove global map object listener"));
env->DeleteGlobalRef(g_userMarkActivationListener);
g_userMarkActivationListener = nullptr;
env->DeleteGlobalRef(g_placePageActivationListener);
g_placePageActivationListener = nullptr;
}
JNIEXPORT jstring JNICALL

View file

@ -29,7 +29,7 @@ import com.mapswithme.maps.routing.RoutingInfo;
import com.mapswithme.maps.routing.TransitRouteInfo;
import com.mapswithme.maps.search.FilterUtils;
import com.mapswithme.maps.settings.SettingsPrefsFragment;
import com.mapswithme.maps.widget.placepage.UserMarkInterface;
import com.mapswithme.maps.widget.placepage.PlacePageData;
import com.mapswithme.util.Constants;
import com.mapswithme.util.KeyValue;
import com.mapswithme.util.log.Logger;
@ -114,11 +114,11 @@ public class Framework
public static final int SUBSCRIPTION_TYPE_BOOKMARK_CATALOG = 1;
@SuppressWarnings("unused")
public interface UserMarkActivationListener
public interface PlacePageActivationListener
{
void onUserMarkActivated(@NonNull UserMarkInterface userMark);
void onPlacePageActivated(@NonNull PlacePageData data);
void onUserMarkDeactivated(boolean switchFullScreenMode);
void onPlacePageDeactivated(boolean switchFullScreenMode);
}
@SuppressWarnings("unused")
@ -282,9 +282,9 @@ public class Framework
public static native String nativeGetAddress(double lat, double lon);
public static native void nativeSetUserMarkActivationListener(@NonNull UserMarkActivationListener listener);
public static native void nativePlacePageActivationListener(@NonNull PlacePageActivationListener listener);
public static native void nativeRemoveUserMarkActivationListener();
public static native void nativeRemovePlacePageActivationListener();
@UiThread
public static native String nativeGetOutdatedCountriesString();

View file

@ -30,7 +30,7 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.mapswithme.maps.Framework.UserMarkActivationListener;
import com.mapswithme.maps.Framework.PlacePageActivationListener;
import com.mapswithme.maps.activity.CustomNavigateUpListener;
import com.mapswithme.maps.ads.LikesManager;
import com.mapswithme.maps.api.ParsedMwmRequest;
@ -124,9 +124,9 @@ import com.mapswithme.maps.widget.menu.BaseMenu;
import com.mapswithme.maps.widget.menu.MainMenu;
import com.mapswithme.maps.widget.menu.MyPositionButton;
import com.mapswithme.maps.widget.placepage.PlacePageController;
import com.mapswithme.maps.widget.placepage.PlacePageData;
import com.mapswithme.maps.widget.placepage.PlacePageFactory;
import com.mapswithme.maps.widget.placepage.RoutingModeListener;
import com.mapswithme.maps.widget.placepage.UserMarkInterface;
import com.mapswithme.util.Counters;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.NetworkPolicy;
@ -150,7 +150,7 @@ import java.util.List;
import java.util.Stack;
public class MwmActivity extends BaseMwmFragmentActivity
implements UserMarkActivationListener,
implements PlacePageActivationListener,
View.OnTouchListener,
OnClickListener,
MapRenderingListener,
@ -1402,7 +1402,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
protected void onStart()
{
super.onStart();
Framework.nativeSetUserMarkActivationListener(this);
Framework.nativePlacePageActivationListener(this);
BookmarkManager.INSTANCE.addLoadingListener(this);
BookmarkManager.INSTANCE.addCatalogListener(this);
RoutingController.get().attach(this);
@ -1416,7 +1416,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
protected void onStop()
{
super.onStop();
Framework.nativeRemoveUserMarkActivationListener();
Framework.nativeRemovePlacePageActivationListener();
BookmarkManager.INSTANCE.removeLoadingListener(this);
BookmarkManager.INSTANCE.removeCatalogListener(this);
LocationHelper.INSTANCE.detach(!isFinishing());
@ -1545,11 +1545,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
// Called from JNI.
@Override
public void onUserMarkActivated(@NonNull UserMarkInterface userMark)
public void onPlacePageActivated(@NonNull PlacePageData data)
{
if (userMark instanceof MapObject)
if (data instanceof MapObject)
{
MapObject object = (MapObject) userMark;
MapObject object = (MapObject) data;
if (MapObject.isOfType(MapObject.API_POINT, object))
{
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
@ -1563,7 +1563,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
setFullscreen(false);
mPlacePageController.openFor(userMark);
mPlacePageController.openFor(data);
if (UiUtils.isVisible(mFadeView))
mFadeView.fadeOut();
@ -1571,7 +1571,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
// Called from JNI.
@Override
public void onUserMarkDeactivated(boolean switchFullScreenMode)
public void onPlacePageDeactivated(boolean switchFullScreenMode)
{
if (switchFullScreenMode)
{

View file

@ -4,14 +4,14 @@ import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import com.mapswithme.maps.widget.placepage.UserMarkInterface;
import com.mapswithme.maps.widget.placepage.PlacePageData;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ElevationInfo implements UserMarkInterface
public class ElevationInfo implements PlacePageData
{
private final long mId;
@NonNull

View file

@ -15,7 +15,7 @@ import com.mapswithme.maps.search.PopularityProvider;
import com.mapswithme.maps.search.PriceFilterView;
import com.mapswithme.maps.taxi.TaxiType;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.maps.widget.placepage.UserMarkInterface;
import com.mapswithme.maps.widget.placepage.PlacePageData;
import com.mapswithme.util.sharing.ShareableInfoProvider;
import java.lang.annotation.Retention;
@ -27,7 +27,7 @@ import java.util.List;
// TODO(yunikkk): Refactor. Displayed information is different from edited information, and it's better to
// separate them. Simple getters from jni place_page::Info and osm::EditableFeature should be enough.
public class MapObject implements PopularityProvider, ShareableInfoProvider,
UserMarkInterface
PlacePageData
{
// Order must correspond indexer/map_object.hpp
public enum OsmProps

View file

@ -15,7 +15,7 @@ import com.mapswithme.maps.routing.RoutingController;
import java.util.Objects;
public class ElevationProfileViewRenderer implements PlacePageViewRenderer<UserMarkInterface>
public class ElevationProfileViewRenderer implements PlacePageViewRenderer<PlacePageData>
{
private static final int MAX_DIFFICULTY_LEVEL = 3;
@ -47,9 +47,9 @@ public class ElevationProfileViewRenderer implements PlacePageViewRenderer<UserM
@SuppressLint("SetTextI18n")
@Override
public void render(@NonNull UserMarkInterface userMark)
public void render(@NonNull PlacePageData data)
{
mElevationInfo = (ElevationInfo) userMark;
mElevationInfo = (ElevationInfo) data;
mChartController.setData(mElevationInfo);
Resources resources = mTitle.getResources();
String meters = " " + resources.getString(R.string.elevation_profile_m);
@ -99,13 +99,13 @@ public class ElevationProfileViewRenderer implements PlacePageViewRenderer<UserM
@Override
public void onSave(@NonNull Bundle outState)
{
outState.putParcelable(PlacePageUtils.EXTRA_USER_MARK, mElevationInfo);
outState.putParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA, mElevationInfo);
}
@Override
public void onRestore(@NonNull Bundle inState)
{
mElevationInfo = inState.getParcelable(PlacePageUtils.EXTRA_USER_MARK);
mElevationInfo = inState.getParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA);
if (mElevationInfo != null)
render(mElevationInfo);
}

View file

@ -12,9 +12,9 @@ import com.mapswithme.maps.base.Supportable;
public interface PlacePageController extends Initializable<Activity>,
Savable<Bundle>,
Application.ActivityLifecycleCallbacks,
Supportable<UserMarkInterface>
Supportable<PlacePageData>
{
void openFor(@NonNull UserMarkInterface object);
void openFor(@NonNull PlacePageData data);
void close(boolean deactivateMapSelection);
boolean isClosed();

View file

@ -5,7 +5,6 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider;
import java.util.ArrayList;
@ -35,22 +34,22 @@ class PlacePageControllerComposite implements PlacePageController
}
@Override
public void openFor(@NonNull UserMarkInterface object)
public void openFor(@NonNull PlacePageData data)
{
boolean support = mActiveController.support(object);
boolean support = mActiveController.support(data);
if (support)
{
mActiveController.openFor(object);
mActiveController.openFor(data);
return;
}
mActiveController.close(false);
PlacePageController controller = findControllerFor(object);
PlacePageController controller = findControllerFor(data);
if (controller == null)
throw new UnsupportedOperationException("Map object '" + object + "' can't be opened " +
throw new UnsupportedOperationException("Place page data '" + data + "' not supported " +
"by existing controllers");
mActiveController = controller;
mActiveController.openFor(object);
mActiveController.openFor(data);
}
@Override
@ -148,7 +147,7 @@ class PlacePageControllerComposite implements PlacePageController
@Override
public void onRestore(@NonNull Bundle inState)
{
UserMarkInterface userMark = inState.getParcelable(PlacePageUtils.EXTRA_USER_MARK);
PlacePageData userMark = inState.getParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA);
if (userMark != null)
{
PlacePageController controller = findControllerFor(userMark);
@ -159,7 +158,7 @@ class PlacePageControllerComposite implements PlacePageController
}
@Nullable
private PlacePageController findControllerFor(@NonNull UserMarkInterface object)
private PlacePageController findControllerFor(@NonNull PlacePageData object)
{
for (PlacePageController controller : mControllers)
{
@ -171,7 +170,7 @@ class PlacePageControllerComposite implements PlacePageController
}
@Override
public boolean support(@NonNull UserMarkInterface object)
public boolean support(@NonNull PlacePageData object)
{
return mActiveController.support(object);
}

View file

@ -2,6 +2,6 @@ package com.mapswithme.maps.widget.placepage;
import android.os.Parcelable;
public interface UserMarkInterface extends Parcelable
public interface PlacePageData extends Parcelable
{
}

View file

@ -17,7 +17,7 @@ import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;
class PlacePageUtils
{
static final String EXTRA_USER_MARK = "extra_user_mark";
static final String EXTRA_PLACE_PAGE_DATA = "extra_place_page_data";
static void moveViewportUp(@NonNull View placePageView, int viewportMinHeight)
{

View file

@ -247,7 +247,7 @@ public class RichPlacePageController implements PlacePageController, LocationLis
}
@Override
public void openFor(@NonNull UserMarkInterface data)
public void openFor(@NonNull PlacePageData data)
{
MapObject object = (MapObject) data;
mPlacePage.setMapObject(object, (policy, isSameObject) -> {
@ -448,7 +448,7 @@ public class RichPlacePageController implements PlacePageController, LocationLis
public void onSave(@NonNull Bundle outState)
{
mPlacePageTracker.onSave(outState);
outState.putParcelable(PlacePageUtils.EXTRA_USER_MARK, mPlacePage.getMapObject());
outState.putParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA, mPlacePage.getMapObject());
}
@Override
@ -464,7 +464,7 @@ public class RichPlacePageController implements PlacePageController, LocationLis
return;
}
MapObject object = inState.getParcelable(PlacePageUtils.EXTRA_USER_MARK);
MapObject object = inState.getParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA);
if (object == null)
return;
@ -567,8 +567,8 @@ public class RichPlacePageController implements PlacePageController, LocationLis
}
@Override
public boolean support(@NonNull UserMarkInterface userMark)
public boolean support(@NonNull PlacePageData data)
{
return userMark instanceof MapObject;
return data instanceof MapObject;
}
}

View file

@ -34,7 +34,7 @@ public class SimplePlacePageController implements PlacePageController
private int mViewportMinHeight;
private int mViewPortMinWidth;
@NonNull
private final PlacePageViewRenderer<UserMarkInterface> mViewRenderer;
private final PlacePageViewRenderer<PlacePageData> mViewRenderer;
@NonNull
private final BottomSheetChangedListener mBottomSheetChangedListener =
new BottomSheetChangedListener()
@ -93,16 +93,16 @@ public class SimplePlacePageController implements PlacePageController
private boolean mDeactivateMapSelection = true;
SimplePlacePageController(@NonNull SlideListener slideListener,
@NonNull PlacePageViewRenderer<UserMarkInterface> renderer)
@NonNull PlacePageViewRenderer<PlacePageData> renderer)
{
mSlideListener = slideListener;
mViewRenderer = renderer;
}
@Override
public void openFor(@NonNull UserMarkInterface userMark)
public void openFor(@NonNull PlacePageData data)
{
mViewRenderer.render(userMark);
mViewRenderer.render(data);
if (mSheetBehavior.getSkipCollapsed())
mSheetBehavior.setState(AnchorBottomSheetBehavior.STATE_EXPANDED);
else
@ -236,9 +236,9 @@ public class SimplePlacePageController implements PlacePageController
}
@Override
public boolean support(@NonNull UserMarkInterface object)
public boolean support(@NonNull PlacePageData data)
{
return object instanceof ElevationInfo;
return data instanceof ElevationInfo;
}
private static class SimplePlacePageGestureListener extends PlacePageGestureListener