[android] Removed redundant layouts from placepage hiearachy to improve ui performance and make layout xml cleaner

This commit is contained in:
Александр Зацепин 2019-01-25 20:52:40 +03:00 committed by yoksnod
parent 1d71dcbcbe
commit b52f18ea95
4 changed files with 89 additions and 99 deletions

View file

@ -74,27 +74,25 @@
android:layout_height="@dimen/height_block_base"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/pp_bottom_sheet"
<com.mapswithme.maps.widget.placepage.PlacePageView
android:id="@+id/placepage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
app:behavior_hideable="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<com.mapswithme.maps.widget.placepage.PlacePageView
android:id="@+id/placepage"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
app:layout_behavior="@string/bottom_sheet_behavior"/>
<FrameLayout
android:id="@+id/pp_buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="invisible">
<include
android:id="@+id/pp_buttons"
layout="@layout/place_page_button_frame"
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="@dimen/place_page_buttons_height"
android:orientation="horizontal"
android:background="?ppButtonsBackground"/>
<include layout="@layout/divider_horizontal"/>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -1,34 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.NestedScrollView
android:id="@+id/pp__details"
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<include
android:id="@+id/pp__preview"
layout="@layout/place_page_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
android:id="@+id/pp__details_frame"
layout="@layout/place_page_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<include
android:id="@+id/pp__preview"
layout="@layout/place_page_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
android:id="@+id/pp__details_frame"
layout="@layout/place_page_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?panel"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<include
android:id="@+id/toolbar_layout"
layout="@layout/toolbar_elevated"
android:visibility="gone"/>
android:background="?panel"/>
</LinearLayout>
</merge>

View file

@ -16,6 +16,7 @@ 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.Utils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.PlacePageTracker;
@ -30,7 +31,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
private final Activity mActivity;
@SuppressWarnings("NullableProblems")
@NonNull
private BottomSheetBehavior<View> mPpSheetBehavior;
private BottomSheetBehavior<View> mPlacePageBehavior;
@SuppressWarnings("NullableProblems")
@NonNull
private View mButtonsLayout;
@ -49,7 +50,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
public void onStateChanged(@NonNull View bottomSheet, int newState)
{
LOGGER.d(TAG, "State change, new = " + BottomSheetPlacePageController.toString(newState)
+ " sheet height = " + mPpSheet.getHeight());
+ " placepage height = " + mPlacePage.getHeight());
if (newState == BottomSheetBehavior.STATE_SETTLING
|| newState == BottomSheetBehavior.STATE_DRAGGING)
return;
@ -71,9 +72,6 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
};
private int mLastPeekHeight;
@SuppressWarnings("NullableProblems")
@NonNull
private View mPpSheet;
private int mViewportMinHeight;
public BottomSheetPlacePageController(@NonNull Activity activity)
@ -85,19 +83,27 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
public void initialize()
{
mViewportMinHeight = mActivity.getResources().getDimensionPixelSize(R.dimen.viewport_min_height);
mPpSheet = mActivity.findViewById(R.id.pp_bottom_sheet);
mPpSheetBehavior = BottomSheetBehavior.from(mPpSheet);
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mPpSheetBehavior.setBottomSheetCallback(mSheetCallback);
mPlacePage = mPpSheet.findViewById(R.id.placepage);
mPlacePage = mActivity.findViewById(R.id.placepage);
mPlacePageBehavior = BottomSheetBehavior.from(mPlacePage);
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mPlacePageBehavior.setBottomSheetCallback(mSheetCallback);
mPlacePage.addOnLayoutChangeListener(this);
mButtonsLayout = mActivity.findViewById(R.id.pp_buttons_layout);
ViewGroup buttons = mButtonsLayout.findViewById(R.id.pp_buttons);
mPlacePage.initButtons(buttons.findViewById(R.id.container));
bringButtonsToFront();
ViewGroup buttons = mButtonsLayout.findViewById(R.id.container);
mPlacePage.initButtons(buttons);
mPlacePageTracker = new PlacePageTracker(mPlacePage, buttons);
LocationHelper.INSTANCE.addListener(this);
}
private void bringButtonsToFront()
{
if (Utils.isLollipopOrLater())
mButtonsLayout.setZ(mPlacePage.getZ() + 1);
else
mButtonsLayout.bringToFront();
}
@Override
public void destroy()
{
@ -110,7 +116,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
mPlacePage.setMapObject(object, false, () -> {
if (object.isExtendedView())
{
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
return;
}
@ -122,12 +128,12 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
private void openBottomSheet()
{
mPpSheet.post(() -> {
mPlacePage.post(() -> {
int peekHeight = getPeekHeight();
LOGGER.d(TAG, "Peek height = " + peekHeight);
mLastPeekHeight = peekHeight;
mPpSheetBehavior.setPeekHeight(mLastPeekHeight);
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mPlacePageBehavior.setPeekHeight(mLastPeekHeight);
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
});
}
@ -139,7 +145,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public void close()
{
mPpSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mPlacePage.hide();
}
@ -180,7 +186,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public boolean isClosed()
{
return mPpSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN;
return mPlacePageBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN;
}
@Override
@ -206,8 +212,8 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
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)
LOGGER.d(TAG, "Layout changed, current state = " + toString(mPlacePageBehavior.getState()));
if (mPlacePageBehavior.getState() != BottomSheetBehavior.STATE_COLLAPSED)
return;
if (getPeekHeight() == mLastPeekHeight)
@ -218,7 +224,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
private void updateViewPortRect()
{
View coordinatorLayout = (ViewGroup) mPpSheet.getParent();
View coordinatorLayout = (ViewGroup) mPlacePage.getParent();
int viewPortWidth = coordinatorLayout.getWidth();
int viewPortHeight = coordinatorLayout.getHeight();
Rect sheetRect = new Rect();

View file

@ -111,7 +111,7 @@ import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_A
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_DETAILS;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_OPENTABLE;
public class PlacePageView extends RelativeLayout
public class PlacePageView extends NestedScrollView
implements View.OnClickListener,
View.OnLongClickListener,
Sponsored.OnPriceReceivedListener,
@ -146,8 +146,6 @@ public class PlacePageView extends RelativeLayout
@SuppressWarnings("NullableProblems")
@NonNull
private RatingView mHotelDiscount;
// Details.
private NestedScrollView mDetails;
private View mPhone;
private TextView mTvPhone;
private View mWebsite;
@ -379,10 +377,10 @@ public class PlacePageView extends RelativeLayout
mBannerController.attach();
}
private void initViews()
@Override
protected void onFinishInflate()
{
LayoutInflater.from(getContext()).inflate(R.layout.place_page, this);
super.onFinishInflate();
mPreview = findViewById(R.id.pp__preview);
mTvTitle = mPreview.findViewById(R.id.tv__title);
mPopularityView = findViewById(R.id.popular_rating_view);
@ -403,48 +401,47 @@ public class PlacePageView extends RelativeLayout
mTvSponsoredPrice = mPreviewRatingInfo.findViewById(R.id.tv__hotel_price);
mHotelDiscount = mPreviewRatingInfo.findViewById(R.id.discount_in_percents);
mDetails = findViewById(R.id.pp__details);
RelativeLayout address = mDetails.findViewById(R.id.ll__place_name);
mPhone = mDetails.findViewById(R.id.ll__place_phone);
RelativeLayout address = findViewById(R.id.ll__place_name);
mPhone = findViewById(R.id.ll__place_phone);
mPhone.setOnClickListener(this);
mTvPhone = mDetails.findViewById(R.id.tv__place_phone);
mWebsite = mDetails.findViewById(R.id.ll__place_website);
mTvPhone = findViewById(R.id.tv__place_phone);
mWebsite = findViewById(R.id.ll__place_website);
mWebsite.setOnClickListener(this);
mTvWebsite = mDetails.findViewById(R.id.tv__place_website);
LinearLayout latlon = mDetails.findViewById(R.id.ll__place_latlon);
mTvWebsite = findViewById(R.id.tv__place_website);
LinearLayout latlon = findViewById(R.id.ll__place_latlon);
latlon.setOnClickListener(this);
mTvLatlon = mDetails.findViewById(R.id.tv__place_latlon);
mOpeningHours = mDetails.findViewById(R.id.ll__place_schedule);
mFullOpeningHours = mDetails.findViewById(R.id.opening_hours);
mTodayOpeningHours = mDetails.findViewById(R.id.today_opening_hours);
mWifi = mDetails.findViewById(R.id.ll__place_wifi);
mEmail = mDetails.findViewById(R.id.ll__place_email);
mTvLatlon = findViewById(R.id.tv__place_latlon);
mOpeningHours = findViewById(R.id.ll__place_schedule);
mFullOpeningHours = findViewById(R.id.opening_hours);
mTodayOpeningHours = findViewById(R.id.today_opening_hours);
mWifi = findViewById(R.id.ll__place_wifi);
mEmail = findViewById(R.id.ll__place_email);
mEmail.setOnClickListener(this);
mTvEmail = mEmail.findViewById(R.id.tv__place_email);
mOperator = mDetails.findViewById(R.id.ll__place_operator);
mTvEmail = findViewById(R.id.tv__place_email);
mOperator = findViewById(R.id.ll__place_operator);
mOperator.setOnClickListener(this);
mTvOperator = mOperator.findViewById(R.id.tv__place_operator);
mCuisine = mDetails.findViewById(R.id.ll__place_cuisine);
mTvCuisine = mCuisine.findViewById(R.id.tv__place_cuisine);
mWiki = mDetails.findViewById(R.id.ll__place_wiki);
mTvOperator = findViewById(R.id.tv__place_operator);
mCuisine = findViewById(R.id.ll__place_cuisine);
mTvCuisine = findViewById(R.id.tv__place_cuisine);
mWiki = findViewById(R.id.ll__place_wiki);
mWiki.setOnClickListener(this);
mEntrance = mDetails.findViewById(R.id.ll__place_entrance);
mEntrance = findViewById(R.id.ll__place_entrance);
mTvEntrance = mEntrance.findViewById(R.id.tv__place_entrance);
mTaxiShadow = mDetails.findViewById(R.id.place_page_taxi_shadow);
mTaxiDivider = mDetails.findViewById(R.id.place_page_taxi_divider);
mTaxi = mDetails.findViewById(R.id.ll__place_page_taxi);
mTaxiShadow = findViewById(R.id.place_page_taxi_shadow);
mTaxiDivider = findViewById(R.id.place_page_taxi_divider);
mTaxi = findViewById(R.id.ll__place_page_taxi);
TextView orderTaxi = mTaxi.findViewById(R.id.tv__place_page_order_taxi);
orderTaxi.setOnClickListener(this);
mEditPlace = mDetails.findViewById(R.id.ll__place_editor);
mEditPlace = findViewById(R.id.ll__place_editor);
mEditPlace.setOnClickListener(this);
mAddOrganisation = mDetails.findViewById(R.id.ll__add_organisation);
mAddOrganisation = findViewById(R.id.ll__add_organisation);
mAddOrganisation.setOnClickListener(this);
mAddPlace = mDetails.findViewById(R.id.ll__place_add);
mAddPlace = findViewById(R.id.ll__place_add);
mAddPlace.setOnClickListener(this);
mLocalAd = mDetails.findViewById(R.id.ll__local_ad);
mLocalAd = findViewById(R.id.ll__local_ad);
mLocalAd.setOnClickListener(this);
mTvLocalAd = mLocalAd.findViewById(R.id.tv__local_ad);
mEditTopSpace = mDetails.findViewById(R.id.edit_top_space);
mEditTopSpace = findViewById(R.id.edit_top_space);
latlon.setOnLongClickListener(this);
address.setOnLongClickListener(this);
mPhone.setOnLongClickListener(this);
@ -454,7 +451,7 @@ public class PlacePageView extends RelativeLayout
mOperator.setOnLongClickListener(this);
mWiki.setOnLongClickListener(this);
mBookmarkFrame = mDetails.findViewById(R.id.bookmark_frame);
mBookmarkFrame = findViewById(R.id.bookmark_frame);
mWvBookmarkNote = mBookmarkFrame.findViewById(R.id.wv__bookmark_notes);
mWvBookmarkNote.getSettings().setJavaScriptEnabled(false);
mTvBookmarkNote = mBookmarkFrame.findViewById(R.id.tv__bookmark_notes);
@ -488,7 +485,7 @@ public class PlacePageView extends RelativeLayout
setElevation(UiUtils.dimen(R.dimen.placepage_elevation));
if (UiUtils.isLandscape(getContext()))
mDetails.setBackgroundResource(0);
setBackgroundResource(0);
Sponsored.setPriceListener(this);
Sponsored.setInfoListener(this);
@ -984,7 +981,7 @@ public class PlacePageView extends RelativeLayout
private void init(AttributeSet attrs, int defStyleAttr)
{
initViews();
LayoutInflater.from(getContext()).inflate(R.layout.place_page, this);
if (isInEditMode())
return;
@ -1900,7 +1897,7 @@ public class PlacePageView extends RelativeLayout
public void hide()
{
mDetails.scrollTo(0, 0);
scrollTo(0, 0);
detachCountry();
}