android: move place page buttons to fragment

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-12-28 17:33:50 +01:00 committed by Viktor Govako
parent 0969baf696
commit 7f62e38996
10 changed files with 547 additions and 642 deletions

View file

@ -58,18 +58,8 @@
android:layout_height="wrap_content"
android:fillViewport="true"
app:layout_behavior="@string/placepage_behavior" />
<FrameLayout
android:id="@+id/pp_buttons_layout"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/pp_buttons_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?ppButtonsBackground"
android:visibility="invisible">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="@dimen/place_page_buttons_height"
android:orientation="horizontal" />
<include layout="@layout/divider_horizontal" />
</FrameLayout>
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pp_buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?ppButtonsBackground"
android:orientation="horizontal"
android:layout_gravity="bottom">
<include layout="@layout/divider_horizontal" />
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="@dimen/place_page_buttons_height"
android:orientation="horizontal" />
</RelativeLayout>

View file

@ -6,6 +6,7 @@
<item name="android:gravity">center</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">10sp</item>
<item name="android:color">?iconTint</item>
</style>
<style name="PlacePageButtonImage">
@ -16,6 +17,7 @@
<item name="android:paddingTop">@dimen/margin_base</item>
<item name="android:paddingBottom">@dimen/margin_base</item>
<item name="android:scaleType">center</item>
<item name="android:color">?iconTint</item>
</style>
<style name="PlacePageButton">

View file

@ -79,6 +79,7 @@ import app.organicmaps.settings.UnitLocale;
import app.organicmaps.sound.TtsPlayer;
import app.organicmaps.util.log.Logger;
import app.organicmaps.widget.menu.MainMenu;
import app.organicmaps.widget.placepage.PlacePageButtons;
import app.organicmaps.widget.placepage.PlacePageController;
import app.organicmaps.widget.placepage.PlacePageData;
import app.organicmaps.widget.placepage.RoutingModeListener;
@ -114,7 +115,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
RoutingModeListener,
NoConnectionListener,
MenuBottomSheetFragment.MenuBottomSheetInterfaceWithHeader,
ToggleMapLayerFragment.LayerItemClickListener
ToggleMapLayerFragment.LayerItemClickListener,
PlacePageButtons.PlacePageButtonClickListener
{
private static final String TAG = MwmActivity.class.getSimpleName();
@ -149,6 +151,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private View mPointChooser;
private Toolbar mPointChooserToolbar;
enum PointChooserMode
{
NONE,
@ -1810,7 +1813,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
return items;
}
else if (id.equals(PLACEPAGE_MORE_MENU_ID))
return mPlacePageController.getMenuBottomSheetItems();
return mPlacePageController.getMenuBottomSheetItems(id);
return null;
}
@ -1822,4 +1825,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
return new ToggleMapLayerFragment();
return null;
}
@Override
public void onPlacePageButtonClick(PlacePageButtons.ButtonType item)
{
mPlacePageController.onPlacePageButtonClick(item);
}
}

View file

@ -0,0 +1,40 @@
package app.organicmaps.widget.placepage;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
public class PlacePageButton
{
@StringRes
private final int mTitleId;
@DrawableRes
private final int mIconId;
@NonNull
private final PlacePageButtons.ButtonType mButtonType;
PlacePageButton(@StringRes int titleId, @DrawableRes int iconId, @NonNull PlacePageButtons.ButtonType buttonType)
{
mTitleId = titleId;
mIconId = iconId;
mButtonType = buttonType;
}
@StringRes
public int getTitle()
{
return mTitleId;
}
@DrawableRes
public int getIcon()
{
return mIconId;
}
@NonNull
public PlacePageButtons.ButtonType getType()
{
return mButtonType;
}
}

View file

@ -0,0 +1,71 @@
package app.organicmaps.widget.placepage;
import android.content.Context;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.util.ThemeUtils;
public class PlacePageButtonFactory
{
static PlacePageButton createButton(PlacePageButtons.ButtonType buttonType, @NonNull Context context)
{
@StringRes int titleId = 0;
@DrawableRes int iconId = 0;
switch (buttonType)
{
case BACK:
titleId = R.string.back;
iconId = ThemeUtils.getResource(MwmApplication.from(context), android.R.attr.homeAsUpIndicator);
break;
case BOOKMARK_SAVE:
titleId = R.string.save;
iconId = R.drawable.ic_bookmarks_off;
break;
case BOOKMARK_DELETE:
titleId = R.string.delete;
iconId = R.drawable.ic_bookmarks_on;
break;
case ROUTE_FROM:
titleId = R.string.p2p_from_here;
iconId = R.drawable.ic_route_from;
break;
case ROUTE_TO:
titleId = R.string.p2p_to_here;
iconId = R.drawable.ic_route_to;
break;
case ROUTE_ADD:
titleId = R.string.placepage_add_stop;
iconId = R.drawable.ic_route_via;
break;
case ROUTE_REMOVE:
titleId = R.string.placepage_remove_stop;
iconId = R.drawable.ic_route_remove;
break;
case ROUTE_AVOID_TOLL:
titleId = R.string.avoid_toll_roads_placepage;
iconId = R.drawable.ic_avoid_tolls;
break;
case ROUTE_AVOID_UNPAVED:
titleId = R.string.avoid_unpaved_roads_placepage;
iconId = R.drawable.ic_avoid_unpaved;
break;
case ROUTE_AVOID_FERRY:
titleId = R.string.avoid_ferry_crossing_placepage;
iconId = R.drawable.ic_avoid_ferry;
break;
case SHARE:
titleId = R.string.share;
iconId = R.drawable.ic_share;
break;
case MORE:
titleId = R.string.placepage_more_button;
iconId = R.drawable.ic_more;
break;
}
return new PlacePageButton(titleId, iconId, buttonType);
}
}

View file

@ -1,110 +1,144 @@
package app.organicmaps.widget.placepage;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import app.organicmaps.MwmActivity;
import app.organicmaps.MwmApplication;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import app.organicmaps.R;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.UiUtils;
import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public final class PlacePageButtons
public final class PlacePageButtons extends Fragment implements Observer<List<PlacePageButtons.ButtonType>>
{
public static final String PLACEPAGE_MORE_MENU_ID = "PLACEPAGE_MORE_MENU_BOTTOM_SHEET";
private final int mMaxButtons;
private int mMaxButtons;
private final MwmActivity mMwmActivity;
private final ViewGroup mFrame;
private final ItemListener mItemListener;
private PlacePageButtonClickListener mItemListener;
private ViewGroup mButtonsContainer;
private PlacePageButtonsViewModel viewModel;
private List<PlacePageButton> mPrevItems;
private List<PlacePageButton> mMoreItems;
interface PlacePageButton
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
@StringRes
int getTitle();
return inflater.inflate(R.layout.pp_buttons_fragment, container, false);
}
ImageResources getIcon();
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
mButtonsContainer = view.findViewById(R.id.container);
view.setOnApplyWindowInsetsListener((v, windowInsets) -> {
UiUtils.setViewInsetsPaddingNoTop(v, windowInsets);
return windowInsets;
});
mMaxButtons = getResources().getInteger(R.integer.pp_buttons_max);
viewModel = new ViewModelProvider(requireActivity()).get(PlacePageButtonsViewModel.class);
viewModel.getCurrentButtons().observe(requireActivity(), this);
createButtons(viewModel.getCurrentButtons().getValue());
}
@NonNull
ButtonType getType();
@DrawableRes
int getBackgroundResource();
class ImageResources
@Override
public void onAttach(@NonNull Context context)
{
super.onAttach(context);
try
{
@DrawableRes
private final int mEnabledStateResId;
@DrawableRes
private final int mDisabledStateResId;
public ImageResources(@DrawableRes int enabledStateResId, @DrawableRes int disabledStateResId)
{
mEnabledStateResId = enabledStateResId;
mDisabledStateResId = disabledStateResId;
}
public ImageResources(@DrawableRes int enabledStateResId)
{
this(enabledStateResId, enabledStateResId);
}
@DrawableRes
public int getDisabledStateResId()
{
return mDisabledStateResId;
}
@DrawableRes
public int getEnabledStateResId(@NonNull Context context)
{
return mEnabledStateResId;
}
public static class Stub extends ImageResources
{
public Stub()
{
super(UiUtils.NO_ID);
}
@Override
public int getDisabledStateResId()
{
throw new UnsupportedOperationException("Not supported here");
}
@Override
public int getEnabledStateResId(@NonNull Context context)
{
throw new UnsupportedOperationException("Not supported here");
}
}
mItemListener = (PlacePageButtonClickListener) context;
}
catch (ClassCastException e)
{
throw new ClassCastException(context + " must implement PlacePageButtonClickListener");
}
}
enum ButtonType {
@Override
public void onDestroy()
{
super.onDestroy();
viewModel.getCurrentButtons().removeObserver(this);
}
private @NonNull
List<PlacePageButton> collectButtons(List<PlacePageButtons.ButtonType> items)
{
List<PlacePageButton> res = new ArrayList<>();
int count = items.size();
if (items.size() > mMaxButtons)
count = mMaxButtons - 1;
for (int i = 0; i < count; i++)
res.add(PlacePageButtonFactory.createButton(items.get(i), requireContext()));
if (items.size() > mMaxButtons)
res.add(PlacePageButtonFactory.createButton(ButtonType.MORE, requireContext()));
return res;
}
private void showMoreBottomSheet()
{
MenuBottomSheetFragment.newInstance(PLACEPAGE_MORE_MENU_ID)
.show(requireActivity().getSupportFragmentManager(), PLACEPAGE_MORE_MENU_ID);
}
private void createButtons(@Nullable List<ButtonType> buttons)
{
if (buttons == null)
return;
List<PlacePageButton> shownButtons = collectButtons(buttons);
mButtonsContainer.removeAllViews();
for (PlacePageButton button : shownButtons)
mButtonsContainer.addView(createButton(button));
}
private View createButton(@NonNull final PlacePageButton current)
{
LayoutInflater inflater = LayoutInflater.from(requireContext());
View parent = inflater.inflate(R.layout.place_page_button, mButtonsContainer, false);
ImageView icon = parent.findViewById(R.id.icon);
TextView title = parent.findViewById(R.id.title);
title.setText(current.getTitle());
@AttrRes final int tint = current.getType() == ButtonType.BOOKMARK_DELETE
? R.attr.iconTintActive
: R.attr.iconTint;
icon.setImageDrawable(Graphics.tint(getContext(), current.getIcon(), tint));
parent.setOnClickListener((view) -> {
if (current.getType() == ButtonType.MORE)
showMoreBottomSheet();
else
mItemListener.onPlacePageButtonClick(current.getType());
});
return parent;
}
@Override
public void onChanged(List<ButtonType> buttonTypes)
{
createButtons(buttonTypes);
}
public enum ButtonType
{
BACK,
BOOKMARK,
BOOKMARK_SAVE,
BOOKMARK_DELETE,
ROUTE_FROM,
ROUTE_TO,
ROUTE_ADD,
@ -113,275 +147,11 @@ public final class PlacePageButtons
ROUTE_AVOID_FERRY,
ROUTE_AVOID_UNPAVED,
SHARE,
MORE,
CALL
MORE
}
enum Item implements PlacePageButtons.PlacePageButton
public interface PlacePageButtonClickListener
{
BACK(
R.string.back,
new ImageResources.Stub()
{
@Override
public int getEnabledStateResId(@NonNull Context context)
{
return ThemeUtils.getResource(MwmApplication.from(context),
android.R.attr.homeAsUpIndicator);
}
},
ButtonType.BACK),
BOOKMARK_SAVE(
R.string.save,
new ImageResources(R.drawable.ic_bookmarks_on),
ButtonType.BOOKMARK),
BOOKMARK_DELETE(
R.string.delete,
new ImageResources(R.drawable.ic_bookmarks_off),
ButtonType.BOOKMARK),
ROUTE_FROM(
R.string.p2p_from_here,
new ImageResources(R.drawable.ic_route_from),
ButtonType.ROUTE_FROM),
ROUTE_TO(
R.string.p2p_to_here,
new ImageResources(R.drawable.ic_route_to),
ButtonType.ROUTE_TO),
ROUTE_ADD(
R.string.placepage_add_stop,
new ImageResources(R.drawable.ic_route_via),
ButtonType.ROUTE_ADD),
ROUTE_REMOVE(
R.string.placepage_remove_stop,
new ImageResources(R.drawable.ic_route_remove),
ButtonType.ROUTE_REMOVE),
ROUTE_AVOID_TOLL(
R.string.avoid_toll_roads_placepage,
new ImageResources(R.drawable.ic_avoid_tolls),
ButtonType.ROUTE_AVOID_TOLL),
ROUTE_AVOID_UNPAVED(
R.string.avoid_unpaved_roads_placepage,
new ImageResources(R.drawable.ic_avoid_unpaved),
ButtonType.ROUTE_AVOID_UNPAVED),
ROUTE_AVOID_FERRY(
R.string.avoid_ferry_crossing_placepage,
new ImageResources(R.drawable.ic_avoid_ferry),
ButtonType.ROUTE_AVOID_FERRY),
SHARE(
R.string.share,
new ImageResources(R.drawable.ic_share),
ButtonType.SHARE),
// Must not be used outside
MORE(
R.string.placepage_more_button,
new ImageResources(R.drawable.ic_more),
ButtonType.MORE),
CALL(
R.string.placepage_call_button,
new ImageResources(R.drawable.ic_place_page_phone),
ButtonType.CALL);
@StringRes
private final int mTitleId;
@NonNull
private final ImageResources mIconId;
@NonNull
private final ButtonType mButtonType;
Item(@StringRes int titleId, @NonNull ImageResources iconId, @NonNull ButtonType buttonType)
{
mTitleId = titleId;
mIconId = iconId;
mButtonType = buttonType;
}
@StringRes
@Override
public int getTitle()
{
return mTitleId;
}
@NonNull
@Override
public ImageResources getIcon()
{
return mIconId;
}
@NonNull
@Override
public ButtonType getType()
{
return mButtonType;
}
@DrawableRes
@Override
public int getBackgroundResource()
{
throw new UnsupportedOperationException("Not supported!");
}
}
interface ItemListener
{
void onPrepareVisibleView(@NonNull PlacePageButton item, @NonNull View frame,
@NonNull ImageView icon, @NonNull TextView title);
void onItemClick(PlacePageButton item);
}
PlacePageButtons(MwmActivity mwmActivity, ViewGroup frame, ItemListener itemListener)
{
mMwmActivity = mwmActivity;
mFrame = frame;
mItemListener = itemListener;
mMaxButtons = mMwmActivity.getResources().getInteger(R.integer.pp_buttons_max);
}
private @NonNull List<PlacePageButtons.PlacePageButton> collectButtons(List<PlacePageButtons.PlacePageButton> items)
{
List<PlacePageButtons.PlacePageButton> res = new ArrayList<>(items);
if (res.size() > mMaxButtons)
res.add(mMaxButtons - 1, Item.MORE);
// Swap ROUTE_FROM and ROUTE_TO if the latter one was pressed out to bottomsheet
int from = res.indexOf(Item.ROUTE_FROM);
if (from > -1)
{
int addStop = res.indexOf(Item.ROUTE_ADD);
int to = res.indexOf(Item.ROUTE_TO);
if ((to > from && to >= mMaxButtons) || (to > from && addStop >= mMaxButtons))
Collections.swap(res, from, to);
if (addStop >= mMaxButtons)
{
from = res.indexOf(Item.ROUTE_FROM);
if (addStop > from)
Collections.swap(res, from, addStop);
}
preserveRoutingButtons(res, Item.CALL);
from = res.indexOf(Item.ROUTE_FROM);
to = res.indexOf(Item.ROUTE_TO);
if (from < mMaxButtons && from > to)
Collections.swap(res, to, from);
}
return res;
}
private void preserveRoutingButtons(@NonNull List<PlacePageButton> items, @NonNull Item itemToShift)
{
if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning())
return;
int pos = items.indexOf(itemToShift);
if (pos > -1)
{
items.remove(pos);
items.add(mMaxButtons, itemToShift);
int to = items.indexOf(Item.ROUTE_TO);
if (items.indexOf(Item.ROUTE_ADD) > -1)
{
items.remove(Item.ROUTE_ADD);
items.remove(Item.ROUTE_FROM);
items.add(to + 1, Item.ROUTE_ADD);
items.add(mMaxButtons, Item.ROUTE_FROM);
}
else
{
items.remove(Item.ROUTE_FROM);
items.add(to + 1, Item.ROUTE_FROM);
}
}
}
@Nullable
public ArrayList<MenuBottomSheetItem> getMenuBottomSheetItems()
{
if (mMoreItems == null)
return null;
ArrayList<MenuBottomSheetItem> items = new ArrayList<>();
for (int i = mMaxButtons; i < mMoreItems.size(); i++)
{
final PlacePageButton bsItem = mMoreItems.get(i);
int iconRes = bsItem.getIcon().getEnabledStateResId(mMwmActivity);
items.add(new MenuBottomSheetItem(bsItem.getTitle(), iconRes, () -> mItemListener.onItemClick(bsItem)));
}
return items;
}
private void showPopup()
{
MenuBottomSheetFragment.newInstance(PLACEPAGE_MORE_MENU_ID)
.show(mMwmActivity.getSupportFragmentManager(), PLACEPAGE_MORE_MENU_ID);
}
private View createButton(@NonNull final List<PlacePageButton> items,
@NonNull final PlacePageButton current)
{
LayoutInflater inflater = LayoutInflater.from(mMwmActivity);
View parent = inflater.inflate(R.layout.place_page_button, mFrame, false);
ImageView icon = parent.findViewById(R.id.icon);
TextView title = parent.findViewById(R.id.title);
title.setText(current.getTitle());
icon.setImageResource(current.getIcon().getEnabledStateResId(mMwmActivity));
mItemListener.onPrepareVisibleView(current, parent, icon, title);
if (current == Item.MORE)
mMoreItems = items;
parent.setOnClickListener(new ShowPopupClickListener(current));
return parent;
}
void setItems(List<PlacePageButton> items)
{
final List<PlacePageButton> buttons = collectButtons(items);
if (buttons.equals(mPrevItems))
return;
mFrame.removeAllViews();
int count = Math.min(buttons.size(), mMaxButtons);
for (int i = 0; i < count; i++)
mFrame.addView(createButton(buttons, buttons.get(i)));
mPrevItems = buttons;
}
private class ShowPopupClickListener implements View.OnClickListener
{
@NonNull
private final PlacePageButton mCurrent;
public ShowPopupClickListener(@NonNull PlacePageButton current)
{
mCurrent = current;
}
@Override
public void onClick(View v)
{
if (mCurrent == Item.MORE)
showPopup();
else
mItemListener.onItemClick(mCurrent);
}
void onPlacePageButtonClick(ButtonType item);
}
}

View file

@ -0,0 +1,22 @@
package app.organicmaps.widget.placepage;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import java.util.List;
public class PlacePageButtonsViewModel extends ViewModel
{
private final MutableLiveData<List<PlacePageButtons.ButtonType>> mCurrentButtons = new MutableLiveData<>();
public LiveData<List<PlacePageButtons.ButtonType>> getCurrentButtons()
{
return mCurrentButtons;
}
public void setCurrentButtons(List<PlacePageButtons.ButtonType> buttons)
{
mCurrentButtons.setValue(buttons);
}
}

View file

@ -6,11 +6,13 @@ import android.content.res.Resources;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GestureDetectorCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import app.organicmaps.Framework;
import app.organicmaps.R;
import app.organicmaps.base.Initializable;
@ -20,17 +22,21 @@ import app.organicmaps.location.LocationHelper;
import app.organicmaps.location.LocationListener;
import app.organicmaps.util.UiUtils;
import app.organicmaps.util.Utils;
import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
import app.organicmaps.util.log.Logger;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class PlacePageController implements Initializable<Activity>,
Savable<Bundle>,
LocationListener,
PlacePageView.OnPlacePageRequestCloseListener
PlacePageView.OnPlacePageRequestCloseListener,
PlacePageButtons.PlacePageButtonClickListener,
MenuBottomSheetFragment.MenuBottomSheetInterface
{
private static final String TAG = PlacePageController.class.getSimpleName();
@ -44,12 +50,11 @@ public class PlacePageController implements Initializable<Activity>,
private BottomSheetBehavior<View> mPlacePageBehavior;
@SuppressWarnings("NullableProblems")
@NonNull
private View mButtonsLayout;
@SuppressWarnings("NullableProblems")
@NonNull
private PlacePageView mPlacePage;
private int mViewportMinHeight;
private boolean mDeactivateMapSelection = true;
private AppCompatActivity mMwmActivity;
private float mButtonsHeight;
@NonNull
private final BottomSheetChangedListener mBottomSheetChangedListener = new BottomSheetChangedListener()
{
@ -88,6 +93,8 @@ public class PlacePageController implements Initializable<Activity>,
@NonNull
private final BottomSheetBehavior.BottomSheetCallback mSheetCallback
= new DefaultBottomSheetCallback(mBottomSheetChangedListener);
private int mMaxButtons;
private PlacePageButtonsViewModel viewModel;
public PlacePageController(@NonNull SlideListener listener,
@Nullable RoutingModeListener routingModeListener)
@ -102,7 +109,14 @@ public class PlacePageController implements Initializable<Activity>,
Framework.nativeDeactivatePopup();
mDeactivateMapSelection = true;
PlacePageUtils.moveViewportUp(mPlacePage, mViewportMinHeight);
UiUtils.invisible(mButtonsLayout);
Fragment f = mMwmActivity.getSupportFragmentManager().findFragmentByTag("PLACE_PAGE_BUTTONS");
if (f != null)
{
mMwmActivity.getSupportFragmentManager().beginTransaction()
.remove(f)
.commit();
}
}
@SuppressLint("ClickableViewAccessibility")
@ -110,6 +124,7 @@ public class PlacePageController implements Initializable<Activity>,
public void initialize(@Nullable Activity activity)
{
Objects.requireNonNull(activity);
mMwmActivity = (AppCompatActivity) activity;
Resources res = activity.getResources();
mViewportMinHeight = res.getDimensionPixelSize(R.dimen.viewport_min_height);
mPlacePage = activity.findViewById(R.id.placepage);
@ -125,17 +140,15 @@ public class PlacePageController implements Initializable<Activity>,
mPlacePage.setRoutingModeListener(mRoutingModeListener);
mPlacePage.setOnPlacePageContentChangeListener(this::setPeekHeight);
mButtonsLayout = activity.findViewById(R.id.pp_buttons_layout);
ViewGroup buttons = mButtonsLayout.findViewById(R.id.container);
mPlacePage.initButtons(buttons);
UiUtils.bringViewToFrontOf(mButtonsLayout, mPlacePage);
UiUtils.bringViewToFrontOf(activity.findViewById(R.id.pp_buttons_fragment), mPlacePage);
LocationHelper.INSTANCE.addListener(this);
mButtonsLayout.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPaddingNoTop(mButtonsLayout, windowInsets);
return windowInsets;
});
mPlacePage.requestApplyInsets();
mButtonsHeight = mMwmActivity.getResources().getDimension(R.dimen.place_page_buttons_height);
mMaxButtons = mMwmActivity.getResources().getInteger(R.integer.pp_buttons_max);
viewModel = new ViewModelProvider(mMwmActivity).get(PlacePageButtonsViewModel.class);
}
public int getPlacePageWidth()
@ -144,9 +157,22 @@ public class PlacePageController implements Initializable<Activity>,
}
@Nullable
public ArrayList<MenuBottomSheetItem> getMenuBottomSheetItems()
public ArrayList<MenuBottomSheetItem> getMenuBottomSheetItems(String id)
{
return mPlacePage.getMenuBottomSheetItems();
final List<PlacePageButtons.ButtonType> currentItems = viewModel.getCurrentButtons().getValue();
if (currentItems == null || currentItems.size() <= mMaxButtons)
return null;
ArrayList<MenuBottomSheetItem> items = new ArrayList<>();
for (int i = mMaxButtons - 1; i < currentItems.size(); i++)
{
final PlacePageButton bsItem = PlacePageButtonFactory.createButton(currentItems.get(i), mMwmActivity);
items.add(new MenuBottomSheetItem(
bsItem.getTitle(),
bsItem.getIcon(),
() -> ((PlacePageButtons.PlacePageButtonClickListener) mMwmActivity).onPlacePageButtonClick(bsItem.getType())
));
}
return items;
}
@Override
@ -172,8 +198,14 @@ public class PlacePageController implements Initializable<Activity>,
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
return;
}
if (mMwmActivity.getSupportFragmentManager().findFragmentByTag("PLACE_PAGE_BUTTONS") == null)
{
mMwmActivity.getSupportFragmentManager().beginTransaction()
.add(R.id.pp_buttons_fragment,
PlacePageButtons.class, null, "PLACE_PAGE_BUTTONS")
.commit();
}
UiUtils.show(mButtonsLayout);
mPlacePage.post(() -> {
setPeekHeight();
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
@ -203,8 +235,7 @@ public class PlacePageController implements Initializable<Activity>,
{
// Buttons layout padding is the navigation bar height.
// Bottom sheets are displayed above it so we need to remove it from the computed size
final int organicPeekHeight = mPlacePage.getPreviewHeight() +
mButtonsLayout.getHeight() - mButtonsLayout.getPaddingBottom();
final int organicPeekHeight = (int) (mPlacePage.getPreviewHeight() + mButtonsHeight);
final MapObject object = mPlacePage.getMapObject();
if (object != null)
{
@ -281,7 +312,6 @@ public class PlacePageController implements Initializable<Activity>,
{
mPlacePage.post(() -> {
mPlacePageBehavior.setState(state);
UiUtils.show(mButtonsLayout);
setPeekHeight();
});
}
@ -292,6 +322,12 @@ public class PlacePageController implements Initializable<Activity>,
close(true);
}
@Override
public void onPlacePageButtonClick(PlacePageButtons.ButtonType item)
{
mPlacePage.onPlacePageButtonClick(item);
}
public interface SlideListener
{
void onPlacePageSlide(int top);

View file

@ -21,7 +21,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
@ -33,6 +32,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.widget.NestedScrollViewClickFixed;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.Framework;
import app.organicmaps.MwmActivity;
@ -58,16 +58,14 @@ import app.organicmaps.location.LocationHelper;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.search.Popularity;
import app.organicmaps.settings.RoadType;
import app.organicmaps.widget.ArrowView;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.SharingUtils;
import app.organicmaps.util.StringUtils;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.UiUtils;
import app.organicmaps.util.Utils;
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
import app.organicmaps.util.concurrency.UiThread;
import app.organicmaps.util.log.Logger;
import app.organicmaps.widget.ArrowView;
import java.util.ArrayList;
import java.util.Arrays;
@ -79,7 +77,8 @@ import java.util.Objects;
public class PlacePageView extends NestedScrollViewClickFixed
implements View.OnClickListener,
View.OnLongClickListener,
EditBookmarkFragment.EditBookmarkListener
EditBookmarkFragment.EditBookmarkListener,
PlacePageButtons.PlacePageButtonClickListener
{
private static final String TAG = PlacePageView.class.getSimpleName();
@ -90,11 +89,11 @@ public class PlacePageView extends NestedScrollViewClickFixed
CoordinatesFormat.LatLonDecimal,
CoordinatesFormat.OLCFull,
CoordinatesFormat.OSMLink);
@NonNull
private final EditBookmarkClickListener mEditBookmarkClickListener = new EditBookmarkClickListener();
private boolean mIsDocked;
private boolean mIsFloating;
private int mDescriptionMaxLength;
// Preview.
private ViewGroup mPreview;
private Toolbar mToolbar;
@ -104,7 +103,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
private ArrowView mAvDirection;
private TextView mTvDistance;
private TextView mTvAddress;
// Details.
private ViewGroup mDetails;
private RecyclerView mPhoneRecycler;
@ -123,7 +121,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
private TextView mTvVkPage;
private View mLinePage;
private TextView mTvLinePage;
private View mOpeningHours;
private TextView mTodayLabel;
private TextView mTodayOpenTime;
@ -154,49 +151,39 @@ public class PlacePageView extends NestedScrollViewClickFixed
private WebView mWvBookmarkNote;
private TextView mTvBookmarkNote;
private boolean mBookmarkSet;
// Place page buttons
private PlacePageButtons mButtons;
private ImageView mBookmarkButtonIcon;
@Nullable
private View mBookmarkButtonFrame;
@SuppressWarnings("NullableProblems")
@NonNull
private View mPlaceDescriptionContainer;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private View mPlaceDescriptionHeaderContainer;
@SuppressWarnings("NullableProblems")
@NonNull
private TextView mPlaceDescriptionView;
@SuppressWarnings("NullableProblems")
@NonNull
private View mPlaceDescriptionMoreBtn;
@SuppressWarnings("NullableProblems")
@NonNull
private View mPopularityView;
// Data
@Nullable
private MapObject mMapObject;
private CoordinatesFormat mCoordsFormat = CoordinatesFormat.LatLonDecimal;
// Downloader`s stuff
private DownloaderStatusIcon mDownloaderIcon;
private TextView mDownloaderInfo;
private int mStorageCallbackSlot;
@Nullable
private CountryItem mCurrentCountry;
private boolean mScrollable = true;
private OnPlacePageContentChangeListener mOnPlacePageContentChangeListener;
private OnPlacePageRequestCloseListener mOnPlacePageRequestCloseListener;
private final Runnable mDownloaderDeferredDetachProc = new Runnable()
{
@Override
public void run()
{
detachCountry();
}
};
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
{
@Override
@ -220,18 +207,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
updateDownloader();
}
};
private final Runnable mDownloaderDeferredDetachProc = new Runnable()
{
@Override
public void run()
{
detachCountry();
}
};
@NonNull
private final EditBookmarkClickListener mEditBookmarkClickListener = new EditBookmarkClickListener();
@NonNull
private final OnClickListener mDownloadClickListener = new OnClickListener()
{
@ -241,7 +216,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
MapManager.warn3gAndDownload(requireActivity(), mCurrentCountry.id, null);
}
};
@NonNull
private final OnClickListener mCancelDownloadListener = new OnClickListener()
{
@ -251,13 +225,73 @@ public class PlacePageView extends NestedScrollViewClickFixed
MapManager.nativeCancel(mCurrentCountry.id);
}
};
private boolean mScrollable = true;
private OnPlacePageContentChangeListener mOnPlacePageContentChangeListener;
private OnPlacePageRequestCloseListener mOnPlacePageRequestCloseListener;
@Nullable
private PlacePageGestureListener mPlacePageGestureListener;
@Nullable
private RoutingModeListener mRoutingModeListener;
private PlacePageButtonsViewModel viewModel;
public PlacePageView(Context context)
{
this(context, null, 0);
}
public PlacePageView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public PlacePageView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs);
mCoordsFormat = CoordinatesFormat.fromId(MwmApplication.prefs(context)
.getInt(PREF_COORDINATES_FORMAT, CoordinatesFormat.LatLonDecimal.getId()));
init(attrs, defStyleAttr);
}
@NonNull
private static PlacePageButtons.ButtonType toPlacePageButton(@NonNull RoadWarningMarkType type)
{
switch (type)
{
case DIRTY:
return PlacePageButtons.ButtonType.ROUTE_AVOID_UNPAVED;
case FERRY:
return PlacePageButtons.ButtonType.ROUTE_AVOID_FERRY;
case TOLL:
return PlacePageButtons.ButtonType.ROUTE_AVOID_TOLL;
default:
throw new AssertionError("Unsupported road warning type: " + type);
}
}
private static void refreshMetadataOrHide(String metadata, View metaLayout, TextView metaTv)
{
if (!TextUtils.isEmpty(metadata))
{
metaLayout.setVisibility(View.VISIBLE);
if (metaTv != null)
metaTv.setText(metadata);
}
else
metaLayout.setVisibility(View.GONE);
}
private static boolean isInvalidDownloaderStatus(int status)
{
return (status != CountryItem.STATUS_DOWNLOADABLE &&
status != CountryItem.STATUS_ENQUEUED &&
status != CountryItem.STATUS_FAILED &&
status != CountryItem.STATUS_PARTLY &&
status != CountryItem.STATUS_PROGRESS &&
status != CountryItem.STATUS_APPLYING);
}
void setScrollable(boolean scrollable)
{
mScrollable = scrollable;
@ -291,32 +325,12 @@ public class PlacePageView extends NestedScrollViewClickFixed
return mScrollable && super.onInterceptTouchEvent(event);
}
public interface SetMapObjectListener
{
void onSetMapObjectComplete(boolean isSameObject);
}
public PlacePageView(Context context)
{
this(context, null, 0);
}
public PlacePageView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public PlacePageView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs);
mCoordsFormat = CoordinatesFormat.fromId(MwmApplication.prefs(context).getInt(PREF_COORDINATES_FORMAT, CoordinatesFormat.LatLonDecimal.getId()));
init(attrs, defStyleAttr);
}
@Override
protected void onFinishInflate()
{
super.onFinishInflate();
viewModel = new ViewModelProvider(requireActivity()).get(PlacePageButtonsViewModel.class);
mPreview = findViewById(R.id.pp__preview);
mPreview.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
final int oldHeight = oldBottom - oldTop;
@ -445,85 +459,52 @@ public class PlacePageView extends NestedScrollViewClickFixed
initPlaceDescriptionView();
}
public void initButtons(@NonNull ViewGroup buttons)
@Override
public void onPlacePageButtonClick(PlacePageButtons.ButtonType item)
{
mButtons = new PlacePageButtons(requireActivity(), buttons, new PlacePageButtons.ItemListener()
switch (item)
{
public void onPrepareVisibleView(@NonNull PlacePageButtons.PlacePageButton item,
@NonNull View frame, @NonNull ImageView icon,
@NonNull TextView title)
{
int color;
case BOOKMARK_SAVE:
case BOOKMARK_DELETE:
onBookmarkBtnClicked();
break;
switch (item.getType())
{
case BOOKMARK:
mBookmarkButtonIcon = icon;
mBookmarkButtonFrame = frame;
updateBookmarkButton();
color = ThemeUtils.getColor(getContext(), R.attr.iconTint);
break;
case SHARE:
onShareBtnClicked();
break;
default:
color = ThemeUtils.getColor(getContext(), R.attr.iconTint);
icon.setColorFilter(color);
break;
}
case BACK:
onBackBtnClicked();
break;
title.setTextColor(color);
}
case ROUTE_FROM:
onRouteFromBtnClicked();
break;
@Override
public void onItemClick(PlacePageButtons.PlacePageButton item)
{
switch (item.getType())
{
case BOOKMARK:
onBookmarkBtnClicked();
break;
case ROUTE_TO:
onRouteToBtnClicked();
break;
case SHARE:
onShareBtnClicked();
break;
case ROUTE_ADD:
onRouteAddBtnClicked();
break;
case BACK:
onBackBtnClicked();
break;
case ROUTE_REMOVE:
onRouteRemoveBtnClicked();
break;
case ROUTE_FROM:
onRouteFromBtnClicked();
break;
case ROUTE_AVOID_TOLL:
onAvoidTollBtnClicked();
break;
case ROUTE_TO:
onRouteToBtnClicked();
break;
case ROUTE_AVOID_UNPAVED:
onAvoidUnpavedBtnClicked();
break;
case ROUTE_ADD:
onRouteAddBtnClicked();
break;
case ROUTE_REMOVE:
onRouteRemoveBtnClicked();
break;
case ROUTE_AVOID_TOLL:
onAvoidTollBtnClicked();
break;
case ROUTE_AVOID_UNPAVED:
onAvoidUnpavedBtnClicked();
break;
case ROUTE_AVOID_FERRY:
onAvoidFerryBtnClicked();
break;
case CALL:
onCallBtnClicked(buttons);
break;
}
}
});
case ROUTE_AVOID_FERRY:
onAvoidFerryBtnClicked();
break;
}
}
private void onBookmarkBtnClicked()
@ -560,10 +541,10 @@ public class PlacePageView extends NestedScrollViewClickFixed
{
final Intent result = new Intent();
result.putExtra(Const.EXTRA_POINT_LAT, mMapObject.getLat())
.putExtra(Const.EXTRA_POINT_LON, mMapObject.getLon())
.putExtra(Const.EXTRA_POINT_NAME, mMapObject.getTitle())
.putExtra(Const.EXTRA_POINT_ID, mMapObject.getApiId())
.putExtra(Const.EXTRA_ZOOM_LEVEL, Framework.nativeGetDrawScale());
.putExtra(Const.EXTRA_POINT_LON, mMapObject.getLon())
.putExtra(Const.EXTRA_POINT_NAME, mMapObject.getTitle())
.putExtra(Const.EXTRA_POINT_ID, mMapObject.getApiId())
.putExtra(Const.EXTRA_ZOOM_LEVEL, Framework.nativeGetDrawScale());
requireActivity().setResult(Activity.RESULT_OK, result);
ParsedMwmRequest.setCurrentRequest(null);
}
@ -614,7 +595,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
return mPhoneAdapter.getPhonesList();
}
private void onCallBtnClicked(View parentView)
private void onCallBtnClicked()
{
final List<String> phones = getAllPhones();
if (phones.size() == 1)
@ -624,7 +605,8 @@ public class PlacePageView extends NestedScrollViewClickFixed
else
{
// Show popup menu with all phones
final PopupMenu popup = new PopupMenu(getContext(), parentView);
// TODO find a way to access the correct parent instead of mPreview
final PopupMenu popup = new PopupMenu(getContext(), mPreview);
final Menu menu = popup.getMenu();
for (int i = 0; i < phones.size(); i++)
@ -734,16 +716,13 @@ public class PlacePageView extends NestedScrollViewClickFixed
mMapObject = mapObject;
refreshViews();
if (listener != null)
{
listener.onSetMapObjectComplete(true);
}
if (mCurrentCountry == null)
setCurrentCountry();
return;
}
mMapObject = mapObject;
setMapObjectInternal();
if (listener != null)
listener.onSetMapObjectComplete(false);
@ -770,7 +749,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
attachCountry(country);
}
void refreshViews()
private void refreshViews()
{
if (mMapObject == null)
{
@ -785,32 +764,38 @@ public class PlacePageView extends NestedScrollViewClickFixed
private void refreshViewsInternal(@NonNull MapObject mapObject)
{
final Location loc = LocationHelper.INSTANCE.getSavedLocation();
boolean showBackButton = false;
boolean showRoutingButton = true;
switch (mapObject.getMapObjectType())
{
case MapObject.BOOKMARK:
refreshDistanceToObject(mapObject, loc);
showBookmarkDetails(mapObject);
updateBookmarkButton();
setButtons(mapObject, false, true);
break;
case MapObject.POI:
case MapObject.SEARCH:
refreshDistanceToObject(mapObject, loc);
hideBookmarkDetails();
setButtons(mapObject, false, true);
setPlaceDescription(mapObject);
break;
case MapObject.API_POINT:
refreshDistanceToObject(mapObject, loc);
hideBookmarkDetails();
setButtons(mapObject, true, true);
showBackButton = true;
break;
case MapObject.MY_POSITION:
refreshMyPosition(mapObject, loc);
hideBookmarkDetails();
setButtons(mapObject, false, false);
showRoutingButton = false;
break;
}
final boolean hasNumber = mapObject.hasPhoneNumber();
if (hasNumber)
mPhoneRecycler.setVisibility(VISIBLE);
else
mPhoneRecycler.setVisibility(GONE);
updateButtons(mapObject, showBackButton, showRoutingButton);
}
private Spanned getShortDescription(@NonNull MapObject mapObject)
@ -865,7 +850,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
{
sb.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.base_yellow)),
start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
mTvSubtitle.setText(sb);
}
@ -892,7 +876,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
String url = mapObject.getMetadata(Metadata.MetadataType.FMD_URL);
refreshMetadataOrHide(TextUtils.isEmpty(website) ? url : website, mWebsite, mTvWebsite);
String wikimedia_commons = mapObject.getMetadata(Metadata.MetadataType.FMD_WIKIMEDIA_COMMONS);
String wikimedia_commons_text = TextUtils.isEmpty(wikimedia_commons) ? "" : getResources().getString(R.string.wikimedia_commons);
String wikimedia_commons_text = TextUtils.isEmpty(wikimedia_commons) ? "" : getResources().getString(R.string.wikimedia_commons);
refreshMetadataOrHide(wikimedia_commons_text, mWikimedia, mTvWikimedia);
refreshPhoneNumberList(mapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
refreshMetadataOrHide(mapObject.getMetadata(Metadata.MetadataType.FMD_EMAIL), mEmail, mTvEmail);
@ -1015,7 +999,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
private void refreshTodayNonBusinessTime(Timespan[] closedTimespans)
{
final String hoursClosedLabel = getResources().getString(R.string.editor_hours_closed);
if (closedTimespans==null || closedTimespans.length == 0)
if (closedTimespans == null || closedTimespans.length == 0)
UiUtils.clearTextAndHide(mTodayNonBusinessTime);
else
UiUtils.setTextAndShow(mTodayNonBusinessTime, TimeFormatUtils.formatNonBusinessTime(closedTimespans, hoursClosedLabel));
@ -1107,15 +1091,25 @@ public class PlacePageView extends NestedScrollViewClickFixed
private void updateBookmarkButton()
{
if (mBookmarkButtonIcon == null || mBookmarkButtonFrame == null)
return;
final List<PlacePageButtons.ButtonType> currentButtons = viewModel.getCurrentButtons()
.getValue();
PlacePageButtons.ButtonType oldType = PlacePageButtons.ButtonType.BOOKMARK_DELETE;
PlacePageButtons.ButtonType newType = PlacePageButtons.ButtonType.BOOKMARK_SAVE;
if (mBookmarkSet)
mBookmarkButtonIcon.setImageDrawable(Graphics.tint(getContext(), R.drawable.ic_bookmarks_on, R.attr.iconTintActive));
else
mBookmarkButtonIcon.setImageDrawable(Graphics.tint(getContext(), R.drawable.ic_bookmarks_off, R.attr.iconTint));
mBookmarkButtonFrame.setEnabled(true);
{
oldType = PlacePageButtons.ButtonType.BOOKMARK_SAVE;
newType = PlacePageButtons.ButtonType.BOOKMARK_DELETE;
}
if (currentButtons != null)
{
final List<PlacePageButtons.ButtonType> newList = new ArrayList<>(currentButtons);
final int index = newList.indexOf(oldType);
if (index >= 0)
{
newList.set(index, newType);
viewModel.setCurrentButtons(newList);
}
}
}
private void hideBookmarkDetails()
@ -1156,76 +1150,50 @@ public class PlacePageView extends NestedScrollViewClickFixed
}
}
@NonNull
private static PlacePageButtons.Item toPlacePageButton(@NonNull RoadWarningMarkType type)
private void updateButtons(@NonNull MapObject mapObject, boolean showBackButton, boolean showRoutingButton)
{
switch (type)
{
case DIRTY:
return PlacePageButtons.Item.ROUTE_AVOID_UNPAVED;
case FERRY:
return PlacePageButtons.Item.ROUTE_AVOID_FERRY;
case TOLL:
return PlacePageButtons.Item.ROUTE_AVOID_TOLL;
default:
throw new AssertionError("Unsupported road warning type: " + type);
}
}
private void setButtons(@NonNull MapObject mapObject, boolean showBackButton, boolean showRoutingButton)
{
List<PlacePageButtons.PlacePageButton> buttons = new ArrayList<>();
List<PlacePageButtons.ButtonType> buttons = new ArrayList<>();
if (mapObject.getRoadWarningMarkType() != RoadWarningMarkType.UNKNOWN)
{
RoadWarningMarkType markType = mapObject.getRoadWarningMarkType();
PlacePageButtons.Item roadType = toPlacePageButton(markType);
PlacePageButtons.ButtonType roadType = toPlacePageButton(markType);
buttons.add(roadType);
mButtons.setItems(buttons);
return;
}
if (RoutingController.get().isRoutePoint(mapObject))
else if (RoutingController.get().isRoutePoint(mapObject))
{
buttons.add(PlacePageButtons.Item.ROUTE_REMOVE);
mButtons.setItems(buttons);
return;
}
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
if (showBackButton || (request != null && request.isPickPointMode()))
buttons.add(PlacePageButtons.Item.BACK);
final boolean hasNumber = mapObject.hasPhoneNumber();
if (hasNumber)
{
buttons.add(PlacePageButtons.Item.CALL);
mPhoneRecycler.setVisibility(VISIBLE);
buttons.add(PlacePageButtons.ButtonType.ROUTE_REMOVE);
}
else
mPhoneRecycler.setVisibility(GONE);
boolean needToShowRoutingButtons = RoutingController.get().isPlanning() || showRoutingButton;
if (needToShowRoutingButtons && !hasNumber)
buttons.add(PlacePageButtons.Item.ROUTE_FROM);
buttons.add(mapObject.getMapObjectType() == MapObject.BOOKMARK ? PlacePageButtons.Item.BOOKMARK_DELETE
: PlacePageButtons.Item.BOOKMARK_SAVE);
if (needToShowRoutingButtons)
{
buttons.add(PlacePageButtons.Item.ROUTE_TO);
if (hasNumber)
buttons.add(PlacePageButtons.Item.ROUTE_FROM);
if (RoutingController.get().isStopPointAllowed())
buttons.add(PlacePageButtons.Item.ROUTE_ADD);
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
if (showBackButton || (request != null && request.isPickPointMode()))
buttons.add(PlacePageButtons.ButtonType.BACK);
boolean needToShowRoutingButtons = RoutingController.get().isPlanning() || showRoutingButton;
if (needToShowRoutingButtons)
buttons.add(PlacePageButtons.ButtonType.ROUTE_FROM);
if (needToShowRoutingButtons && RoutingController.get().isStopPointAllowed())
buttons.add(PlacePageButtons.ButtonType.ROUTE_ADD);
else
buttons.add(mapObject.getMapObjectType() == MapObject.BOOKMARK
? PlacePageButtons.ButtonType.BOOKMARK_DELETE
: PlacePageButtons.ButtonType.BOOKMARK_SAVE);
if (needToShowRoutingButtons)
{
buttons.add(PlacePageButtons.ButtonType.ROUTE_TO);
if (!RoutingController.get().isStopPointAllowed())
buttons.add(PlacePageButtons.ButtonType.ROUTE_ADD);
else
buttons.add(mapObject.getMapObjectType() == MapObject.BOOKMARK
? PlacePageButtons.ButtonType.BOOKMARK_DELETE
: PlacePageButtons.ButtonType.BOOKMARK_SAVE);
}
buttons.add(PlacePageButtons.ButtonType.SHARE);
}
buttons.add(PlacePageButtons.Item.SHARE);
mButtons.setItems(buttons);
viewModel.setCurrentButtons(buttons);
}
public void refreshLocation(@NonNull Location l)
@ -1289,18 +1257,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
mTvLatlon.setText(latLon);
}
private static void refreshMetadataOrHide(String metadata, View metaLayout, TextView metaTv)
{
if (!TextUtils.isEmpty(metadata))
{
metaLayout.setVisibility(View.VISIBLE);
if (metaTv != null)
metaTv.setText(metadata);
}
else
metaLayout.setVisibility(View.GONE);
}
public void refreshAzimuth(double northAzimuth)
{
if (mMapObject == null || MapObject.isOfType(MapObject.MY_POSITION, mMapObject))
@ -1317,7 +1273,8 @@ public class PlacePageView extends NestedScrollViewClickFixed
mMapObject.getLon(),
location.getLatitude(),
location.getLongitude(),
northAzimuth).getAzimuth();
northAzimuth)
.getAzimuth();
UiUtils.showIf(azimuth >= 0, mAvDirection);
if (azimuth >= 0)
{
@ -1369,7 +1326,10 @@ public class PlacePageView extends NestedScrollViewClickFixed
{
final int formatIndex = visibleCoordsFormat.indexOf(mCoordsFormat);
mCoordsFormat = visibleCoordsFormat.get((formatIndex + 1) % visibleCoordsFormat.size());
MwmApplication.prefs(getContext()).edit().putInt(PREF_COORDINATES_FORMAT, mCoordsFormat.getId()).apply();
MwmApplication.prefs(getContext())
.edit()
.putInt(PREF_COORDINATES_FORMAT, mCoordsFormat.getId())
.apply();
if (mMapObject == null)
{
Logger.e(TAG, "A LatLon cannot be refreshed, mMapObject is null");
@ -1429,7 +1389,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
{
final FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
final DirectionFragment fragment = (DirectionFragment) fragmentManager.getFragmentFactory()
.instantiate(getContext().getClassLoader(), DirectionFragment.class.getName());
.instantiate(getContext().getClassLoader(), DirectionFragment.class.getName());
fragment.setMapObject(mMapObject);
fragment.show(fragmentManager, null);
}
@ -1527,8 +1487,8 @@ public class PlacePageView extends NestedScrollViewClickFixed
{
Utils.copyTextToClipboard(ctx, items.get(0));
Utils.showSnackbarAbove(mDetails,
getRootView().findViewById(R.id.pp_buttons_layout),
ctx.getString(R.string.copied_to_clipboard, items.get(0)));
getRootView().findViewById(R.id.pp_buttons_layout),
ctx.getString(R.string.copied_to_clipboard, items.get(0)));
}
else
{
@ -1543,8 +1503,8 @@ public class PlacePageView extends NestedScrollViewClickFixed
final int itemId = item.getItemId();
Utils.copyTextToClipboard(ctx, items.get(itemId));
Utils.showSnackbarAbove(mDetails,
getRootView().findViewById(R.id.pp_buttons_layout),
ctx.getString(R.string.copied_to_clipboard, items.get(itemId)));
getRootView().findViewById(R.id.pp_buttons_layout),
ctx.getString(R.string.copied_to_clipboard, items.get(itemId)));
return true;
});
popup.show();
@ -1564,16 +1524,6 @@ public class PlacePageView extends NestedScrollViewClickFixed
scrollTo(0, 0);
}
private static boolean isInvalidDownloaderStatus(int status)
{
return (status != CountryItem.STATUS_DOWNLOADABLE &&
status != CountryItem.STATUS_ENQUEUED &&
status != CountryItem.STATUS_FAILED &&
status != CountryItem.STATUS_PARTLY &&
status != CountryItem.STATUS_PROGRESS &&
status != CountryItem.STATUS_APPLYING);
}
private void updateDownloader(CountryItem country)
{
if (isInvalidDownloaderStatus(country.status))
@ -1588,7 +1538,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
StringBuilder sb = new StringBuilder(StringUtils.getFileSizeString(getContext(), country.totalSize));
if (country.isExpandable())
sb.append(StringUtils.formatUsingUsLocale(" • %s: %d", getContext().getString(R.string.downloader_status_maps),
country.totalChildCount));
country.totalChildCount));
mDownloaderInfo.setText(sb.toString());
}
@ -1655,10 +1605,24 @@ public class PlacePageView extends NestedScrollViewClickFixed
return mPreview.getHeight();
}
@Nullable
public ArrayList<MenuBottomSheetItem> getMenuBottomSheetItems()
public void setOnPlacePageContentChangeListener(OnPlacePageContentChangeListener onPlacePageContentChangeListener)
{
return mButtons.getMenuBottomSheetItems();
mOnPlacePageContentChangeListener = onPlacePageContentChangeListener;
}
public interface SetMapObjectListener
{
void onSetMapObjectComplete(boolean isSameObject);
}
interface OnPlacePageContentChangeListener
{
void OnPlacePageContentChange();
}
interface OnPlacePageRequestCloseListener
{
void onPlacePageRequestClose();
}
private class EditBookmarkClickListener implements OnClickListener
@ -1679,19 +1643,4 @@ public class PlacePageView extends NestedScrollViewClickFixed
PlacePageView.this);
}
}
public void setOnPlacePageContentChangeListener(OnPlacePageContentChangeListener onPlacePageContentChangeListener)
{
mOnPlacePageContentChangeListener = onPlacePageContentChangeListener;
}
interface OnPlacePageContentChangeListener
{
void OnPlacePageContentChange();
}
interface OnPlacePageRequestCloseListener
{
void onPlacePageRequestClose();
}
}