Skip to content

Commit

Permalink
[android] Unbound elevation logic from simple place page controller t…
Browse files Browse the repository at this point in the history
…o make it reusable for another bottom sheet (e.g. guides layer)
  • Loading branch information
alexzatsepin authored and devnullorthrow committed Apr 24, 2020
1 parent a83e089 commit eadfe70
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion android/src/com/mapswithme/maps/MwmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ protected void onSafeCreate(@Nullable Bundle savedInstanceState)

setContentView(R.layout.activity_map);

mPlacePageController = PlacePageFactory.createPlacePageController(this, this, this);
mPlacePageController = PlacePageFactory.createCompositePlacePageController(this, this, this);
mPlacePageController.initialize(this);
mPlacePageController.onActivityCreated(this, savedInstanceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onSlide(@NonNull View view, float v)
};

BottomSheetMenuController(int sheetResId, @NonNull MenuRenderer menuRenderer,
@Nullable MenuStateObserver stateObserver)
@Nullable MenuStateObserver stateObserver)
{
mSheetResId = sheetResId;
mMenuRenderer = menuRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,10 @@ public void onPlacePageClosed()
if (mElevationInfo != null)
Statistics.INSTANCE.trackElevationProfilePageClose(mElevationInfo.getServerId());
}

@Override
public boolean support(@NonNull PlacePageData data)
{
return data instanceof ElevationInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ public void initialize(@Nullable Activity activity)
throw new AssertionError("Place page controllers already initialized!");

PlacePageController richController =
createRichPlacePageController(mAdsProvider, mSlideListener, mRoutingModeListener);
PlacePageFactory.createRichPlacePageController(mAdsProvider, mSlideListener,
mRoutingModeListener);
richController.initialize(activity);
mControllers.add(richController);

PlacePageController simpleController =
createSimplePlacePageController(mSlideListener);
simpleController.initialize(activity);
mControllers.add(simpleController);
PlacePageController elevationProfileController =
PlacePageFactory.createElevationProfilePlacePageController(mSlideListener);
elevationProfileController.initialize(activity);
mControllers.add(elevationProfileController);

mActiveController = richController;
}
Expand All @@ -147,10 +148,10 @@ public void onSave(@NonNull Bundle outState)
@Override
public void onRestore(@NonNull Bundle inState)
{
PlacePageData userMark = inState.getParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA);
if (userMark != null)
PlacePageData data = inState.getParcelable(PlacePageUtils.EXTRA_PLACE_PAGE_DATA);
if (data != null)
{
PlacePageController controller = findControllerFor(userMark);
PlacePageController controller = findControllerFor(data);
if (controller != null)
mActiveController = controller;
}
Expand All @@ -174,21 +175,4 @@ public boolean support(@NonNull PlacePageData object)
{
return mActiveController.support(object);
}

@NonNull
private static PlacePageController createRichPlacePageController(
@NonNull AdsRemovalPurchaseControllerProvider provider,
@NonNull PlacePageController.SlideListener listener,
@Nullable RoutingModeListener routingModeListener)
{
return new RichPlacePageController(provider, listener, routingModeListener);
}

@NonNull
private static PlacePageController createSimplePlacePageController(
@NonNull PlacePageController.SlideListener listener)
{
ElevationProfileViewRenderer renderer = new ElevationProfileViewRenderer();
return new SimplePlacePageController(listener, renderer, renderer);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package com.mapswithme.maps.widget.placepage;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.R;
import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider;

public class PlacePageFactory
{
@NonNull
public static PlacePageController createPlacePageController(
public static PlacePageController createCompositePlacePageController(
@NonNull AdsRemovalPurchaseControllerProvider provider,
@NonNull PlacePageController.SlideListener slideListener,
@NonNull RoutingModeListener routingModeListener)
{
return new PlacePageControllerComposite(provider, slideListener, routingModeListener);
}

@NonNull
static PlacePageController createRichPlacePageController(
@NonNull AdsRemovalPurchaseControllerProvider provider,
@NonNull PlacePageController.SlideListener listener,
@Nullable RoutingModeListener routingModeListener)
{
return new RichPlacePageController(provider, listener, routingModeListener);
}

@NonNull
static PlacePageController createElevationProfilePlacePageController(
@NonNull PlacePageController.SlideListener listener)
{
ElevationProfileViewRenderer renderer = new ElevationProfileViewRenderer();
return new SimplePlacePageController(R.id.elevation_profile, renderer, renderer, listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ static void moveViewPortRight(@NonNull View bootomSheet, int viewportMinWidth)
static void setPullDrawable(@NonNull AnchorBottomSheetBehavior behavior, @NonNull View bottomSheet,
@IdRes int pullDrawableId)
{
final ImageView img = bottomSheet.findViewById(pullDrawableId);
if (img == null)
return;

@AnchorBottomSheetBehavior.State
int state = behavior.getState();
@DrawableRes
Expand All @@ -80,7 +84,6 @@ else if (PlacePageUtils.isAnchoredState(state) || PlacePageUtils.isExpandedState
if (drawableId == UiUtils.NO_ID)
return;

ImageView img = bottomSheet.findViewById(pullDrawableId);
Drawable drawable = Graphics.tint(bottomSheet.getContext(), drawableId,
R.attr.bannerButtonBackgroundColor);
img.setImageDrawable(drawable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import com.mapswithme.maps.base.Hideable;
import com.mapswithme.maps.base.Initializable;
import com.mapswithme.maps.base.Savable;
import com.mapswithme.maps.base.Supportable;

public interface PlacePageViewRenderer<Data> extends Initializable<View>, Savable<Bundle>,
Hideable
Hideable, Supportable<Data>
{
void render(@NonNull Data data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GestureDetectorCompat;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.ElevationInfo;
import com.mapswithme.util.UiUtils;
import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;

Expand Down Expand Up @@ -99,11 +99,14 @@ public void onSheetSlideFinish()
= new DefaultBottomSheetCallback(mBottomSheetChangedListener);

private boolean mDeactivateMapSelection = true;
@IdRes
private final int mSheetResId;

SimplePlacePageController(@NonNull SlideListener slideListener,
@NonNull PlacePageViewRenderer<PlacePageData> renderer,
@Nullable PlacePageStateObserver stateObserver)
SimplePlacePageController(int sheetResId, @NonNull PlacePageViewRenderer<PlacePageData> renderer,
@Nullable PlacePageStateObserver stateObserver,
@NonNull SlideListener slideListener)
{
mSheetResId = sheetResId;
mSlideListener = slideListener;
mViewRenderer = renderer;
mStateObserver = stateObserver;
Expand Down Expand Up @@ -181,7 +184,7 @@ public void initialize(@Nullable Activity activity)
{
Objects.requireNonNull(activity);
mApplication = activity.getApplication();
mSheet = activity.findViewById(R.id.elevation_profile);
mSheet = activity.findViewById(mSheetResId);
mViewportMinHeight = mSheet.getResources().getDimensionPixelSize(R.dimen.viewport_min_height);
mViewPortMinWidth = mSheet.getResources().getDimensionPixelSize(R.dimen.viewport_min_width);
mSheetBehavior = AnchorBottomSheetBehavior.from(mSheet);
Expand Down Expand Up @@ -250,7 +253,7 @@ private void onHiddenInternal()
@Override
public boolean support(@NonNull PlacePageData data)
{
return data instanceof ElevationInfo;
return mViewRenderer.support(data);
}

private static class SimplePlacePageGestureListener extends PlacePageGestureListener
Expand Down

0 comments on commit eadfe70

Please sign in to comment.