From ab1614b90e83636f00b055d94ef2a1f98f56489e Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 23 Feb 2018 16:11:06 +0200 Subject: [PATCH] Fix map markers sorting --- ...nt_marker_order_by_bottom_sheet_dialog.xml | 144 ++++++++++++------ OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/MapMarkersHelper.java | 72 +++++---- .../src/net/osmand/plus/OsmandSettings.java | 36 ----- .../mapmarkers/MapMarkersActiveFragment.java | 2 - .../mapmarkers/MapMarkersDialogFragment.java | 30 ++-- .../OrderByBottomSheetDialogFragment.java | 100 ++++++------ .../plus/mapmarkers/PlanRouteFragment.java | 1 - 8 files changed, 200 insertions(+), 187 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml index db93b04e55..617d985df1 100644 --- a/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml @@ -1,11 +1,12 @@ - + - - - - - - - + android:paddingStart="@dimen/content_padding"> + + + + + + + + + + + + + + + + + + + android:paddingStart="@dimen/content_padding"> + android:textAppearance="@style/TextAppearance.ListItemTitle" + tools:text="Date added (Ascendingly)"/> + android:paddingStart="@dimen/content_padding"> + android:textAppearance="@style/TextAppearance.ListItemTitle" + tools:text="Date added (Descendingly)"/> @@ -173,4 +221,4 @@ android:textStyle="bold"/> - \ No newline at end of file + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 52597b3719..d8a54c0dc3 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Distance: farthest first + Distance: nearest first Enter longitude Enter latitude Enter latitude and longitude diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index f0d32692e3..c2c5e77418 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -2,6 +2,7 @@ package net.osmand.plus; import android.content.Context; import android.os.AsyncTask; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; @@ -15,13 +16,14 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.io.File; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -35,17 +37,33 @@ import java.util.concurrent.Executors; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; public class MapMarkersHelper { + public static final int MAP_MARKERS_COLORS_COUNT = 7; + public static final int BY_NAME = 0; + public static final int BY_DISTANCE_DESC = 1; + public static final int BY_DISTANCE_ASC = 2; + public static final int BY_DATE_ADDED_DESC = 3; + public static final int BY_DATE_ADDED_ASC = 4; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({BY_NAME, BY_DISTANCE_DESC, BY_DISTANCE_ASC, BY_DATE_ADDED_DESC, BY_DATE_ADDED_ASC}) + public @interface MapMarkersSortByDef { + } + + private OsmandApplication ctx; + private OsmandSettings settings; + private MapMarkersDbHelper markersDbHelper; + + private ExecutorService executorService = Executors.newSingleThreadExecutor(); + private List mapMarkers = new LinkedList<>(); private List mapMarkersHistory = new LinkedList<>(); private List mapMarkersGroups = new ArrayList<>(); - private OsmandSettings settings; + private List listeners = new ArrayList<>(); - private OsmandApplication ctx; - private MapMarkersDbHelper markersDbHelper; + private boolean startFromMyLocation; - private ExecutorService executorService = Executors.newSingleThreadExecutor(); private MarkersPlanRouteContext planRouteContext; @@ -283,7 +301,7 @@ public class MapMarkersHelper { reorderActiveMarkersIfNeeded(); List markersHistory = markersDbHelper.getMarkersHistory(); - sortMarkers(markersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(markersHistory, true, BY_DATE_ADDED_DESC); addToMapMarkersHistoryList(markersHistory); if (!ctx.isApplicationInitializing()) { @@ -385,34 +403,34 @@ public class MapMarkersHelper { } } - public void sortMarkers(List markers, final boolean visited, final MapMarkersOrderByMode orderByMode) { - sortMarkers(markers, visited, orderByMode, null); + private void sortMarkers(List markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) { + sortMarkers(markers, visited, sortByMode, null); } - public void sortMarkers(List markers, final boolean visited, - final MapMarkersOrderByMode orderByMode, @Nullable final LatLon location) { + private void sortMarkers(List markers, final boolean visited, + final @MapMarkersSortByDef int sortByMode, @Nullable final LatLon location) { Collections.sort(markers, new Comparator() { @Override public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - if (orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { + if (sortByMode == BY_DATE_ADDED_DESC || sortByMode == BY_DATE_ADDED_ASC) { long t1 = visited ? mapMarker1.visitedDate : mapMarker1.creationDate; long t2 = visited ? mapMarker2.visitedDate : mapMarker2.creationDate; if (t1 > t2) { - return orderByMode.isDateAddedDescending() ? -1 : 1; + return sortByMode == BY_DATE_ADDED_DESC ? -1 : 1; } else if (t1 == t2) { return 0; } else { - return orderByMode.isDateAddedDescending() ? 1 : -1; + return sortByMode == BY_DATE_ADDED_DESC ? 1 : -1; } - } else if (location != null && (orderByMode.isDistanceDescending() || orderByMode.isDistanceAscending())) { + } else if (location != null && (sortByMode == BY_DISTANCE_DESC || sortByMode == BY_DISTANCE_ASC)) { int d1 = (int) MapUtils.getDistance(location, mapMarker1.getLatitude(), mapMarker1.getLongitude()); int d2 = (int) MapUtils.getDistance(location, mapMarker2.getLatitude(), mapMarker2.getLongitude()); if (d1 > d2) { - return orderByMode.isDistanceDescending() ? -1 : 1; + return sortByMode == BY_DISTANCE_DESC ? -1 : 1; } else if (d1 == d2) { return 0; } else { - return orderByMode.isDistanceDescending() ? 1 : -1; + return sortByMode == BY_DISTANCE_DESC ? 1 : -1; } } else { String n1 = mapMarker1.getName(ctx); @@ -423,8 +441,8 @@ public class MapMarkersHelper { }); } - public void orderMarkers(MapMarkersOrderByMode orderByMode, LatLon location) { - sortMarkers(getMapMarkers(), false, orderByMode, location); + public void sortMarkers(final @MapMarkersSortByDef int sortByMode, LatLon location) { + sortMarkers(getMapMarkers(), false, sortByMode, location); reorderActiveMarkersIfNeeded(); } @@ -687,7 +705,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; addToMapMarkersHistoryList(marker); reorderActiveMarkersIfNeeded(); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); refresh(); } } @@ -707,7 +725,7 @@ public class MapMarkersHelper { markersDbHelper.addMarker(marker); if (marker.history) { addToMapMarkersHistoryList(marker); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); } else { addToMapMarkersList(marker); reorderActiveMarkersIfNeeded(); @@ -724,7 +742,7 @@ public class MapMarkersHelper { marker.history = false; addToMapMarkersList(position, marker); reorderActiveMarkersIfNeeded(); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); refresh(); } } @@ -738,7 +756,7 @@ public class MapMarkersHelper { addToMapMarkersList(marker); } reorderActiveMarkersIfNeeded(); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); updateGroups(); refresh(); } @@ -829,7 +847,6 @@ public class MapMarkersHelper { removeFromMapMarkersList(markersToRemove); addToMapMarkersList(0, markers); reorderActiveMarkersIfNeeded(); - ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(MapMarkersOrderByMode.CUSTOM); } public List getActiveMarkersLatLon() { @@ -862,7 +879,6 @@ public class MapMarkersHelper { cancelAddressRequests(); Collections.reverse(mapMarkers); reorderActiveMarkersIfNeeded(); - ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(MapMarkersOrderByMode.CUSTOM); } public void moveAllActiveMarkersToHistory() { @@ -876,7 +892,7 @@ public class MapMarkersHelper { } addToMapMarkersHistoryList(mapMarkers); mapMarkers = new LinkedList<>(); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); updateGroups(); refresh(); } @@ -940,7 +956,7 @@ public class MapMarkersHelper { } } reorderActiveMarkersIfNeeded(); - sortMarkers(mapMarkersHistory, true, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); refresh(); } @@ -1219,7 +1235,7 @@ public class MapMarkersHelper { mapMarkersGroup.getMarkers().add(marker); updateGroup(mapMarkersGroup); if (mapMarkersGroup.getName() == null) { - sortMarkers(mapMarkersGroup.getMarkers(), false, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC); } } else { mapMarkersGroup = createMapMarkerGroup(marker); @@ -1333,7 +1349,7 @@ public class MapMarkersHelper { for (int i = 0; i < mapMarkersGroups.size(); i++) { MapMarkersGroup group = mapMarkersGroups.get(i); if (group.getName() == null) { - sortMarkers(group.getMarkers(), false, MapMarkersOrderByMode.DATE_ADDED_DESC); + sortMarkers(group.getMarkers(), false, BY_DATE_ADDED_DESC); removeFromGroupsList(group); noGroup = group; } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index f09d14cfb3..241e7e26a0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1338,9 +1338,6 @@ public class OsmandSettings { public final CommonPreference MAP_MARKERS_MODE = new EnumIntPreference<>("map_markers_mode", MapMarkersMode.TOOLBAR, MapMarkersMode.values()); - public final CommonPreference MAP_MARKERS_ORDER_BY_MODE = - new EnumIntPreference<>("map_markers_order_by_mode", MapMarkersOrderByMode.DATE_ADDED_DESC, MapMarkersOrderByMode.values()); - { MAP_MARKERS_MODE.makeProfile().cache(); MAP_MARKERS_MODE.setModeDefaultValue(ApplicationMode.DEFAULT, MapMarkersMode.TOOLBAR); @@ -3188,39 +3185,6 @@ public class OsmandSettings { } } - public enum MapMarkersOrderByMode { - CUSTOM, - DISTANCE_DESC, - DISTANCE_ASC, - NAME, - DATE_ADDED_DESC, - DATE_ADDED_ASC; - - public boolean isCustom() { - return this == CUSTOM; - } - - public boolean isDistanceDescending() { - return this == DISTANCE_DESC; - } - - public boolean isDistanceAscending() { - return this == DISTANCE_ASC; - } - - public boolean isName() { - return this == NAME; - } - - public boolean isDateAddedDescending() { - return this == DATE_ADDED_DESC; - } - - public boolean isDateAddedAscending() { - return this == DATE_ADDED_ASC; - } - } - public enum MapMarkersMode { TOOLBAR(R.string.shared_string_topbar), WIDGETS(R.string.shared_string_widgets), diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 4f561ebdfe..ba27e09aa3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -22,7 +22,6 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -116,7 +115,6 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL hideSnackbar(); mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded(); adapter.notifyDataSetChanged(); - mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 1d8d5d579a..d1e7ab2d44 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -25,9 +25,9 @@ import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.LockableViewPager; import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; @@ -143,8 +143,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); - setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get()); - Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar); toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @@ -470,26 +468,20 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm private OrderByFragmentListener createOrderByFragmentListener() { return new OrderByFragmentListener() { @Override - public void onMapMarkersOrderByModeChanged(MapMarkersOrderByMode orderByMode) { - setOrderByMode(orderByMode); + public void onMapMarkersOrderByModeChanged(@MapMarkersSortByDef int sortByMode) { + OsmandApplication app = getMyApplication(); + MapActivity mapActivity = getMapActivity(); + + Location location = app.getLocationProvider().getLastKnownLocation(); + boolean useCenter = !(mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation() && location != null); + LatLon loc = useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()); + + app.getMapMarkersHelper().sortMarkers(sortByMode, loc); + activeFragment.updateAdapter(); } }; } - private void setOrderByMode(MapMarkersOrderByMode orderByMode) { - if (orderByMode != MapMarkersOrderByMode.CUSTOM) { - OsmandApplication app = getMyApplication(); - MapActivity mapActivity = getMapActivity(); - - Location location = app.getLocationProvider().getLastKnownLocation(); - boolean useCenter = !(mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation() && location != null); - LatLon loc = useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()); - - app.getMapMarkersHelper().orderMarkers(orderByMode, loc); - activeFragment.updateAdapter(); - } - } - private void hideSnackbar() { if (snackbar != null && snackbar.isShown()) { snackbar.dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 3bdd3d143b..b50682748d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapmarkers; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -9,8 +11,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -18,7 +20,6 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm public final static String TAG = "OrderByBottomSheetDialogFragment"; - private OsmandSettings settings; private OrderByFragmentListener listener; public void setListener(OrderByFragmentListener listener) { @@ -28,76 +29,69 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - settings = getMyApplication().getSettings(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_order_by_bottom_sheet_dialog, container); + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.fragment_marker_order_by_bottom_sheet_dialog, container); if (nightMode) { - ((TextView) mainView.findViewById(R.id.order_by_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + ((TextView) mainView.findViewById(R.id.order_by_title)).setTextColor( + ContextCompat.getColor(getContext(), R.color.ctx_menu_info_text_dark) + ); } - ((TextView) mainView.findViewById(R.id.order_by_title)).setText(getString(R.string.order_by)); - ((ImageView) mainView.findViewById(R.id.distance_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_markers_dark)); + Drawable distanceIcon = getContentIcon(R.drawable.ic_action_markers_dark); + Drawable dateIcon = getContentIcon(R.drawable.ic_action_sort_by_date); ((ImageView) mainView.findViewById(R.id.name_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name)); - ((ImageView) mainView.findViewById(R.id.date_added_asc_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); - ((ImageView) mainView.findViewById(R.id.date_added_desc_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); + ((ImageView) mainView.findViewById(R.id.distance_nearest_icon)).setImageDrawable(distanceIcon); + ((ImageView) mainView.findViewById(R.id.distance_farthest_icon)).setImageDrawable(distanceIcon); + ((ImageView) mainView.findViewById(R.id.date_added_asc_icon)).setImageDrawable(dateIcon); + ((ImageView) mainView.findViewById(R.id.date_added_desc_icon)).setImageDrawable(dateIcon); ((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")"); ((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")"); - mainView.findViewById(R.id.distance_row).setOnClickListener(orderByModeOnClickListener); - mainView.findViewById(R.id.name_row).setOnClickListener(orderByModeOnClickListener); - mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(orderByModeOnClickListener); - mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(orderByModeOnClickListener); - - mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { + View.OnClickListener onClickListener = new View.OnClickListener() { @Override - public void onClick(View view) { + public void onClick(View v) { + int sortByMode = -1; + switch (v.getId()) { + case R.id.name_row: + sortByMode = MapMarkersHelper.BY_NAME; + break; + case R.id.distance_nearest_row: + sortByMode = MapMarkersHelper.BY_DISTANCE_ASC; + break; + case R.id.distance_farthest_row: + sortByMode = MapMarkersHelper.BY_DISTANCE_DESC; + break; + case R.id.date_added_asc_row: + sortByMode = MapMarkersHelper.BY_DATE_ADDED_ASC; + break; + case R.id.date_added_desc_row: + sortByMode = MapMarkersHelper.BY_DATE_ADDED_DESC; + break; + } + if (sortByMode != -1 && listener != null) { + listener.onMapMarkersOrderByModeChanged(sortByMode); + } dismiss(); } - }); + }; + + mainView.findViewById(R.id.name_row).setOnClickListener(onClickListener); + mainView.findViewById(R.id.distance_nearest_row).setOnClickListener(onClickListener); + mainView.findViewById(R.id.distance_farthest_row).setOnClickListener(onClickListener); + mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(onClickListener); + mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(onClickListener); + mainView.findViewById(R.id.close_row).setOnClickListener(onClickListener); setupHeightAndBackground(mainView, R.id.marker_order_by_scroll_view); return mainView; } - private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { - - @Override - public void onClick(View view) { - MapMarkersOrderByMode currentOrderByMode = settings.MAP_MARKERS_ORDER_BY_MODE.get(); - MapMarkersOrderByMode modeToSet; - switch (view.getId()) { - case R.id.distance_row: - if (currentOrderByMode == MapMarkersOrderByMode.DISTANCE_ASC) { - modeToSet = MapMarkersOrderByMode.DISTANCE_DESC; - } else { - modeToSet = MapMarkersOrderByMode.DISTANCE_ASC; - } - break; - case R.id.name_row: - modeToSet = MapMarkersOrderByMode.NAME; - break; - case R.id.date_added_asc_row: - modeToSet = MapMarkersOrderByMode.DATE_ADDED_ASC; - break; - case R.id.date_added_desc_row: - modeToSet = MapMarkersOrderByMode.DATE_ADDED_DESC; - break; - default: - modeToSet = currentOrderByMode; - } - settings.MAP_MARKERS_ORDER_BY_MODE.set(modeToSet); - if (listener != null) { - listener.onMapMarkersOrderByModeChanged(modeToSet); - } - dismiss(); - } - }; - interface OrderByFragmentListener { - void onMapMarkersOrderByModeChanged(MapMarkersOrderByMode orderByMode); + void onMapMarkersOrderByModeChanged(@MapMarkersSortByDef int sortByMode); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 098748fa6c..fab4fcc504 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -331,7 +331,6 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0) { mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded(); - mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); mapActivity.refreshMap(); adapter.reloadData(); try {