[android] Added user mark interface for java objects that can be activated on map, i.e. place page can be opened for that

This commit is contained in:
Александр Зацепин 2020-03-13 11:35:24 +03:00 committed by Daria Volvenkova
parent 59182b809e
commit 3b6e7d3ecd
11 changed files with 100 additions and 85 deletions

View file

@ -1020,22 +1020,22 @@ Java_com_mapswithme_maps_Framework_nativeSetMapObjectListener(JNIEnv * env, jcla
{
LOG(LINFO, ("Set global map object listener"));
g_mapObjectListener = env->NewGlobalRef(jListener);
// void onMapObjectActivated(MapObject object);
jmethodID const activatedId = jni::GetMethodID(env, g_mapObjectListener, "onMapObjectActivated",
"(Lcom/mapswithme/maps/bookmarks/data/MapObject;)V");
// void onDismiss(boolean switchFullScreenMode);
jmethodID const dismissId = jni::GetMethodID(env, g_mapObjectListener, "onDismiss", "(Z)V");
// void onUserMarkActivated(MapObject object);
jmethodID const activatedId = jni::GetMethodID(env, g_mapObjectListener, "onUserMarkActivated",
"(Lcom/mapswithme/maps/widget/placepage/UserMarkInterface;)V");
// void onUserMarkDeactivated(boolean switchFullScreenMode);
jmethodID const deactivateId = jni::GetMethodID(env, g_mapObjectListener, "onUserMarkDeactivated", "(Z)V");
auto const fillPlacePage = [activatedId]()
{
JNIEnv * env = jni::GetEnv();
auto const & info = frm()->GetCurrentPlacePageInfo();
jni::TScopedLocalRef mapObject(env, usermark_helper::CreateMapObject(env, info));
env->CallVoidMethod(g_mapObjectListener, activatedId, mapObject.get());
jni::TScopedLocalRef userMarkRef(env, usermark_helper::CreateMapObject(env, info));
env->CallVoidMethod(g_mapObjectListener, activatedId, userMarkRef.get());
};
auto const closePlacePage = [dismissId](bool switchFullScreenMode)
auto const closePlacePage = [deactivateId](bool switchFullScreenMode)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(g_mapObjectListener, dismissId, switchFullScreenMode);
env->CallVoidMethod(g_mapObjectListener, deactivateId, switchFullScreenMode);
};
frm()->SetPlacePageListeners(fillPlacePage, closePlacePage, fillPlacePage);
}

View file

@ -29,6 +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.util.Constants;
import com.mapswithme.util.KeyValue;
import com.mapswithme.util.log.Logger;
@ -113,11 +114,11 @@ public class Framework
public static final int SUBSCRIPTION_TYPE_BOOKMARK_CATALOG = 1;
@SuppressWarnings("unused")
public interface MapObjectListener
public interface UserMarkActivationListener
{
void onMapObjectActivated(MapObject object);
void onUserMarkActivated(@NonNull UserMarkInterface userMark);
void onDismiss(boolean switchFullScreenMode);
void onUserMarkDeactivated(boolean switchFullScreenMode);
}
@SuppressWarnings("unused")
@ -281,7 +282,7 @@ public class Framework
public static native String nativeGetAddress(double lat, double lon);
public static native void nativeSetMapObjectListener(MapObjectListener listener);
public static native void nativeSetMapObjectListener(UserMarkActivationListener listener);
public static native void nativeRemoveMapObjectListener();

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.MapObjectListener;
import com.mapswithme.maps.Framework.UserMarkActivationListener;
import com.mapswithme.maps.activity.CustomNavigateUpListener;
import com.mapswithme.maps.ads.LikesManager;
import com.mapswithme.maps.api.ParsedMwmRequest;
@ -126,6 +126,7 @@ import com.mapswithme.maps.widget.menu.MyPositionButton;
import com.mapswithme.maps.widget.placepage.PlacePageController;
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;
@ -149,32 +150,32 @@ import java.util.List;
import java.util.Stack;
public class MwmActivity extends BaseMwmFragmentActivity
implements MapObjectListener,
View.OnTouchListener,
OnClickListener,
MapRenderingListener,
CustomNavigateUpListener,
RoutingController.Container,
LocationHelper.UiCallback,
FloatingSearchToolbarController.VisibilityListener,
NativeSearchListener,
NavigationButtonsAnimationController.OnTranslationChangedListener,
RoutingPlanInplaceController.RoutingPlanListener,
RoutingBottomMenuListener,
BookmarkManager.BookmarksLoadingListener,
DiscoveryFragment.DiscoveryListener,
FloatingSearchToolbarController.SearchToolbarListener,
OnTrafficLayerToggleListener,
OnSubwayLayerToggleListener,
BookmarkManager.BookmarksCatalogListener,
AdsRemovalPurchaseControllerProvider,
AdsRemovalActivationCallback,
PlacePageController.SlideListener,
AlertDialogCallback, RoutingModeListener,
AppBackgroundTracker.OnTransitionListener,
MaterialTapTargetPrompt.PromptStateChangeListener,
WelcomeDialogFragment.OnboardingStepPassedListener,
OnIsolinesLayerToggleListener
implements UserMarkActivationListener,
View.OnTouchListener,
OnClickListener,
MapRenderingListener,
CustomNavigateUpListener,
RoutingController.Container,
LocationHelper.UiCallback,
FloatingSearchToolbarController.VisibilityListener,
NativeSearchListener,
NavigationButtonsAnimationController.OnTranslationChangedListener,
RoutingPlanInplaceController.RoutingPlanListener,
RoutingBottomMenuListener,
BookmarkManager.BookmarksLoadingListener,
DiscoveryFragment.DiscoveryListener,
FloatingSearchToolbarController.SearchToolbarListener,
OnTrafficLayerToggleListener,
OnSubwayLayerToggleListener,
BookmarkManager.BookmarksCatalogListener,
AdsRemovalPurchaseControllerProvider,
AdsRemovalActivationCallback,
PlacePageController.SlideListener,
AlertDialogCallback, RoutingModeListener,
AppBackgroundTracker.OnTransitionListener,
MaterialTapTargetPrompt.PromptStateChangeListener,
WelcomeDialogFragment.OnboardingStepPassedListener,
OnIsolinesLayerToggleListener
{
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = MwmActivity.class.getSimpleName();
@ -265,7 +266,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private final OnClickListener mOnMyPositionClickListener = new CurrentPositionClickListener();
@SuppressWarnings("NullableProblems")
@NonNull
private PlacePageController<MapObject> mPlacePageController;
private PlacePageController mPlacePageController;
@Nullable
private Tutorial mTutorial;
@Nullable
@ -1546,21 +1547,25 @@ public class MwmActivity extends BaseMwmFragmentActivity
// Called from JNI.
@Override
public void onMapObjectActivated(final MapObject object)
public void onUserMarkActivated(@NonNull UserMarkInterface userMark)
{
if (MapObject.isOfType(MapObject.API_POINT, object))
if (userMark instanceof MapObject)
{
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
if (request == null)
return;
MapObject object = (MapObject) userMark;
if (MapObject.isOfType(MapObject.API_POINT, object))
{
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
if (request == null)
return;
request.setPointData(object.getLat(), object.getLon(), object.getTitle(), object.getApiId());
object.setSubtitle(request.getCallerName(MwmApplication.get()).toString());
request.setPointData(object.getLat(), object.getLon(), object.getTitle(), object.getApiId());
object.setSubtitle(request.getCallerName(MwmApplication.get()).toString());
}
}
setFullscreen(false);
mPlacePageController.openFor(object);
mPlacePageController.openFor(userMark);
if (UiUtils.isVisible(mFadeView))
mFadeView.fadeOut();
@ -1568,7 +1573,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
// Called from JNI.
@Override
public void onDismiss(boolean switchFullScreenMode)
public void onUserMarkDeactivated(boolean switchFullScreenMode)
{
if (switchFullScreenMode)
{

View file

@ -1,6 +1,8 @@
package com.mapswithme.maps.base;
import androidx.annotation.NonNull;
public interface Supportable<T>
{
boolean support(T object);
boolean support(@NonNull T object);
}

View file

@ -2,11 +2,11 @@ package com.mapswithme.maps.bookmarks.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.ads.LocalAdInfo;
import com.mapswithme.maps.routing.RoutePointInfo;
@ -16,6 +16,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.util.sharing.ShareableInfoProvider;
import java.lang.annotation.Retention;
@ -26,7 +27,8 @@ 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 Parcelable, PopularityProvider, ShareableInfoProvider
public class MapObject implements Parcelable, PopularityProvider, ShareableInfoProvider,
UserMarkInterface
{
// Order must correspond indexer/map_object.hpp
public enum OsmProps

View file

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

View file

@ -11,7 +11,7 @@ import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider;
import java.util.ArrayList;
import java.util.List;
class PlacePageControllerComposite implements PlacePageController<MapObject>
class PlacePageControllerComposite implements PlacePageController
{
@NonNull
private final AdsRemovalPurchaseControllerProvider mAdsProvider;
@ -20,10 +20,10 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
@Nullable
private final RoutingModeListener mRoutingModeListener;
@NonNull
private final List<PlacePageController<MapObject>> mControllers = new ArrayList<>();
private final List<PlacePageController> mControllers = new ArrayList<>();
@SuppressWarnings("NullableProblems")
@NonNull
private PlacePageController<MapObject> mActiveController;
private PlacePageController mActiveController;
PlacePageControllerComposite(@NonNull AdsRemovalPurchaseControllerProvider adsProvider,
@NonNull SlideListener slideListener,
@ -35,7 +35,7 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
}
@Override
public void openFor(@NonNull MapObject object)
public void openFor(@NonNull UserMarkInterface object)
{
boolean support = mActiveController.support(object);
if (support)
@ -45,7 +45,7 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
}
mActiveController.close(false);
PlacePageController<MapObject> controller = findControllerFor(object);
PlacePageController controller = findControllerFor(object);
if (controller == null)
throw new UnsupportedOperationException("Map object '" + object + "' can't be opened " +
"by existing controllers");
@ -113,12 +113,12 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
if (!mControllers.isEmpty())
throw new AssertionError("Place page controllers already initialized!");
PlacePageController<MapObject> richController =
PlacePageController richController =
createRichPlacePageController(mAdsProvider, mSlideListener, mRoutingModeListener);
richController.initialize(activity);
mControllers.add(richController);
PlacePageController<MapObject> simpleController =
PlacePageController simpleController =
createSimplePlacePageController(mSlideListener);
simpleController.initialize(activity);
mControllers.add(simpleController);
@ -126,13 +126,14 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
mActiveController = richController;
}
@Override
public void destroy()
{
if (mControllers.isEmpty())
throw new AssertionError("Place page controllers already destroyed!");
for (PlacePageController<MapObject> controller: mControllers)
for (PlacePageController controller: mControllers)
controller.destroy();
mControllers.clear();
@ -150,7 +151,7 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
MapObject object = inState.getParcelable(PlacePageUtils.EXTRA_MAP_OBJECT);
if (object != null)
{
PlacePageController<MapObject> controller = findControllerFor(object);
PlacePageController controller = findControllerFor(object);
if (controller != null)
mActiveController = controller;
}
@ -158,9 +159,9 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
}
@Nullable
private PlacePageController<MapObject> findControllerFor(@NonNull MapObject object)
private PlacePageController findControllerFor(@NonNull UserMarkInterface object)
{
for (PlacePageController<MapObject> controller : mControllers)
for (PlacePageController controller : mControllers)
{
if (controller.support(object))
return controller;
@ -170,13 +171,13 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
}
@Override
public boolean support(MapObject object)
public boolean support(@NonNull UserMarkInterface object)
{
return mActiveController.support(object);
}
@NonNull
private static PlacePageController<MapObject> createRichPlacePageController(
private static PlacePageController createRichPlacePageController(
@NonNull AdsRemovalPurchaseControllerProvider provider,
@NonNull PlacePageController.SlideListener listener,
@Nullable RoutingModeListener routingModeListener)
@ -185,7 +186,7 @@ class PlacePageControllerComposite implements PlacePageController<MapObject>
}
@NonNull
private static PlacePageController<MapObject> createSimplePlacePageController(
private static PlacePageController createSimplePlacePageController(
@NonNull PlacePageController.SlideListener listener)
{
return new SimplePlacePageController(listener, new ElevationProfileViewRenderer());

View file

@ -1,15 +1,12 @@
package com.mapswithme.maps.widget.placepage;
import android.app.Activity;
import androidx.annotation.NonNull;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider;
public class PlacePageFactory
{
@NonNull
public static PlacePageController<MapObject> createPlacePageController(
public static PlacePageController createPlacePageController(
@NonNull AdsRemovalPurchaseControllerProvider provider,
@NonNull PlacePageController.SlideListener slideListener,
@NonNull RoutingModeListener routingModeListener)

View file

@ -36,7 +36,7 @@ import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;
import java.util.Objects;
public class RichPlacePageController implements PlacePageController<MapObject>, LocationListener,
public class RichPlacePageController implements PlacePageController, LocationListener,
View.OnLayoutChangeListener,
BannerController.BannerStateRequester,
BannerController.BannerStateListener,
@ -247,8 +247,9 @@ public class RichPlacePageController implements PlacePageController<MapObject>,
}
@Override
public void openFor(@NonNull MapObject object)
public void openFor(@NonNull UserMarkInterface data)
{
MapObject object = (MapObject) data;
mPlacePage.setMapObject(object, (policy, isSameObject) -> {
@AnchorBottomSheetBehavior.State
int state = mPlacePageBehavior.getState();
@ -566,9 +567,9 @@ public class RichPlacePageController implements PlacePageController<MapObject>,
}
@Override
public boolean support(MapObject object)
public boolean support(@NonNull UserMarkInterface object)
{
// TODO: only for tests.
return !object.getTitle().equals("Петровский Путевой Дворец");
return !((MapObject) object).getTitle().equals("Петровский Путевой Дворец");
}
}

View file

@ -18,7 +18,7 @@ import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;
import java.util.Objects;
public class SimplePlacePageController implements PlacePageController<MapObject>
public class SimplePlacePageController implements PlacePageController
{
@SuppressWarnings("NullableProblems")
@NonNull
@ -102,9 +102,9 @@ public class SimplePlacePageController implements PlacePageController<MapObject>
}
@Override
public void openFor(@NonNull MapObject object)
public void openFor(@NonNull UserMarkInterface object)
{
mMapObject = object;
mMapObject = (MapObject) object;
mViewRenderer.render(mMapObject);
if (mSheetBehavior.getSkipCollapsed())
mSheetBehavior.setState(AnchorBottomSheetBehavior.STATE_EXPANDED);
@ -244,10 +244,10 @@ public class SimplePlacePageController implements PlacePageController<MapObject>
}
@Override
public boolean support(MapObject object)
public boolean support(@NonNull UserMarkInterface object)
{
// TODO: only for tests.
return object.getTitle().equals("Петровский Путевой Дворец");
return ((MapObject) object).getTitle().equals("Петровский Путевой Дворец");
}
private static class SimplePlacePageGestureListener extends PlacePageGestureListener

View file

@ -0,0 +1,5 @@
package com.mapswithme.maps.widget.placepage;
public interface UserMarkInterface
{
}