From c367139f6a082fc5f0eeefb704069e479a38daf6 Mon Sep 17 00:00:00 2001 From: xmd5a Date: Fri, 16 Mar 2018 10:37:59 +0300 Subject: [PATCH 1/4] Add phrase --- OsmAnd/res/values-ru/phrases.xml | 2 ++ OsmAnd/res/values/phrases.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/OsmAnd/res/values-ru/phrases.xml b/OsmAnd/res/values-ru/phrases.xml index 55d642f8da..4c0a5f4dde 100644 --- a/OsmAnd/res/values-ru/phrases.xml +++ b/OsmAnd/res/values-ru/phrases.xml @@ -3743,4 +3743,6 @@ Пункт выдачи заказов + Мангал: есть + diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index 2a9d4217de..f65dd93fcd 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -3763,4 +3763,6 @@ Shop\'s delivery point + Barbecue grill: yes + From 775bbe1e21d26a953c4debf3a771af8b77c5a113 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Mar 2018 14:22:32 +0200 Subject: [PATCH 2/4] Add the ability to set maximum height for bottom sheet menus --- .../plus/base/MenuBottomSheetDialogFragment.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index a80d28f5a7..e5536433dd 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -158,9 +158,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra final int screenHeight = AndroidUtils.getScreenHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); - final int availableHeight = screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity) - - AndroidUtils.dpToPx(getContext(), 1) // divider height - - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); // bottom row height + final int availableHeight = getAvailableHeight(screenHeight, statusBarHeight); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @@ -189,6 +187,18 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra }); } + private int getAvailableHeight(int screenHeight, int statusBarHeight) { + int maxHeight = getMaximumHeight(); + return maxHeight != -1 ? maxHeight + : screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(getContext()) + - AndroidUtils.dpToPx(getContext(), 1) // divider height + - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + } + + protected int getMaximumHeight() { + return -1; + } + protected boolean useScrollableItemsContainer() { return true; } From 4262e9aec751cc8343cf811d9e5cb690766a40cf Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Mar 2018 18:40:03 +0200 Subject: [PATCH 3/4] Add small refactoring to MenuBottomSheetDialogFragment --- .../base/MenuBottomSheetDialogFragment.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index e5536433dd..6ca1f973c3 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -32,6 +32,7 @@ import java.util.List; public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment { private static final String USED_ON_MAP_KEY = "used_on_map"; + private static final int DEFAULT_VALUE = -1; protected List items = new ArrayList<>(); @@ -75,7 +76,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } int bottomDividerColorId = getBottomDividerColorId(); - if (bottomDividerColorId != -1) { + if (bottomDividerColorId != DEFAULT_VALUE) { mainView.findViewById(R.id.bottom_row_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId)); } @@ -89,10 +90,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.dismiss_button_text)).setText(getDismissButtonTextId()); int rightBottomButtonTextId = getRightBottomButtonTextId(); - if (rightBottomButtonTextId != -1) { + if (rightBottomButtonTextId != DEFAULT_VALUE) { View buttonsDivider = mainView.findViewById(R.id.bottom_buttons_divider); buttonsDivider.setVisibility(View.VISIBLE); - if (bottomDividerColorId != -1) { + if (bottomDividerColorId != DEFAULT_VALUE) { buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId)); } View rightButton = mainView.findViewById(R.id.right_bottom_button); @@ -158,15 +159,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra final int screenHeight = AndroidUtils.getScreenHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); - final int availableHeight = getAvailableHeight(screenHeight, statusBarHeight); + final int contentHeight = getContentHeight(screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity)); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - final View viewToAdjust = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer; - if (viewToAdjust.getHeight() > availableHeight) { - viewToAdjust.getLayoutParams().height = availableHeight; - viewToAdjust.requestLayout(); + final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer; + if (contentView.getHeight() > contentHeight) { + contentView.getLayoutParams().height = contentHeight; + contentView.requestLayout(); } // 8dp is the shadow height @@ -187,16 +188,19 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra }); } - private int getAvailableHeight(int screenHeight, int statusBarHeight) { - int maxHeight = getMaximumHeight(); - return maxHeight != -1 ? maxHeight - : screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(getContext()) + private int getContentHeight(int availableScreenHeight) { + int customHeight = getCustomHeight(); + int maxHeight = availableScreenHeight - AndroidUtils.dpToPx(getContext(), 1) // divider height - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + if (customHeight != DEFAULT_VALUE && customHeight <= maxHeight) { + return customHeight; + } + return maxHeight; } - protected int getMaximumHeight() { - return -1; + protected int getCustomHeight() { + return DEFAULT_VALUE; } protected boolean useScrollableItemsContainer() { @@ -205,7 +209,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @ColorRes protected int getBottomDividerColorId() { - return -1; + return DEFAULT_VALUE; } @StringRes @@ -219,7 +223,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @StringRes protected int getRightBottomButtonTextId() { - return -1; + return DEFAULT_VALUE; } protected void onRightBottomButtonClick() { From da2c4824146073486d4ab3fe665be29a6ea33772 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Mar 2018 19:00:46 +0200 Subject: [PATCH 4/4] Make small refactoring in MapMarkersHelper --- .../net/osmand/plus/FavouritesDbHelper.java | 6 +-- .../net/osmand/plus/GpxSelectionHelper.java | 2 +- .../src/net/osmand/plus/MapMarkersHelper.java | 49 +++++++------------ .../EditFavoriteGroupDialogFragment.java | 2 +- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index a4a71c4efa..fd8d7c9b74 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -135,7 +135,7 @@ public class FavouritesDbHelper { flatGroups.remove(g.name); favoriteGroups.remove(g); cachedFavoritePoints.removeAll(g.points); - context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true); + context.getMapMarkersHelper().removeMarkersSyncGroup(g.name); } } saveCurrentPointsIntoFile(); @@ -352,7 +352,7 @@ public class FavouritesDbHelper { if (remove) { flatGroups.remove(group.name); saveCurrentPointsIntoFile(); - context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true); + context.getMapMarkersHelper().removeMarkersSyncGroup(group.name); return true; } return false; @@ -622,7 +622,7 @@ public class FavouritesDbHelper { } if (!group.name.equals(newName)) { FavoriteGroup gr = flatGroups.remove(group.name); - markersHelper.removeMarkersSyncGroup(group.name, true); + markersHelper.removeMarkersSyncGroup(group.name); gr.name = newName; FavoriteGroup renamedGroup = flatGroups.get(gr.name); boolean existing = renamedGroup != null; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 79e7211b27..0dc42d50a9 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -554,7 +554,7 @@ public class GpxSelectionHelper { if (show && !enabled) { mapMarkersHelper.addMarkersSyncGroup(syncGroup); } else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) { - mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true); + mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath()); } } mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback); diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 7feafe89d3..54dea59630 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; @@ -57,8 +56,8 @@ public class MapMarkersHelper { private ExecutorService executorService = Executors.newSingleThreadExecutor(); - private List mapMarkers = new LinkedList<>(); - private List mapMarkersHistory = new LinkedList<>(); + private List mapMarkers = new ArrayList<>(); + private List mapMarkersHistory = new ArrayList<>(); private List mapMarkersGroups = new ArrayList<>(); private List listeners = new ArrayList<>(); @@ -195,16 +194,6 @@ public class MapMarkersHelper { public static int getColorId(int colorIndex) { return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0]; } - - public static int getColorIndex(Context context, int color) { - int[] colors = getColors(context); - for (int i = 0; i < colors.length; i++) { - if (colors[i] == color) { - return i; - } - } - return -1; - } } @Nullable @@ -293,8 +282,8 @@ public class MapMarkersHelper { } private void loadMarkers() { - mapMarkers = new LinkedList<>(); - mapMarkersHistory = new LinkedList<>(); + mapMarkers = new ArrayList<>(); + mapMarkersHistory = new ArrayList<>(); List activeMarkers = markersDbHelper.getActiveMarkers(); addToMapMarkersList(activeMarkers); @@ -310,13 +299,13 @@ public class MapMarkersHelper { } private void removeFromMapMarkersList(List markers) { - List copyList = new LinkedList<>(mapMarkers); + List copyList = new ArrayList<>(mapMarkers); copyList.removeAll(markers); mapMarkers = copyList; } private void removeFromMapMarkersList(MapMarker marker) { - List copyList = new LinkedList<>(mapMarkers); + List copyList = new ArrayList<>(mapMarkers); copyList.remove(marker); mapMarkers = copyList; } @@ -326,7 +315,7 @@ public class MapMarkersHelper { } private void addToMapMarkersList(int position, MapMarker marker) { - List copyList = new LinkedList<>(mapMarkers); + List copyList = new ArrayList<>(mapMarkers); copyList.add(position, marker); mapMarkers = copyList; } @@ -336,13 +325,13 @@ public class MapMarkersHelper { } private void addToMapMarkersList(int position, List markers) { - List copyList = new LinkedList<>(mapMarkers); + List copyList = new ArrayList<>(mapMarkers); copyList.addAll(position, markers); mapMarkers = copyList; } private void removeFromMapMarkersHistoryList(MapMarker marker) { - List copyList = new LinkedList<>(mapMarkersHistory); + List copyList = new ArrayList<>(mapMarkersHistory); copyList.remove(marker); mapMarkersHistory = copyList; } @@ -352,13 +341,13 @@ public class MapMarkersHelper { } private void addToMapMarkersHistoryList(int position, MapMarker marker) { - List copyList = new LinkedList<>(mapMarkersHistory); + List copyList = new ArrayList<>(mapMarkersHistory); copyList.add(position, marker); mapMarkersHistory = copyList; } private void addToMapMarkersHistoryList(int position, List markers) { - List copyList = new LinkedList<>(mapMarkersHistory); + List copyList = new ArrayList<>(mapMarkersHistory); copyList.addAll(position, markers); mapMarkersHistory = copyList; } @@ -562,7 +551,7 @@ public class MapMarkersHelper { return; } - List gpxPoints = new LinkedList<>(gpx.getPoints()); + List gpxPoints = new ArrayList<>(gpx.getPoints()); int defColor = ContextCompat.getColor(ctx, R.color.marker_red); for (WptPt pt : gpxPoints) { group.setColor(pt.getColor(defColor)); @@ -831,7 +820,7 @@ public class MapMarkersHelper { } public void addSelectedMarkersToTop(@NonNull List markers) { - List markersToRemove = new LinkedList<>(); + List markersToRemove = new ArrayList<>(); for (MapMarker m : mapMarkers) { if (m.selected) { if (!markers.contains(m)) { @@ -891,7 +880,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; } addToMapMarkersHistoryList(mapMarkers); - mapMarkers = new LinkedList<>(); + mapMarkers = new ArrayList<>(); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); updateGroups(); refresh(); @@ -900,7 +889,7 @@ public class MapMarkersHelper { public void removeMarkersHistory() { cancelAddressRequests(); markersDbHelper.clearAllMarkersHistory(); - mapMarkersHistory = new LinkedList<>(); + mapMarkersHistory = new ArrayList<>(); refresh(); removeHistoryMarkersFromGroups(); } @@ -913,12 +902,10 @@ public class MapMarkersHelper { } } - public void removeMarkersSyncGroup(String id, boolean removeActiveMarkers) { + public void removeMarkersSyncGroup(String id) { if (id != null) { markersDbHelper.removeMarkersSyncGroup(id); - if (removeActiveMarkers) { - removeActiveMarkersFromSyncGroup(id); - } + removeActiveMarkersFromSyncGroup(id); MapMarkersGroup group = getMapMarkerGroupByKey(id); if (group != null) { removeFromGroupsList(group); @@ -963,7 +950,7 @@ public class MapMarkersHelper { public void removeActiveMarkersFromSyncGroup(String syncGroupId) { if (syncGroupId != null) { markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId); - List copyList = new LinkedList<>(mapMarkers); + List copyList = new ArrayList<>(mapMarkers); for (int i = 0; i < copyList.size(); i++) { MapMarker marker = copyList.get(i); String groupKey = marker.groupKey; diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index 28ed92ce04..435d360211 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -189,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true); + markersHelper.removeMarkersSyncGroup(syncGroup.getId()); dismiss(); MapActivity.launchMapActivityMoveToTop(getActivity()); }