Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
107c142469
8 changed files with 200 additions and 187 deletions
|
@ -1,11 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/marker_order_by_scroll_view"
|
||||
|
@ -27,50 +28,21 @@
|
|||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
tools:text="@string/order_by"
|
||||
android:text="@string/sort_by"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/distance_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/distance_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_markers_dark"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/distance_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:text="@string/distance"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/name_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:gravity="center_vertical">
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/name_icon"
|
||||
|
@ -89,17 +61,93 @@
|
|||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/distance_nearest_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/distance_nearest_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_markers_dark"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/distance_nearest_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:text="@string/distance_nearest"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/distance_farthest_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/distance_farthest_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_markers_dark"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/distance_farthest_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:text="@string/distance_farthest"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/date_added_asc_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:gravity="center_vertical">
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/date_added_asc_icon"
|
||||
|
@ -114,8 +162,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="Date added (Ascendingly)"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Date added (Ascendingly)"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -123,12 +171,12 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:gravity="center_vertical">
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/date_added_desc_icon"
|
||||
|
@ -143,8 +191,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="Date added (Descendingly)"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Date added (Descendingly)"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -173,4 +221,4 @@
|
|||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -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
|
||||
-->
|
||||
<string name="distance_farthest">Distance: farthest first</string>
|
||||
<string name="distance_nearest">Distance: nearest first</string>
|
||||
<string name="enter_lon">Enter longitude</string>
|
||||
<string name="enter_lat">Enter latitude</string>
|
||||
<string name="enter_lat_and_lon">Enter latitude and longitude</string>
|
||||
|
|
|
@ -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<MapMarker> mapMarkers = new LinkedList<>();
|
||||
private List<MapMarker> mapMarkersHistory = new LinkedList<>();
|
||||
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
|
||||
private OsmandSettings settings;
|
||||
|
||||
private List<MapMarkerChangedListener> 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<MapMarker> 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<MapMarker> markers, final boolean visited, final MapMarkersOrderByMode orderByMode) {
|
||||
sortMarkers(markers, visited, orderByMode, null);
|
||||
private void sortMarkers(List<MapMarker> markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) {
|
||||
sortMarkers(markers, visited, sortByMode, null);
|
||||
}
|
||||
|
||||
public void sortMarkers(List<MapMarker> markers, final boolean visited,
|
||||
final MapMarkersOrderByMode orderByMode, @Nullable final LatLon location) {
|
||||
private void sortMarkers(List<MapMarker> markers, final boolean visited,
|
||||
final @MapMarkersSortByDef int sortByMode, @Nullable final LatLon location) {
|
||||
Collections.sort(markers, new Comparator<MapMarker>() {
|
||||
@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<LatLon> 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;
|
||||
}
|
||||
|
|
|
@ -1338,9 +1338,6 @@ public class OsmandSettings {
|
|||
public final CommonPreference<MapMarkersMode> MAP_MARKERS_MODE =
|
||||
new EnumIntPreference<>("map_markers_mode", MapMarkersMode.TOOLBAR, MapMarkersMode.values());
|
||||
|
||||
public final CommonPreference<MapMarkersOrderByMode> 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),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue