forked from organicmaps/organicmaps
[android] Added touch slop to improve ux if pp is short
[android] Added banner details requester to open banner in right state if pp already opened
This commit is contained in:
parent
acf289e3de
commit
664f9b3365
3 changed files with 60 additions and 33 deletions
|
@ -189,6 +189,7 @@
|
|||
<dimen name="placepage_banner_button_margin_top">5dp</dimen>
|
||||
<dimen name="placepage_banner_small_action_corner">20dp</dimen>
|
||||
<dimen name="placepage_banner_remove_button_size">14dp</dimen>
|
||||
<dimen name="placepage_banner_open_touch_slop">50dp</dimen>
|
||||
<dimen name="megafon_button_min_height">28dp</dimen>
|
||||
<dimen name="megafon_button_corner_radius">@dimen/megafon_button_min_height</dimen>
|
||||
|
||||
|
|
|
@ -115,10 +115,13 @@ final class BannerController
|
|||
private final AdsRemovalPurchaseControllerProvider mAdsRemovalProvider;
|
||||
private int mClosedHeight;
|
||||
private int mOpentHeight;
|
||||
@NonNull
|
||||
private final BannerDetailsRequester mBannerDetailsRequester;
|
||||
|
||||
BannerController(@NonNull ViewGroup bannerContainer, @NonNull CompoundNativeAdLoader loader,
|
||||
@Nullable AdTracker tracker,
|
||||
@NonNull AdsRemovalPurchaseControllerProvider adsRemovalProvider)
|
||||
@NonNull AdsRemovalPurchaseControllerProvider adsRemovalProvider,
|
||||
@NonNull BannerDetailsRequester bannerDetailsRequester)
|
||||
{
|
||||
LOGGER.d(TAG, "Constructor()");
|
||||
mContainerView = bannerContainer;
|
||||
|
@ -130,6 +133,7 @@ final class BannerController
|
|||
mClosedHeight = resources.getDimensionPixelSize(R.dimen.placepage_banner_small_height);
|
||||
mOpentHeight = resources.getDimensionPixelSize(R.dimen.placepage_banner_large_height);
|
||||
mAdsRemovalProvider = adsRemovalProvider;
|
||||
mBannerDetailsRequester = bannerDetailsRequester;
|
||||
initBannerViews();
|
||||
}
|
||||
|
||||
|
@ -341,26 +345,6 @@ final class BannerController
|
|||
mActionLarge.setText(data.getAction());
|
||||
}
|
||||
|
||||
private void loadIconAndOpenIfNeeded(@NonNull MwmNativeAd data)
|
||||
{
|
||||
if (UiUtils.isLandscape(mContainerView.getContext()))
|
||||
{
|
||||
if (!mOpened)
|
||||
open();
|
||||
else
|
||||
loadIcon(data);
|
||||
}
|
||||
else if (!mOpened)
|
||||
{
|
||||
close();
|
||||
Statistics.INSTANCE.trackPPBanner(PP_BANNER_SHOW, data, PP_BANNER_STATE_PREVIEW);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadIcon(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateActionButton()
|
||||
{
|
||||
View view = mOpened ? mActionLarge : mActionSmall;
|
||||
|
@ -384,16 +368,28 @@ final class BannerController
|
|||
animator.start();
|
||||
}
|
||||
|
||||
boolean isOpened()
|
||||
{
|
||||
return mOpened;
|
||||
}
|
||||
|
||||
boolean hasAd()
|
||||
{
|
||||
return mCurrentAd != null;
|
||||
}
|
||||
|
||||
private void setBannerState()
|
||||
{
|
||||
if (mCurrentAd == null)
|
||||
throw new AssertionError("Current ad must be non-null at this point!");
|
||||
|
||||
if (mBannerDetailsRequester.shouldShowBannerDetails())
|
||||
{
|
||||
open();
|
||||
loadIcon(mCurrentAd);
|
||||
}
|
||||
else
|
||||
{
|
||||
close();
|
||||
Statistics.INSTANCE.trackPPBanner(PP_BANNER_SHOW, mCurrentAd, PP_BANNER_STATE_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
private class MyNativeAdsListener implements NativeAdListener
|
||||
{
|
||||
@Nullable
|
||||
|
@ -418,9 +414,8 @@ final class BannerController
|
|||
mLastAdType = mCurrentAd.getType();
|
||||
|
||||
fillViews(ad);
|
||||
loadIconAndOpenIfNeeded(ad);
|
||||
setBannerState();
|
||||
updateVisibility();
|
||||
|
||||
ad.registerView(mBannerView);
|
||||
|
||||
if (mAdTracker != null)
|
||||
|
@ -450,4 +445,9 @@ final class BannerController
|
|||
mOpened ? PP_BANNER_STATE_DETAILS : PP_BANNER_STATE_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
interface BannerDetailsRequester
|
||||
{
|
||||
boolean shouldShowBannerDetails();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.widget.placepage;
|
|||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
|
@ -28,7 +29,8 @@ import com.mapswithme.util.statistics.PlacePageTracker;
|
|||
import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;
|
||||
|
||||
public class BottomSheetPlacePageController implements PlacePageController, LocationListener,
|
||||
View.OnLayoutChangeListener
|
||||
View.OnLayoutChangeListener,
|
||||
BannerController.BannerDetailsRequester
|
||||
{
|
||||
private static final float ANCHOR_RATIO = 0.3f;
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
|
@ -55,6 +57,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
|
|||
private int mViewportMinHeight;
|
||||
private int mCurrentTop;
|
||||
private boolean mPeekHeightAnimating;
|
||||
private int mOpenBannerTouchSlop;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BannerController mBannerController;
|
||||
|
@ -136,8 +139,10 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
|
|||
{
|
||||
View coordinatorLayout = (ViewGroup) mPlacePage.getParent();
|
||||
int height = coordinatorLayout.getHeight();
|
||||
return mPlacePage.getHeight() > height * (1 - ANCHOR_RATIO)
|
||||
? (int) (height * ANCHOR_RATIO) : height - mPlacePage.getHeight();
|
||||
int maxY = mPlacePage.getHeight() > height * (1 - ANCHOR_RATIO)
|
||||
? (int) (height * ANCHOR_RATIO) : height - mPlacePage.getHeight();
|
||||
Resources res = mActivity.getResources();
|
||||
return maxY + mOpenBannerTouchSlop;
|
||||
}
|
||||
|
||||
private int calculateBannerMinY()
|
||||
|
@ -157,7 +162,9 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
|
|||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
mViewportMinHeight = mActivity.getResources().getDimensionPixelSize(R.dimen.viewport_min_height);
|
||||
Resources res = mActivity.getResources();
|
||||
mViewportMinHeight = res.getDimensionPixelSize(R.dimen.viewport_min_height);
|
||||
mOpenBannerTouchSlop = res.getDimensionPixelSize(R.dimen.placepage_banner_open_touch_slop);
|
||||
mToolbar = mActivity.findViewById(R.id.pp_toolbar);
|
||||
UiUtils.extendViewWithStatusBar(mToolbar);
|
||||
UiUtils.showHomeUpButton(mToolbar);
|
||||
|
@ -170,7 +177,8 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
|
|||
ViewGroup bannerContainer = mPlacePage.findViewById(R.id.banner_container);
|
||||
DefaultAdTracker tracker = new DefaultAdTracker();
|
||||
CompoundNativeAdLoader loader = com.mapswithme.maps.ads.Factory.createCompoundLoader(tracker, tracker);
|
||||
mBannerController = new BannerController(bannerContainer, loader, tracker, mPurchaseControllerProvider);
|
||||
mBannerController = new BannerController(bannerContainer, loader, tracker,
|
||||
mPurchaseControllerProvider, this);
|
||||
|
||||
mButtonsLayout = mActivity.findViewById(R.id.pp_buttons_layout);
|
||||
ViewGroup buttons = mButtonsLayout.findViewById(R.id.container);
|
||||
|
@ -470,4 +478,22 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
|
|||
{
|
||||
return state == AnchorBottomSheetBehavior.STATE_COLLAPSED;
|
||||
}
|
||||
|
||||
private static boolean isAnchoredState(@AnchorBottomSheetBehavior.State int state)
|
||||
{
|
||||
return state == AnchorBottomSheetBehavior.STATE_ANCHORED;
|
||||
}
|
||||
|
||||
private static boolean isExpandedState(@AnchorBottomSheetBehavior.State int state)
|
||||
{
|
||||
return state == AnchorBottomSheetBehavior.STATE_EXPANDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldShowBannerDetails()
|
||||
{
|
||||
@AnchorBottomSheetBehavior.State
|
||||
int state = mPlacePageBehavior.getState();
|
||||
return isAnchoredState(state) || isExpandedState(state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue