From c9872197dd8c7402a22ac0a9b02158c6a143d2df Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 27 Mar 2019 17:34:10 +0200 Subject: [PATCH 01/50] Add horizontal scroll bottom sheet item --- .../layout/bottom_sheet_item_recyclerview.xml | 19 ++ OsmAnd/res/layout/plan_route_info.xml | 2 +- OsmAnd/res/layout/warning_card.xml | 2 +- .../net/osmand/plus/FavouritesDbHelper.java | 1 + OsmAnd/src/net/osmand/plus/UiUtilities.java | 2 +- .../HorizontalRecyclerBottomSheetItem.java | 65 ++++ .../net/osmand/plus/helpers/GpxUiHelper.java | 5 +- .../AddPointBottomSheetDialog.java | 282 ++++++++++++++++-- .../MapRouteInfoMenu.java | 29 +- .../cards/HomeWorkCard.java | 18 +- .../cards/WarningCard.java | 16 +- 11 files changed, 359 insertions(+), 82 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_recyclerview.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_recyclerview.xml b/OsmAnd/res/layout/bottom_sheet_item_recyclerview.xml new file mode 100644 index 0000000000..5ea98b5a1f --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_recyclerview.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/OsmAnd/res/layout/plan_route_info.xml b/OsmAnd/res/layout/plan_route_info.xml index 7554053368..db3e5f2c53 100644 --- a/OsmAnd/res/layout/plan_route_info.xml +++ b/OsmAnd/res/layout/plan_route_info.xml @@ -71,7 +71,7 @@ android:paddingLeft="@dimen/route_info_icon_padding_right" android:paddingRight="@dimen/route_info_icon_padding_right" android:src="@drawable/ic_action_arrow_down" - android:tint="?attr/primary_icon_color" /> + android:tint="@color/description_font_and_bottom_sheet_icons" /> diff --git a/OsmAnd/res/layout/warning_card.xml b/OsmAnd/res/layout/warning_card.xml index 95df7fb73d..9ea416e570 100644 --- a/OsmAnd/res/layout/warning_card.xml +++ b/OsmAnd/res/layout/warning_card.xml @@ -1,7 +1,7 @@ diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 3b406007f5..732129ce0c 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -43,6 +43,7 @@ public class FavouritesDbHelper { public static final String BACKUP_FOLDER = "backup"; //$NON-NLS-1$ public static final int BACKUP_CNT = 20; //$NON-NLS-1$ public static final String FILE_TO_BACKUP = "favourites_bak.gpx"; //$NON-NLS-1$ + public static final String FAVOURITES = "favourites"; //$NON-NLS-1$ private List cachedFavoritePoints = new ArrayList(); private List favoriteGroups = new ArrayList(); diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index c33b13cd52..36d70cca4e 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -80,7 +80,7 @@ public class UiUtilities { } public Drawable getThemedIcon(@DrawableRes int id) { - return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0); + return getDrawable(id, R.color.description_font_and_bottom_sheet_icons); } public Drawable getIcon(@DrawableRes int id) { diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java new file mode 100644 index 0000000000..76e3d835ac --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java @@ -0,0 +1,65 @@ +package net.osmand.plus.base.bottomsheetmenu; + +import android.support.annotation.LayoutRes; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +public class HorizontalRecyclerBottomSheetItem extends BaseBottomSheetItem { + + protected RecyclerView.Adapter adapter; + + private RecyclerView recyclerView; + + public HorizontalRecyclerBottomSheetItem(View customView, + @LayoutRes int layoutId, + Object tag, + boolean disabled, + View.OnClickListener onClickListener, + int position, + RecyclerView.Adapter adapter) { + super(customView, layoutId, tag, disabled, onClickListener, position); + this.adapter = adapter; + } + + protected HorizontalRecyclerBottomSheetItem() { + + } + + public void setAdapter(RecyclerView.Adapter adapter) { + this.adapter = adapter; + recyclerView.setAdapter(adapter); + } + + @Override + public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { + super.inflate(app, container, nightMode); + recyclerView = ((RecyclerView) view.findViewById(R.id.recycler_view)); + if (recyclerView != null && adapter != null) { + recyclerView.setAdapter(adapter); + } + } + + public static class Builder extends BaseBottomSheetItem.Builder { + + protected RecyclerView.Adapter adapter; + + public HorizontalRecyclerBottomSheetItem.Builder setAdapter(RecyclerView.Adapter adapter) { + this.adapter = adapter; + return this; + } + + public HorizontalRecyclerBottomSheetItem create() { + return new HorizontalRecyclerBottomSheetItem(customView, + layoutId, + tag, + disabled, + onClickListener, + position, + adapter); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 8d97b14044..b7da4cd6ea 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -1257,8 +1257,9 @@ public class GpxUiHelper { chart.setExtraRightOffset(16); chart.setExtraLeftOffset(16); - yl.setTextColor(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)); - yr.setTextColor(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)); + int mainFontColor = ContextCompat.getColor(app, nightMode ? R.color.main_font_dark : R.color.main_font_light); + yl.setTextColor(mainFontColor); + yr.setTextColor(mainFontColor); chart.setFitBars(true); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 17dec9edd5..10dfa3eef7 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -1,27 +1,37 @@ package net.osmand.plus.routepreparationmenu; +import android.app.Activity; import android.content.Intent; +import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.FragmentManager; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; import android.text.SpannableString; +import android.util.Pair; import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; -import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; @@ -33,10 +43,9 @@ import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.widgets.style.CustomTypefaceSpan; +import java.util.ArrayList; import java.util.List; -import static net.osmand.data.PointDescription.POINT_TYPE_MY_LOCATION; - public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { public static final String TAG = "AddPointBottomSheetDialog"; @@ -81,27 +90,27 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { case START: createMyLocItem(); createSelectOnTheMapItem(); - createFavouritesItem(); + createFavouritesScrollItem(); createMarkersItem(); items.add(new DividerHalfItem(getContext())); createSwitchStartAndEndItem(); break; case TARGET: createSelectOnTheMapItem(); - createFavouritesItem(); + createFavouritesScrollItem(); createMarkersItem(); items.add(new DividerHalfItem(getContext())); createSwitchStartAndEndItem(); break; case INTERMEDIATE: createSelectOnTheMapItem(); - createFavouritesItem(); + createFavouritesScrollItem(); createMarkersItem(); break; case HOME: case WORK: createSelectOnTheMapItem(); - createFavouritesItem(); + createFavouritesScrollItem(); createMarkersItem(); break; default: @@ -245,30 +254,6 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { items.add(selectOnTheMapItem); } - private void createFavouritesItem() { - BaseBottomSheetItem favouritesItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_fav_dark)) - .setTitle(getString(R.string.shared_string_favorites)) - .setLayoutId(R.layout.bottom_sheet_item_simple_56dp) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MapActivity mapActivity = (MapActivity) getActivity(); - if (mapActivity != null) { - FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); - FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment(); - Bundle args = new Bundle(); - args.putString(FavouritesBottomSheetMenuFragment.POINT_TYPE_KEY, pointType.name()); - fragment.setTargetFragment(AddPointBottomSheetDialog.this, ADD_FAVOURITE_TO_ROUTE_REQUEST_CODE); - fragment.setArguments(args); - fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG); - } - } - }) - .create(); - items.add(favouritesItem); - } - private void createMarkersItem() { final OsmandApplication app = getMyApplication(); if (app == null) { @@ -352,4 +337,239 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { }).create(); items.add(switchStartAndEndItem); } + + private void loadFavoritesItems(List items, FavouritesDbHelper helper) { + items.clear(); + addMainScrollItems(items); + items.addAll(helper.getVisibleFavouritePoints()); + if (items.isEmpty()) { + items.addAll(helper.getFavouritePoints()); + } + } + + private void addMainScrollItems(List items) { + items.add(FavouritesDbHelper.FAVOURITES); + items.add(PointType.HOME); + items.add(PointType.WORK); + } + + private void createFavouritesScrollItem() { + final OsmandApplication app = getMyApplication(); + if (app != null) { + List items = new ArrayList<>(); + final FavouritesItemsAdapter adapter = new FavouritesItemsAdapter(app, items); + adapter.setItemClickListener(getAdapterOnClickListener(items)); + final FavouritesDbHelper helper = app.getFavorites(); + if (helper.isFavoritesLoaded()) { + loadFavoritesItems(items, helper); + } else { + addMainScrollItems(items); + helper.addListener(new FavouritesDbHelper.FavoritesListener() { + @Override + public void onFavoritesLoaded() { + MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity != null) { + loadFavoritesItems(adapter.items, helper); + adapter.notifyDataSetChanged(); + } + } + }); + } + BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder() + .setAdapter(adapter) + .setLayoutId(R.layout.bottom_sheet_item_recyclerview) + .create(); + this.items.add(scrollItem); + } + } + + private View.OnClickListener getAdapterOnClickListener(final List items) { + return new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = (MapActivity) getActivity(); + RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) v.getTag(); + int position = viewHolder != null ? viewHolder.getAdapterPosition() : RecyclerView.NO_POSITION; + if (mapActivity == null || position == RecyclerView.NO_POSITION) { + return; + } + Object item = items.get(position); + if (item.equals(FavouritesDbHelper.FAVOURITES)) { + openFavouritesDialog(); + } else { + TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper(); + Pair pair = getLocationAndDescrFromItem(item, helper); + LatLon ll = pair.first; + PointDescription name = pair.second; + if (ll != null) { + switch (pointType) { + case START: + helper.setStartPoint(ll, true, name); + break; + case TARGET: + helper.navigateToPoint(ll, true, -1, name); + break; + case INTERMEDIATE: + helper.navigateToPoint(ll, true, helper.getIntermediatePoints().size(), name); + break; + } + } else if (item instanceof PointType) { + AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item); + } + } + } + }; + } + + private Pair getLocationAndDescrFromItem(Object item, TargetPointsHelper helper) { + PointDescription name = null; + LatLon ll = null; + if (item instanceof FavouritePoint) { + FavouritePoint point = (FavouritePoint) item; + ll = new LatLon(point.getLatitude(), point.getLongitude()); + name = point.getPointDescription(); + } else if (item instanceof PointType) { + TargetPointsHelper.TargetPoint point = null; + if (item == PointType.HOME) { + point = helper.getHomePoint(); + } else if (item == PointType.WORK) { + point = helper.getHomePoint(); + } + if (point != null) { + ll = new LatLon(point.getLatitude(), point.getLongitude()); + name = point.getOriginalPointDescription(); + } + } + return new Pair<>(ll, name); + } + + private void openFavouritesDialog() { + MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity != null) { + FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); + FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment(); + Bundle args = new Bundle(); + args.putString(FavouritesBottomSheetMenuFragment.POINT_TYPE_KEY, pointType.name()); + fragment.setTargetFragment(AddPointBottomSheetDialog.this, ADD_FAVOURITE_TO_ROUTE_REQUEST_CODE); + fragment.setArguments(args); + fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG); + } + } + + public static boolean showInstance(@NonNull MapActivity mapActivity, PointType pointType) { + return showInstance(mapActivity, pointType, true); + } + + public static boolean showInstance(@NonNull MapActivity mapActivity, PointType pointType, boolean usedOnMap) { + try { + if (mapActivity.isActivityDestroyed()) { + return false; + } + Bundle args = new Bundle(); + args.putString(AddPointBottomSheetDialog.POINT_TYPE_KEY, pointType.name()); + AddPointBottomSheetDialog fragment = new AddPointBottomSheetDialog(); + fragment.setArguments(args); + fragment.setUsedOnMap(usedOnMap); + fragment.show(mapActivity.getSupportFragmentManager(), TAG); + return true; + } catch (RuntimeException e) { + return false; + } + } + + public class FavouritesItemsAdapter extends RecyclerView.Adapter { + + private final List items; + private OsmandApplication app; + private View.OnClickListener listener; + + public FavouritesItemsAdapter(OsmandApplication app, List items) { + this.app = app; + this.items = items; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.bottom_sheet_item_with_descr_56dp, viewGroup, false); + view.setOnClickListener(listener); + Activity activity = getActivity(); + if (activity != null) { + RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); + layoutParams.width = AndroidUtils.getScreenWidth(activity) / 2; + view.setLayoutParams(layoutParams); + } + FavouritesViewHolder viewHolder = new FavouritesViewHolder(view); + view.setTag(viewHolder); + + return viewHolder; + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof FavouritesViewHolder) { + Object item = getItem(position); + FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder; + if (item.equals(FavouritesDbHelper.FAVOURITES)) { + favouritesViewHolder.title.setText(R.string.shared_string_favorites); + favouritesViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark)); + favouritesViewHolder.description.setVisibility(View.GONE); + } else { + if (item instanceof PointType) { + final TargetPointsHelper helper = app.getTargetPointsHelper(); + TargetPointsHelper.TargetPoint point = null; + if (item == PointType.HOME) { + point = helper.getHomePoint(); + favouritesViewHolder.title.setText(getString(R.string.home_button)); + favouritesViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_home_dark)); + } else if (item == PointType.WORK) { + point = helper.getWorkPoint(); + favouritesViewHolder.title.setText(getString(R.string.work_button)); + favouritesViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_work)); + } + favouritesViewHolder.description.setText(point != null ? point.getPointDescription(app).getSimpleName(app, false) : getString(R.string.shared_string_add)); + } else if (item instanceof FavouritePoint) { + FavouritePoint point = (FavouritePoint) getItem(position); + favouritesViewHolder.title.setText(point.getName()); + if (point.getCategory().equals("")) { + favouritesViewHolder.description.setText(R.string.shared_string_favorites); + } else { + favouritesViewHolder.description.setText(point.getCategory()); + } + int pointColor = point.getColor(); + int color = pointColor == 0 || pointColor == Color.BLACK ? ContextCompat.getColor(app, R.color.color_favorite) : pointColor; + favouritesViewHolder.icon.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_fav_dark, color)); + } + favouritesViewHolder.description.setVisibility(View.VISIBLE); + } + } + } + + @Override + public int getItemCount() { + return items.size(); + } + + private Object getItem(int position) { + return items.get(position); + } + + public void setItemClickListener(View.OnClickListener listener) { + this.listener = listener; + } + + class FavouritesViewHolder extends RecyclerView.ViewHolder { + + final TextView title; + final TextView description; + final ImageView icon; + + public FavouritesViewHolder(View itemView) { + super(itemView); + title = (TextView) itemView.findViewById(R.id.title); + description = (TextView) itemView.findViewById(R.id.description); + icon = (ImageView) itemView.findViewById(R.id.icon); + } + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 3ce85903bb..16a11998a7 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -5,7 +5,6 @@ import android.content.DialogInterface.OnDismissListener; import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.Build; -import android.os.Bundle; import android.os.Handler; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; @@ -1248,6 +1247,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener container.findViewById(R.id.title_divider).setVisibility(View.GONE); } routeOptionTV.setText(title); + routeOptionTV.setTextColor(ContextCompat.getColor(app, R.color.description_font_and_bottom_sheet_icons)); routeOptionImageView.setImageDrawable(app.getUIUtilities().getIcon(iconId, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); container.setOnClickListener(listener); @@ -1369,7 +1369,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener toLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - openAddPointDialog(PointType.TARGET); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.TARGET); + } } }); @@ -1400,9 +1403,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener toButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - OsmandApplication app = getApp(); - if (app != null) { - openAddPointDialog(app.getTargetPointsHelper().getPointToNavigate() == null ? PointType.TARGET : PointType.INTERMEDIATE); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + AddPointBottomSheetDialog.showInstance(mapActivity, mapActivity.getMyApplication().getTargetPointsHelper().getPointToNavigate() == null ? PointType.TARGET : PointType.INTERMEDIATE); } } }); @@ -1443,7 +1446,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener fromLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - openAddPointDialog(PointType.START); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.START); + } } }); @@ -1659,17 +1665,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } } - private void openAddPointDialog(PointType pointType) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - Bundle args = new Bundle(); - args.putString(AddPointBottomSheetDialog.POINT_TYPE_KEY, pointType.name()); - AddPointBottomSheetDialog fragment = new AddPointBottomSheetDialog(); - fragment.setArguments(args); - fragment.show(mapActivity.getSupportFragmentManager(), AddPointBottomSheetDialog.TAG); - } - } - private boolean isLight() { return !nightMode; } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java index 6fe244b643..0f77e5d3f4 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java @@ -1,6 +1,5 @@ package net.osmand.plus.routepreparationmenu.cards; -import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -40,7 +39,7 @@ public class HomeWorkCard extends BaseCard { @Override public void onClick(View v) { if (homePoint == null) { - openAddPointDialog(mapActivity, true); + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME); } else { targetPointsHelper.navigateToPoint(homePoint.point, true, -1, homePoint.getOriginalPointDescription()); } @@ -49,7 +48,7 @@ public class HomeWorkCard extends BaseCard { homeButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - openAddPointDialog(mapActivity, true); + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME); return true; } }); @@ -59,7 +58,7 @@ public class HomeWorkCard extends BaseCard { @Override public void onClick(View v) { if (workPoint == null) { - openAddPointDialog(mapActivity, false); + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK); } else { targetPointsHelper.navigateToPoint(workPoint.point, true, -1, workPoint.getOriginalPointDescription()); } @@ -68,18 +67,9 @@ public class HomeWorkCard extends BaseCard { workButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - openAddPointDialog(mapActivity, false); + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK); return true; } }); } - - private void openAddPointDialog(MapActivity mapActivity, boolean home) { - Bundle args = new Bundle(); - args.putString(AddPointBottomSheetDialog.POINT_TYPE_KEY, home ? PointType.HOME.name() : PointType.WORK.name()); - AddPointBottomSheetDialog fragment = new AddPointBottomSheetDialog(); - fragment.setArguments(args); - fragment.setUsedOnMap(true); - fragment.show(mapActivity.getSupportFragmentManager(), AddPointBottomSheetDialog.TAG); - } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java index 45e36c9e7d..9f4bff7845 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java @@ -2,9 +2,7 @@ package net.osmand.plus.routepreparationmenu.cards; import android.graphics.Typeface; import android.net.Uri; -import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; import android.text.SpannableString; import android.text.Spanned; import android.text.TextPaint; @@ -78,7 +76,7 @@ public class WarningCard extends BaseCard { @Override public void onClick(@NonNull View widget) { - openAddPointDialog(); + AddPointBottomSheetDialog.showInstance(mapActivity, PointType.INTERMEDIATE); } }; text.setSpan(clickableSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); @@ -88,16 +86,4 @@ public class WarningCard extends BaseCard { warningDescr.setText(text); } } - - private void openAddPointDialog() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - Bundle args = new Bundle(); - args.putString(AddPointBottomSheetDialog.POINT_TYPE_KEY, PointType.INTERMEDIATE.name()); - AddPointBottomSheetDialog fragment = new AddPointBottomSheetDialog(); - fragment.setArguments(args); - fragment.setUsedOnMap(true); - fragment.show(mapActivity.getSupportFragmentManager(), AddPointBottomSheetDialog.TAG); - } - } } \ No newline at end of file From 2ecb5ec4ce99d20927774b344d6ff6bedcbc47cd Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 27 Mar 2019 17:39:37 +0200 Subject: [PATCH 02/50] Dismiss bottomsheet after choosing location --- .../AddPointBottomSheetDialog.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 10dfa3eef7..0c4b3c9e2b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -401,7 +401,13 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { Pair pair = getLocationAndDescrFromItem(item, helper); LatLon ll = pair.first; PointDescription name = pair.second; - if (ll != null) { + if (ll == null) { + if (item instanceof PointType) { + AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item); + } else { + dismiss(); + } + } else { switch (pointType) { case START: helper.setStartPoint(ll, true, name); @@ -413,8 +419,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { helper.navigateToPoint(ll, true, helper.getIntermediatePoints().size(), name); break; } - } else if (item instanceof PointType) { - AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item); + dismiss(); } } } From 9c4f9a7f88e57f3fc0d65be62c641e3f775a0d1f Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 27 Mar 2019 18:34:39 +0200 Subject: [PATCH 03/50] Fix scroll item width in landscape --- .../routepreparationmenu/AddPointBottomSheetDialog.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 0c4b3c9e2b..35ea32021e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -16,6 +16,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -35,6 +36,7 @@ import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.helpers.WaypointDialogHelper; @@ -501,7 +503,12 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { Activity activity = getActivity(); if (activity != null) { RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); - layoutParams.width = AndroidUtils.getScreenWidth(activity) / 2; + if (AndroidUiHelper.isOrientationPortrait(getActivity())) { + layoutParams.width = AndroidUtils.getScreenWidth(activity) / 2; + } else { + // 11.5dp is the shadow width + layoutParams.width = (getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width) / 2) - AndroidUtils.dpToPx(activity, 11.5f); + } view.setLayoutParams(layoutParams); } FavouritesViewHolder viewHolder = new FavouritesViewHolder(view); From a17db4daceb2fd523731f6452ff83a021a323d6c Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 27 Mar 2019 18:41:39 +0200 Subject: [PATCH 04/50] Fix item margin --- OsmAnd/res/layout/bottom_sheet_double_item.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_double_item.xml b/OsmAnd/res/layout/bottom_sheet_double_item.xml index af9d8a73fe..6fc30d0a85 100644 --- a/OsmAnd/res/layout/bottom_sheet_double_item.xml +++ b/OsmAnd/res/layout/bottom_sheet_double_item.xml @@ -78,9 +78,9 @@ android:layout_height="@dimen/standard_icon_size" android:layout_gravity="center_vertical" android:layout_marginEnd="@dimen/bottom_sheet_icon_margin" - android:layout_marginLeft="@dimen/bottom_sheet_content_margin_small" + android:layout_marginLeft="@dimen/content_padding" android:layout_marginRight="@dimen/bottom_sheet_icon_margin" - android:layout_marginStart="@dimen/bottom_sheet_content_margin_small" + android:layout_marginStart="@dimen/content_padding" tools:src="@drawable/ic_action_info_dark" /> Date: Wed, 27 Mar 2019 19:56:07 +0300 Subject: [PATCH 05/50] Route preparation / details UI fixes --- OsmAnd/res/layout/context_menu_top_shadow.xml | 15 + OsmAnd/res/layout/plan_route_info.xml | 32 +- OsmAnd/res/layout/route_info_layout.xml | 9 +- OsmAnd/res/layout/route_info_statistic.xml | 10 +- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/sizes.xml | 1 + OsmAnd/res/values/styles.xml | 2 + .../osmand/plus/base/ContextMenuFragment.java | 172 ++-- .../ChooseRouteFragment.java | 34 +- .../MapRouteInfoMenu.java | 62 +- .../MapRouteInfoMenuFragment.java | 793 ++++-------------- .../RouteDetailsFragment.java | 92 +- .../cards/PublicTransportCard.java | 21 +- .../cards/RouteStatisticCard.java | 46 +- .../cards/SimpleRouteCard.java | 10 +- .../osmand/plus/views/MapControlsLayer.java | 13 +- 16 files changed, 482 insertions(+), 831 deletions(-) create mode 100644 OsmAnd/res/layout/context_menu_top_shadow.xml diff --git a/OsmAnd/res/layout/context_menu_top_shadow.xml b/OsmAnd/res/layout/context_menu_top_shadow.xml new file mode 100644 index 0000000000..b500a81cf4 --- /dev/null +++ b/OsmAnd/res/layout/context_menu_top_shadow.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/plan_route_info.xml b/OsmAnd/res/layout/plan_route_info.xml index 7554053368..56e18a36df 100644 --- a/OsmAnd/res/layout/plan_route_info.xml +++ b/OsmAnd/res/layout/plan_route_info.xml @@ -12,19 +12,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - + @@ -79,6 +69,7 @@ android:id="@+id/app_modes_options_container" android:layout_width="wrap_content" android:layout_height="match_parent" + android:background="@color/color_transparent" android:layout_gravity="end"> + tools:text="Intermediate point" /> @@ -378,7 +369,7 @@ android:singleLine="true" android:textColor="?attr/main_font_color_basic" android:textSize="@dimen/default_list_text_size" - tools:text="Destination"/> + tools:text="Destination" /> @@ -527,22 +518,22 @@ android:id="@+id/bottom_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:foregroundGravity="top|fill_horizontal" - android:foreground="@drawable/bg_contextmenu_shadow"> + android:foreground="@drawable/bg_contextmenu_shadow" + android:foregroundGravity="top|fill_horizontal"> + android:background="?attr/activity_background_basic"> + android:paddingBottom="30dp"> @@ -582,6 +573,7 @@ android:orientation="vertical"> + + + android:layout_height="match_parent" + android:background="?attr/route_info_bg"> + android:paddingBottom="24dp"> diff --git a/OsmAnd/res/layout/route_info_statistic.xml b/OsmAnd/res/layout/route_info_statistic.xml index c439ed1f3e..917816fed9 100644 --- a/OsmAnd/res/layout/route_info_statistic.xml +++ b/OsmAnd/res/layout/route_info_statistic.xml @@ -5,7 +5,6 @@ android:id="@+id/route_info_details_card" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/card_and_list_background_basic" android:orientation="vertical"> + android:paddingTop="@dimen/route_info_details_padding" + android:paddingBottom="@dimen/route_info_details_padding"> + diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 87d3b0a278..a5afeda640 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -1,6 +1,7 @@ + 16dp 60dp 72dp 120dp diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 669fa381cc..e586ea2772 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -244,6 +244,7 @@ @color/main_font_light @color/active_buttons_and_links_light @color/card_and_list_background_light + @color/activity_background_light