[android] Implemented place page toolbar based on scrolling behavior

This commit is contained in:
Александр Зацепин 2019-01-28 17:38:03 +03:00 committed by yoksnod
parent b52f18ea95
commit 32ab1a989e
6 changed files with 84 additions and 31 deletions

View file

@ -95,4 +95,18 @@
android:background="?ppButtonsBackground"/>
<include layout="@layout/divider_horizontal"/>
</FrameLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
app:layout_behavior="@string/placepage_toolbar_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="@dimen/appbar_elevation"
android:visibility="gone">
<android.support.v7.widget.Toolbar
android:id="@+id/pp_toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/MwmWidget.ToolbarTheme.DownButton"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/MwmWidget.ToolbarTheme.DownButton"/>
<FrameLayout
style="@style/MwmWidget.FrameLayout.Elevation"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -96,5 +96,5 @@
<string name="never_enum_value" translatable="false">NEVER</string>
<string name="always_enum_value" translatable="false">ALWAYS</string>
<string name="auto_enum_value" translatable="false">AUTO</string>
<string name="user_lock_bottom_sheet_behavior" translatable="false">com.mapswithme.maps.widget.UserLockBottomSheetBehavior</string>
<string name="placepage_toolbar_behavior" translatable="false">com.mapswithme.maps.widget.placepage.ToolbarBehavior</string>
</resources>

View file

@ -7,6 +7,7 @@ import android.graphics.Rect;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
@ -16,7 +17,6 @@ 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;
@ -41,6 +41,11 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@SuppressWarnings("NullableProblems")
@NonNull
private PlacePageTracker mPlacePageTracker;
@SuppressWarnings("NullableProblems")
@NonNull
private Toolbar mToolbar;
private int mLastPeekHeight;
private int mViewportMinHeight;
@NonNull
private final BottomSheetBehavior.BottomSheetCallback mSheetCallback
= new BottomSheetBehavior.BottomSheetCallback()
@ -71,9 +76,6 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
}
};
private int mLastPeekHeight;
private int mViewportMinHeight;
public BottomSheetPlacePageController(@NonNull Activity activity)
{
mActivity = activity;
@ -83,27 +85,24 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
public void initialize()
{
mViewportMinHeight = mActivity.getResources().getDimensionPixelSize(R.dimen.viewport_min_height);
mToolbar = mActivity.findViewById(R.id.pp_toolbar);
UiUtils.extendViewWithStatusBar(mToolbar);
UiUtils.showHomeUpButton(mToolbar);
mToolbar.setNavigationOnClickListener(v -> close());
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);
bringButtonsToFront();
ViewGroup buttons = mButtonsLayout.findViewById(R.id.container);
mPlacePage.initButtons(buttons);
UiUtils.bringViewToFrontOf(mButtonsLayout, mPlacePage);
UiUtils.bringViewToFrontOf(mActivity.findViewById(R.id.app_bar), mPlacePage);
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()
{
@ -122,6 +121,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
openBottomSheet();
});
mToolbar.setTitle(object.getTitle());
mPlacePageTracker.setMapObject(object);
Framework.logLocalAdsEvent(Framework.LocalAdsEventType.LOCAL_ADS_EVENT_OPEN_INFO, object);
}

View file

@ -0,0 +1,48 @@
package com.mapswithme.maps.widget.placepage;
import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
@SuppressWarnings("unused")
public class ToolbarBehavior extends AppBarLayout.ScrollingViewBehavior
{
public ToolbarBehavior()
{
// Do nothing by default.
}
public ToolbarBehavior(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency)
{
return dependency.getId() == R.id.placepage;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency)
{
if (dependency.getY() == 0 && UiUtils.isHidden(child))
{
UiUtils.show(child);
return false;
}
if (dependency.getY() > 0 && UiUtils.isVisible(child))
{
UiUtils.hide(child);
return false;
}
return false;
}
}

View file

@ -55,6 +55,14 @@ public final class UiUtils
params.setMargins(0, UiUtils.getStatusBarHeight(view.getContext()), 0, 0);
}
public static void bringViewToFrontOf(@NonNull View frontView, @NonNull View backView)
{
if (Utils.isLollipopOrLater())
frontView.setZ(backView.getZ() + 1);
else
frontView.bringToFront();
}
public static class SimpleAnimationListener implements AnimationListener
{
@Override