[android] Place page preview state based on bottom sheet

This commit is contained in:
Александр Зацепин 2019-01-24 13:18:45 +03:00 committed by yoksnod
parent da67f46423
commit 34f1ffd2c6
5 changed files with 98 additions and 37 deletions

View file

@ -9,6 +9,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<include
android:id="@+id/pp__preview"

View file

@ -179,6 +179,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half_plus"
android:layout_marginBottom="@dimen/margin_half_plus"
android:layout_marginStart="@dimen/margin_base"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginEnd="@dimen/margin_base"

View file

@ -146,8 +146,11 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
UGC.setListener(this);
}
public void clear()
public void clearViewsFor(@NonNull MapObject mapObject)
{
if (mapObject.shouldShowUGC())
return;
UiUtils.hide(mUgcRootView, mLeaveReviewButton, mPreviewUgcInfoView);
mUGCReviewAdapter.setItems(new ArrayList<UGC.Review>());
mUGCRatingRecordsAdapter.setItems(new ArrayList<UGC.Rating>());

View file

@ -15,11 +15,16 @@ import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationListener;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.PlacePageTracker;
public class BottomSheetPlacePageController implements PlacePageController, LocationListener
public class BottomSheetPlacePageController implements PlacePageController, LocationListener,
View.OnLayoutChangeListener
{
private static final int BUTTONS_ANIMATION_DURATION = 100;
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = BottomSheetPlacePageController.class.getSimpleName();
@NonNull
private final Activity mActivity;
@SuppressWarnings("NullableProblems")
@ -33,9 +38,6 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
private PlacePageView mPlacePage;
@SuppressWarnings("NullableProblems")
@NonNull
private ViewGroup mButtons;
@SuppressWarnings("NullableProblems")
@NonNull
private PlacePageTracker mPlacePageTracker;
@NonNull
private final BottomSheetBehavior.BottomSheetCallback mSheetCallback
@ -45,6 +47,8 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState)
{
LOGGER.d(TAG, "State changed, new state = "
+ BottomSheetPlacePageController.toString(newState));
if (newState == BottomSheetBehavior.STATE_SETTLING
|| newState == BottomSheetBehavior.STATE_DRAGGING)
return;
@ -61,10 +65,12 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset)
{
// TODO: coming soon.
LOGGER.v(TAG, "Sliding: " + slideOffset);
}
};
private int mLastPeekHeight;
public BottomSheetPlacePageController(@NonNull Activity activity)
{
mActivity = activity;
@ -78,10 +84,11 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mPpSheetBehavior.setBottomSheetCallback(mSheetCallback);
mPlacePage = ppSheet.findViewById(R.id.placepage);
mPlacePage.addOnLayoutChangeListener(this);
mButtonsLayout = mActivity.findViewById(R.id.pp_buttons_layout);
mButtons = mButtonsLayout.findViewById(R.id.pp_buttons);
mPlacePage.initButtons(mButtons.findViewById(R.id.container));
mPlacePageTracker = new PlacePageTracker(mPlacePage, mButtons);
ViewGroup buttons = mButtonsLayout.findViewById(R.id.pp_buttons);
mPlacePage.initButtons(buttons.findViewById(R.id.container));
mPlacePageTracker = new PlacePageTracker(mPlacePage, buttons);
LocationHelper.INSTANCE.addListener(this);
}
@ -94,12 +101,26 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public void openFor(@NonNull MapObject object)
{
mPlacePage.setMapObject(object, true, () -> {
mPpSheetBehavior.setState(object.isExtendedView() ? BottomSheetBehavior.STATE_EXPANDED
: BottomSheetBehavior.STATE_COLLAPSED);
Framework.logLocalAdsEvent(Framework.LocalAdsEventType.LOCAL_ADS_EVENT_OPEN_INFO, object);
mPlacePage.setMapObject(object, false, () -> {
if (object.isExtendedView())
{
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
return;
}
int peekHeight = mPlacePage.getPreviewHeight() + mButtonsLayout.getHeight();
LOGGER.d(TAG, "Initial peek height = " + peekHeight + " for " + object.getFeatureId());
openBottomSheet(peekHeight);
});
mPlacePageTracker.setMapObject(object);
Framework.logLocalAdsEvent(Framework.LocalAdsEventType.LOCAL_ADS_EVENT_OPEN_INFO, object);
}
private void openBottomSheet(int peekHeight)
{
mLastPeekHeight = peekHeight;
mPpSheetBehavior.setPeekHeight(mLastPeekHeight);
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
@Override
@ -167,4 +188,38 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
{
// Do nothing by default.
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int
oldTop, int oldRight, int oldBottom)
{
LOGGER.d(TAG, "Layout changed, current state = " + toString(mPpSheetBehavior.getState()));
if (mPpSheetBehavior.getState() != BottomSheetBehavior.STATE_COLLAPSED)
return;
int peekHeight = mPlacePage.getPreviewHeight() + mButtonsLayout.getHeight();
LOGGER.d(TAG, "New peek height = " + peekHeight);
if (peekHeight != mLastPeekHeight)
openBottomSheet(peekHeight);
}
@NonNull
private static String toString(@BottomSheetBehavior.State int state)
{
switch (state)
{
case BottomSheetBehavior.STATE_EXPANDED:
return "EXPANDED";
case BottomSheetBehavior.STATE_COLLAPSED:
return "COLLAPSED";
case BottomSheetBehavior.STATE_DRAGGING:
return "DRAGGING";
case BottomSheetBehavior.STATE_SETTLING:
return "SETTLING";
case BottomSheetBehavior.STATE_HIDDEN:
return "HIDDEN";
default:
throw new AssertionError("Unsupported state detected: " + state);
}
}
}

View file

@ -215,8 +215,8 @@ public class PlacePageView extends RelativeLayout
@NonNull
private View mPopularityView;
@Nullable
UGCController mUgcController;
@NonNull
private UGCController mUgcController;
@Nullable
BannerController mBannerController;
@ -775,7 +775,7 @@ public class PlacePageView extends RelativeLayout
mSponsoredPrice = getContext().getString(R.string.place_page_starting_from, text);
if (mMapObject == null)
{
LOGGER.e(TAG, "A sponsored info cannot be updated, mMapObject is null!", new Throwable());
LOGGER.e(TAG, "A sponsored info cannot be updated, mMapObject is null!");
return;
}
refreshPreview(mMapObject, NetworkPolicy.newInstance(true), priceInfo);
@ -879,12 +879,6 @@ public class PlacePageView extends RelativeLayout
mTvSponsoredPrice.setText("");
}
private void clearUGCViews()
{
if (mUgcController != null)
mUgcController.clear();
}
@Override
public void onLineCountCalculated(boolean grater)
{
@ -1007,7 +1001,7 @@ public class PlacePageView extends RelativeLayout
if (mMapObject == null)
{
// FIXME query map object again
LOGGER.e(TAG, "A place page cannot be restored, mMapObject is null!", new Throwable());
LOGGER.e(TAG, "A place page cannot be restored, mMapObject is null!");
return;
}
@ -1087,11 +1081,10 @@ public class PlacePageView extends RelativeLayout
if (mMapObject != null)
{
clearHotelViews();
clearUGCViews();
processSponsored(policy);
initEditMapObjectBtn();
if (mUgcController != null)
mUgcController.getUGC(mMapObject);
mUgcController.clearViewsFor(mMapObject);
mUgcController.getUGC(mMapObject);
String country = MapManager.nativeGetSelectedCountry();
if (country != null && !RoutingController.get().isNavigating())
@ -1130,7 +1123,7 @@ public class PlacePageView extends RelativeLayout
{
if (mMapObject == null)
{
LOGGER.e(TAG, "A place page views cannot be refreshed, mMapObject is null", new Throwable());
LOGGER.e(TAG, "A place page views cannot be refreshed, mMapObject is null");
return;
}
@ -1142,7 +1135,7 @@ public class PlacePageView extends RelativeLayout
{
if (mMapObject == null)
{
LOGGER.e(TAG, "A place page views cannot be refreshed, mMapObject is null", new Throwable());
LOGGER.e(TAG, "A place page views cannot be refreshed, mMapObject is null");
return;
}
@ -1233,13 +1226,14 @@ public class PlacePageView extends RelativeLayout
UiUtils.hide(mAvDirection);
UiUtils.setTextAndHideIfEmpty(mTvAddress, mapObject.getAddress());
boolean sponsored = isSponsored();
UiUtils.showIf(sponsored, mPreviewRatingInfo, mHotelDiscount);
UiUtils.showIf(sponsored || mapObject.shouldShowUGC(), mPreviewRatingInfo);
UiUtils.showIf(sponsored, mHotelDiscount);
UiUtils.showIf(mapObject.getHotelType() != null, mPreview, R.id.search_hotels_btn);
if (sponsored)
refreshSponsoredViews(priceInfo);
refreshSponsoredViews(mapObject, priceInfo);
}
private void refreshSponsoredViews(@Nullable HotelPriceInfo priceInfo)
private void refreshSponsoredViews(@NonNull MapObject mapObject, @Nullable HotelPriceInfo priceInfo)
{
boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice);
@SuppressWarnings("ConstantConditions")
@ -1251,7 +1245,7 @@ public class PlacePageView extends RelativeLayout
UiUtils.showIf(!isPriceEmpty && ConnectionState.isConnected(), mTvSponsoredPrice);
boolean isBookingInfoExist = (!isRatingEmpty || !isPriceEmpty) &&
mSponsored.getType() == Sponsored.TYPE_BOOKING;
UiUtils.showIf(isBookingInfoExist, mPreviewRatingInfo);
UiUtils.showIf(isBookingInfoExist || mapObject.shouldShowUGC(), mPreviewRatingInfo);
String discount = getHotelDiscount(priceInfo);
UiUtils.hideIf(TextUtils.isEmpty(discount), mHotelDiscount);
mHotelDiscount.setRating(Impress.DISCOUNT, discount);
@ -1567,7 +1561,7 @@ public class PlacePageView extends RelativeLayout
{
if (mMapObject == null)
{
LOGGER.e(TAG, "A location cannot be refreshed, mMapObject is null!", new Throwable());
LOGGER.e(TAG, "A location cannot be refreshed, mMapObject is null!");
return;
}
@ -1732,7 +1726,7 @@ public class PlacePageView extends RelativeLayout
// TODO: Refactor and use separate getters for Wiki and all other PP meta info too.
if (mMapObject == null)
{
LOGGER.e(TAG, "Cannot follow url, mMapObject is null!", new Throwable());
LOGGER.e(TAG, "Cannot follow url, mMapObject is null!");
break;
}
Utils.openUrl(getContext(), mMapObject.getMetadata(Metadata.MetadataType.FMD_WIKIPEDIA));
@ -1906,6 +1900,7 @@ public class PlacePageView extends RelativeLayout
public void hide()
{
mDetails.scrollTo(0, 0);
detachCountry();
}
@ -2013,10 +2008,10 @@ public class PlacePageView extends RelativeLayout
return mBannerController != null && mBannerController.isActionButtonTouched(event);
}
public boolean isLeaveReviewButtonTouched(@NonNull MotionEvent event)
/* public boolean isLeaveReviewButtonTouched(@NonNull MotionEvent event)
{
return mUgcController != null && mUgcController.isLeaveReviewButtonTouched(event);
}
}*/
public boolean isSearchSimilarHotelsButtonTouched(@NonNull MotionEvent event)
{
@ -2033,6 +2028,12 @@ public class PlacePageView extends RelativeLayout
}*/
}
int getPreviewHeight()
{
return mPreview.getHeight();
}
private class EditBookmarkClickListener implements OnClickListener
{
@Override
@ -2040,7 +2041,7 @@ public class PlacePageView extends RelativeLayout
{
if (mMapObject == null)
{
LOGGER.e(TAG, "A bookmark cannot be edited, mMapObject is null!", new Throwable());
LOGGER.e(TAG, "A bookmark cannot be edited, mMapObject is null!");
return;
}
Bookmark bookmark = (Bookmark) mMapObject;