Merge pull request #4460 from osmandapp/sasha_pasha_branch

Sasha pasha branch
This commit is contained in:
Alexey 2017-09-21 10:56:15 +03:00 committed by GitHub
commit 61e0e6801e
26 changed files with 1037 additions and 457 deletions

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/color_dialog_buttons_dark" android:state_checked="true"/>
<item android:color="@color/ctx_menu_info_text_dark" android:state_checked="false"/>
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/dashboard_blue" android:state_checked="true"/>
<item android:color="@color/icon_color" android:state_checked="false"/>
</selector>

View file

@ -98,7 +98,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/bg_color" android:background="?attr/bg_color"
app:itemBackground="?attr/bg_color" app:itemBackground="?attr/bg_color"
app:itemIconTint="@drawable/bottom_navigation_color_selector" app:itemIconTint="@color/bottom_navigation_color_selector_light"
app:itemTextColor="@drawable/bottom_navigation_color_selector" app:itemTextColor="@color/bottom_navigation_color_selector_light"
app:menu="@menu/map_markers_bottom_navigation"/> app:menu="@menu/map_markers_bottom_navigation"/>
</LinearLayout> </LinearLayout>

View file

@ -115,6 +115,73 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/show_arrows_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/show_arrows_on_the_map"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/show_arrows_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<LinearLayout
android:id="@+id/show_guide_line_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:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/show_guide_line"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/show_guide_line_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
android:background="?attr/dashboard_divider"/>
<RelativeLayout <RelativeLayout
android:id="@+id/top_bar_row" android:id="@+id/top_bar_row"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -148,15 +215,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/> android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton <RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/top_bar_radio_button" android:id="@+id/top_bar_radio_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/> android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout
@ -192,15 +259,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/> android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton <RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/widget_radio_button" android:id="@+id/widget_radio_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/> android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout
@ -235,15 +302,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/> android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton <RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/none_radio_button" android:id="@+id/none_radio_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/> android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>

View file

@ -14,24 +14,35 @@
android:orientation="horizontal" android:orientation="horizontal"
android:background="?attr/bg_color"> android:background="?attr/bg_color">
<ImageView
android:id="@+id/icon"
android:scaleType="centerInside"
android:layout_width="56dp"
android:layout_height="48dp"
tools:src="@drawable/ic_action_fav_dark"
tools:visibility="visible"
android:visibility="gone"/>
<View
android:id="@+id/icon_space"
android:layout_width="16dp"
android:layout_height="match_parent"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/date_title" android:id="@+id/title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1" android:layout_weight="1"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:gravity="center_vertical" android:gravity="center_vertical"
tools:text="Today"/> tools:text="Today"/>
<ImageButton <android.support.v7.widget.SwitchCompat
android:id="@+id/date_options_button" android:id="@+id/disable_group_switch"
android:layout_width="48dp" android:layout_width="wrap_content"
android:layout_height="48dp" android:layout_height="match_parent"
android:layout_gravity="center_vertical|end" android:layout_marginLeft="16dp"
android:background="@null" android:layout_marginRight="16dp"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"/>
tools:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout> </LinearLayout>

View file

@ -55,7 +55,6 @@
android:layout_height="28dp"> android:layout_height="28dp">
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:layout_marginBottom="2dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:id="@+id/map_marker_title" android:id="@+id/map_marker_title"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -69,7 +68,6 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_marginTop="1dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:background="?attr/bg_color"
xmlns:android="http://schemas.android.com/apk/res/android">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_hide_history_title"
android:background="?attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="56dp"
android:paddingStart="56dp"
android:textAllCaps="true"
android:gravity="center_vertical"
tools:text="Show passed"
android:textSize="12sp"
osmand:typeface="@string/font_roboto_medium"
android:textColor="@color/dashboard_blue"/>
</LinearLayout>

View file

@ -9,6 +9,10 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 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="show_guide_line">Show guide line</string>
<string name="show_arrows_on_the_map">Show arrows on the map</string>
<string name="show_passed">Show passed</string>
<string name="hide_passed">Hide passed</string>
<string name="remove_from_map_markers">Remove from Map Markers</string> <string name="remove_from_map_markers">Remove from Map Markers</string>
<string name="descendingly">Descendingly</string> <string name="descendingly">Descendingly</string>
<string name="ascendingly">Ascendingly</string> <string name="ascendingly">Ascendingly</string>

View file

@ -15,7 +15,6 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -40,6 +39,7 @@ public class MapMarkersHelper {
private List<MapMarker> mapMarkers = new LinkedList<>(); private List<MapMarker> mapMarkers = new LinkedList<>();
private List<MapMarker> mapMarkersHistory = new LinkedList<>(); private List<MapMarker> mapMarkersHistory = new LinkedList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private OsmandSettings settings; private OsmandSettings settings;
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private OsmandApplication ctx; private OsmandApplication ctx;
@ -175,6 +175,11 @@ public class MapMarkersHelper {
} }
} }
@Nullable
public MarkersSyncGroup getGroup(String id) {
return markersDbHelper.getGroup(id);
}
public static class MarkersSyncGroup { public static class MarkersSyncGroup {
public static final int FAVORITES_TYPE = 0; public static final int FAVORITES_TYPE = 0;
@ -214,6 +219,10 @@ public class MapMarkersHelper {
public int getColor() { public int getColor() {
return color; return color;
} }
public void setColor(int color) {
this.color = color;
}
} }
public MapMarkersHelper(OsmandApplication ctx) { public MapMarkersHelper(OsmandApplication ctx) {
@ -222,6 +231,7 @@ public class MapMarkersHelper {
markersDbHelper = ctx.getMapMarkersDbHelper(); markersDbHelper = ctx.getMapMarkersDbHelper();
startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get(); startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
loadMarkers(); loadMarkers();
createMapMarkersGroups();
} }
public boolean isStartFromMyLocation() { public boolean isStartFromMyLocation() {
@ -251,7 +261,7 @@ public class MapMarkersHelper {
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory(); List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
sortHistoryMarkers(); sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
mapMarkersHistory.addAll(markersHistory); mapMarkersHistory.addAll(markersHistory);
if (!ctx.isApplicationInitializing()) { if (!ctx.isApplicationInitializing()) {
@ -279,73 +289,20 @@ public class MapMarkersHelper {
} }
} }
public List<MapMarker> getMarkersSortedByGroup() { public void sortMarkers(List<MapMarker> markers, final boolean visited, final OsmandSettings.MapMarkersOrderByMode orderByMode) {
Map<String, MapMarkerGroup> groupsMap = new LinkedHashMap<>();
List<MapMarker> noGroup = new ArrayList<>();
for (MapMarker marker : mapMarkers) {
String groupName = marker.groupName;
if (groupName == null) {
noGroup.add(marker);
} else {
MapMarkerGroup group = groupsMap.get(groupName);
if (group == null) {
group = new MapMarkerGroup(groupName, marker.creationDate);
groupsMap.put(groupName, group);
} else {
long markerCreationDate = marker.creationDate;
if (markerCreationDate < group.getCreationDate()) {
group.setCreationDate(markerCreationDate);
}
}
group.getMapMarkers().add(marker);
}
}
List<MapMarkerGroup> groups = new ArrayList<>(groupsMap.values());
sortGroups(groups);
List<MapMarker> markers = new ArrayList<>();
markers.addAll(noGroup);
for (MapMarkerGroup group : groups) {
markers.addAll(group.getMapMarkers());
}
return markers;
}
private void sortGroups(List<MapMarkerGroup> groups) {
Collections.sort(groups, new Comparator<MapMarkerGroup>() {
@Override
public int compare(MapMarkerGroup group1, MapMarkerGroup group2) {
long t1 = group1.creationDate;
long t2 = group2.creationDate;
if (t1 > t2) {
return -1;
} else if (t1 == t2) {
return 0;
} else {
return 1;
}
}
});
}
private void sortHistoryMarkers() {
sortMarkers(true, null);
}
private void sortMarkers(final boolean history, final OsmandSettings.MapMarkersOrderByMode orderByMode) {
final LatLon location = ctx.getSettings().getLastKnownMapLocation(); final LatLon location = ctx.getSettings().getLastKnownMapLocation();
Collections.sort(history ? mapMarkersHistory : mapMarkers, new Comparator<MapMarker>() { Collections.sort(markers, new Comparator<MapMarker>() {
@Override @Override
public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { public int compare(MapMarker mapMarker1, MapMarker mapMarker2) {
if (history || orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { if (orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) {
long t1 = history ? mapMarker1.visitedDate : mapMarker1.creationDate; long t1 = visited ? mapMarker1.visitedDate : mapMarker1.creationDate;
long t2 = history ? mapMarker2.visitedDate : mapMarker2.creationDate; long t2 = visited ? mapMarker2.visitedDate : mapMarker2.creationDate;
if (t1 > t2) { if (t1 > t2) {
return history || orderByMode.isDateAddedDescending() ? -1 : 1; return orderByMode.isDateAddedDescending() ? -1 : 1;
} else if (t1 == t2) { } else if (t1 == t2) {
return 0; return 0;
} else { } else {
return history || orderByMode.isDateAddedDescending() ? 1 : -1; return orderByMode.isDateAddedDescending() ? 1 : -1;
} }
} else if (orderByMode.isDistanceDescending() || orderByMode.isDistanceAscending()) { } else if (orderByMode.isDistanceDescending() || orderByMode.isDistanceAscending()) {
int d1 = (int) MapUtils.getDistance(location, mapMarker1.getLatitude(), mapMarker1.getLongitude()); int d1 = (int) MapUtils.getDistance(location, mapMarker1.getLatitude(), mapMarker1.getLongitude());
@ -367,7 +324,7 @@ public class MapMarkersHelper {
} }
public void orderMarkers(OsmandSettings.MapMarkersOrderByMode orderByMode) { public void orderMarkers(OsmandSettings.MapMarkersOrderByMode orderByMode) {
sortMarkers(false, orderByMode); sortMarkers(getMapMarkers(), false, orderByMode);
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
} }
@ -417,6 +374,9 @@ public class MapMarkersHelper {
removeActiveMarkersFromSyncGroup(group.getId()); removeActiveMarkersFromSyncGroup(group.getId());
return; return;
} }
if (group.getColor() == -1) {
group.setColor(favGroup.color);
}
for (FavouritePoint fp : favGroup.points) { for (FavouritePoint fp : favGroup.points) {
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName()); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName());
@ -438,7 +398,9 @@ public class MapMarkersHelper {
} }
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints()); List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) { for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor));
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name);
} }
@ -452,13 +414,10 @@ public class MapMarkersHelper {
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
if (marker.id.equals(group.getId() + name)) { if (marker.id.equals(group.getId() + name)) {
exists = true; exists = true;
int colorIndex = MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); if (!marker.history && (!marker.point.equals(latLon))) {
boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex;
if (!marker.history && (!marker.point.equals(latLon) || updateColor)) {
for (MapMarker m : mapMarkers) { for (MapMarker m : mapMarkers) {
if (m.id.equals(marker.id)) { if (m.id.equals(marker.id)) {
m.point = latLon; m.point = latLon;
m.colorIndex = colorIndex;
updateMapMarker(m, true); updateMapMarker(m, true);
break; break;
} }
@ -501,7 +460,7 @@ public class MapMarkersHelper {
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
mapMarkersHistory.add(marker); mapMarkersHistory.add(marker);
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
sortHistoryMarkers(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh(); refresh();
} }
} }
@ -511,11 +470,12 @@ public class MapMarkersHelper {
markersDbHelper.addMarker(marker); markersDbHelper.addMarker(marker);
if (marker.history) { if (marker.history) {
mapMarkersHistory.add(marker); mapMarkersHistory.add(marker);
sortHistoryMarkers(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
} else { } else {
mapMarkers.add(marker); mapMarkers.add(marker);
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
} }
addMarkerToGroup(marker);
refresh(); refresh();
} }
} }
@ -527,7 +487,7 @@ public class MapMarkersHelper {
marker.history = false; marker.history = false;
mapMarkers.add(position, marker); mapMarkers.add(position, marker);
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
sortHistoryMarkers(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh(); refresh();
} }
} }
@ -541,7 +501,7 @@ public class MapMarkersHelper {
mapMarkers.add(marker); mapMarkers.add(marker);
} }
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
sortHistoryMarkers(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh(); refresh();
} }
} }
@ -551,6 +511,7 @@ public class MapMarkersHelper {
markersDbHelper.removeMarker(marker, true); markersDbHelper.removeMarker(marker, true);
mapMarkersHistory.remove(marker); mapMarkersHistory.remove(marker);
refresh(); refresh();
removeMarkerFromGroup(marker);
} }
} }
@ -623,7 +584,7 @@ public class MapMarkersHelper {
} }
mapMarkersHistory.addAll(mapMarkers); mapMarkersHistory.addAll(mapMarkers);
mapMarkers.clear(); mapMarkers.clear();
sortHistoryMarkers(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh(); refresh();
} }
@ -632,6 +593,7 @@ public class MapMarkersHelper {
markersDbHelper.clearAllMarkersHistory(); markersDbHelper.clearAllMarkersHistory();
mapMarkersHistory.clear(); mapMarkersHistory.clear();
refresh(); refresh();
removeHistoryMarkersFromGroups();
} }
public void addMarkersSyncGroup(MarkersSyncGroup group) { public void addMarkersSyncGroup(MarkersSyncGroup group) {
@ -675,8 +637,7 @@ public class MapMarkersHelper {
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) { private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
if (points.size() > 0) { if (points.size() > 0) {
boolean randomColor = group == null || group.getColor() == -1; int colorIndex = -1;
int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx)));
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
LatLon point = points.get(i); LatLon point = points.get(i);
PointDescription historyName = historyNames.get(i); PointDescription historyName = historyNames.get(i);
@ -689,16 +650,14 @@ public class MapMarkersHelper {
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
} }
if (randomColor) { if (colorIndex == -1) {
if (colorIndex == -1) { if (mapMarkers.size() > 0) {
if (mapMarkers.size() > 0) { colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
} else { } else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; colorIndex = 0;
} }
} else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} }
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
@ -714,6 +673,7 @@ public class MapMarkersHelper {
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
markersDbHelper.addMarker(marker); markersDbHelper.addMarker(marker);
mapMarkers.add(marker); mapMarkers.add(marker);
addMarkerToGroup(marker);
checkAndFixActiveMarkersOrderIfNeeded(); checkAndFixActiveMarkersOrderIfNeeded();
} }
} }
@ -856,15 +816,165 @@ public class MapMarkersHelper {
GPXUtilities.writeGpxFile(fout, file, ctx); GPXUtilities.writeGpxFile(fout, file, ctx);
} }
public static class MapMarkerGroup { private void removeHistoryMarkersFromGroups() {
private String name; for (MapMarkersGroup markersGroup : mapMarkersGroups) {
private List<MapMarker> mapMarkers = new ArrayList<>(); List<MapMarker> activeMarkers = new ArrayList<>();
private long creationDate; for (MapMarker marker : markersGroup.getMarkers()) {
if (!marker.history) {
public MapMarkerGroup(String name, long creationDate) { activeMarkers.add(marker);
this.name = name; }
this.creationDate = creationDate; }
markersGroup.setMarkers(activeMarkers);
updateShowHideHistoryButtonInGroup(markersGroup);
} }
}
private void updateShowHideHistoryButtonInGroup(MapMarkersGroup mapMarkersGroup) {
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null && historyMarkersCount == 0) {
mapMarkersGroup.setShowHideHistoryButton(null);
} else if (historyMarkersCount > 0) {
showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.setShowHistory(false);
showHideHistoryButton.setMarkerGroup(mapMarkersGroup);
mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton);
}
}
private void addMarkerToGroup(MapMarker marker) {
if (marker != null) {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName);
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().add(marker);
updateShowHideHistoryButtonInGroup(mapMarkersGroup);
if (mapMarkersGroup.getName() == null) {
sortMarkers(mapMarkersGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
}
} else {
MapMarkersGroup group = createMapMarkerGroup(marker);
group.getMarkers().add(marker);
createHeaderAndHistoryButtonInGroup(group);
}
}
}
private MapMarkersGroup createMapMarkerGroup(MapMarker marker) {
MapMarkersGroup group = new MapMarkersGroup();
group.setName(marker.groupName);
MapMarkersHelper.MarkersSyncGroup syncGroup = getGroup(marker.groupKey);
if (syncGroup != null) {
group.setType(syncGroup.getType());
}
group.setColor(MapMarker.getColorId(marker.colorIndex));
group.setCreationDate(marker.creationDate);
mapMarkersGroups.add(group);
return group;
}
private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) {
GroupHeader header = new GroupHeader();
int type = group.getType();
if (type != -1) {
header.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_track_16);
}
header.setGroup(group);
group.setGroupHeader(header);
updateShowHideHistoryButtonInGroup(group);
}
private void removeMarkerFromGroup(MapMarker marker) {
if (marker != null) {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName);
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().remove(marker);
updateShowHideHistoryButtonInGroup(mapMarkersGroup);
}
}
}
public List<MapMarkersGroup> getMapMarkersGroups() {
return mapMarkersGroups;
}
private void createMapMarkersGroups() {
List<MapMarker> markers = new ArrayList<>();
markers.addAll(mapMarkers);
markers.addAll(mapMarkersHistory);
Map<String, MapMarkersGroup> groupsMap = new LinkedHashMap<>();
MapMarkersGroup noGroup = null;
for (MapMarker marker : markers) {
String groupName = marker.groupName;
if (groupName == null) {
if (noGroup == null) {
noGroup = new MapMarkersGroup();
noGroup.setCreationDate(marker.creationDate);
}
noGroup.getMarkers().add(marker);
} else {
MapMarkersGroup group = groupsMap.get(groupName);
if (group == null) {
group = createMapMarkerGroup(marker);
groupsMap.put(groupName, group);
} else {
long markerCreationDate = marker.creationDate;
if (markerCreationDate < group.getCreationDate()) {
group.setCreationDate(markerCreationDate);
}
}
group.getMarkers().add(marker);
}
}
mapMarkersGroups = new ArrayList<>(groupsMap.values());
sortGroups(mapMarkersGroups);
for (MapMarkersGroup group : mapMarkersGroups) {
createHeaderAndHistoryButtonInGroup(group);
}
if (noGroup != null) {
sortMarkers(noGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
mapMarkersGroups.add(0, noGroup);
}
}
private void sortGroups(List<MapMarkersGroup> groups) {
Collections.sort(groups, new Comparator<MapMarkersGroup>() {
@Override
public int compare(MapMarkersGroup group1, MapMarkersGroup group2) {
long t1 = group1.getCreationDate();
long t2 = group2.getCreationDate();
if (t1 > t2) {
return -1;
} else if (t1 == t2) {
return 0;
} else {
return 1;
}
}
});
}
public MapMarkersGroup getMapMarkerGroupByName(String name) {
for (MapMarkersGroup group : mapMarkersGroups) {
if ((name == null && group.getName() == null)
|| (group.getName() != null && group.getName().equals(name))) {
return group;
}
}
return null;
}
public static class MapMarkersGroup {
private String name;
private GroupHeader header;
private int type = -1;
private List<MapMarker> markers = new ArrayList<>();
private long creationDate;
private ShowHideHistoryButton showHideHistoryButton;
private int color;
private boolean disabled;
public String getName() { public String getName() {
return name; return name;
@ -874,12 +984,48 @@ public class MapMarkersHelper {
this.name = name; this.name = name;
} }
public List<MapMarker> getMapMarkers() { public GroupHeader getGroupHeader() {
return mapMarkers; return header;
} }
public void setMapMarkers(List<MapMarker> mapMarkers) { public void setGroupHeader(GroupHeader header) {
this.mapMarkers = mapMarkers; this.header = header;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public List<MapMarker> getActiveMarkers() {
List<MapMarker> activeMarkers = new ArrayList<>();
for (MapMarker marker : markers) {
if (!marker.history) {
activeMarkers.add(marker);
}
}
return activeMarkers;
}
public List<MapMarker> getHistoryMarkers() {
List<MapMarker> historyMarkers = new ArrayList<>();
for (MapMarker marker : markers) {
if (marker.history) {
historyMarkers.add(marker);
}
}
return historyMarkers;
}
public List<MapMarker> getMarkers() {
return markers;
}
public void setMarkers(List<MapMarker> markers) {
this.markers = markers;
} }
public long getCreationDate() { public long getCreationDate() {
@ -889,5 +1035,71 @@ public class MapMarkersHelper {
public void setCreationDate(long creationDate) { public void setCreationDate(long creationDate) {
this.creationDate = creationDate; this.creationDate = creationDate;
} }
public ShowHideHistoryButton getShowHideHistoryButton() {
return showHideHistoryButton;
}
public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) {
this.showHideHistoryButton = showHideHistoryButton;
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
}
public static class ShowHideHistoryButton {
private boolean showHistory;
private MapMarkersGroup group;
public boolean isShowHistory() {
return showHistory;
}
public void setShowHistory(boolean showHistory) {
this.showHistory = showHistory;
}
public MapMarkersGroup getMapMarkerGroup() {
return group;
}
public void setMarkerGroup(MapMarkersGroup group) {
this.group = group;
}
}
public static class GroupHeader {
private int iconRes;
private MapMarkersGroup group;
public int getIconRes() {
return iconRes;
}
public void setIconRes(int iconRes) {
this.iconRes = iconRes;
}
public MapMarkersGroup getGroup() {
return group;
}
public void setGroup(MapMarkersGroup group) {
this.group = group;
}
} }
} }

View file

@ -38,6 +38,7 @@ import android.location.LocationManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
@ -69,11 +70,14 @@ public class OsmAndLocationProvider implements SensorEventListener {
private static final int GPS_DIST_REQUEST = 0; private static final int GPS_DIST_REQUEST = 0;
private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000; private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000;
private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 60; // 60 minutes private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 5; // 5 minutes
public static final long STALE_LOCATION_TIMEOUT_FOR_ICON = 1000 * 60 * 5; // 5 minutes private static final long STALE_LOCATION_TIMEOUT_FOR_UI = 1000 * 60 * 15; // 15 minutes
private static final int UPDATES_BEFORE_CHECK_LOCATION = 100; private static final int UPDATES_BEFORE_CHECK_LOCATION = 100;
private int updatesCounter; private int updatesCounter;
private int updatesCounterUi;
private net.osmand.Location cachedLocation;
private long lastTimeGPSLocationFixed = 0; private long lastTimeGPSLocationFixed = 0;
private boolean gpsSignalLost; private boolean gpsSignalLost;
@ -877,6 +881,26 @@ public class OsmAndLocationProvider implements SensorEventListener {
return location; return location;
} }
@Nullable
public net.osmand.Location getLastStaleKnownLocation() {
if (updatesCounterUi == 0) {
net.osmand.Location newLoc = getLastKnownLocation();
if (newLoc == null) {
if (cachedLocation != null && System.currentTimeMillis() - cachedLocation.getTime() > STALE_LOCATION_TIMEOUT_FOR_UI) {
cachedLocation = null;
}
} else {
cachedLocation = newLoc;
}
}
if (updatesCounterUi == UPDATES_BEFORE_CHECK_LOCATION) {
updatesCounterUi = 0;
} else {
updatesCounterUi++;
}
return cachedLocation;
}
public void showNavigationInfo(TargetPoint pointToNavigate, Context uiActivity) { public void showNavigationInfo(TargetPoint pointToNavigate, Context uiActivity) {
getNavigationInfo().show(pointToNavigate, getHeading(), uiActivity); getNavigationInfo().show(pointToNavigate, getHeading(), uiActivity);

View file

@ -713,6 +713,9 @@ public class OsmandSettings {
public final CommonPreference<RulerMode> RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal(); public final CommonPreference<RulerMode> RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal();
public final CommonPreference<Boolean> SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeGlobal();
public final CommonPreference<Boolean> USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference<Boolean> USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); public final CommonPreference<String> MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal(); public final CommonPreference<String> MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal();

View file

@ -24,9 +24,9 @@ import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -44,12 +44,14 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private LockableViewPager viewPager; private LockableViewPager viewPager;
private TextView orderByModeTitle; private TextView orderByModeTitle;
private boolean lightTheme;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId); setStyle(STYLE_NO_FRAME, themeId);
} }
@ -95,6 +97,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar);
if (!lightTheme) {
toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color));
}
orderByModeTitle = toolbar.findViewById(R.id.order_by_mode_text); orderByModeTitle = toolbar.findViewById(R.id.order_by_mode_text);
setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get()); setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get());
@ -121,6 +126,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);
BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
if (!lightTheme) {
bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
}
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

View file

@ -22,43 +22,45 @@ import net.osmand.util.MapUtils;
public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener {
public static final String TAG = "MapMarkersGroupsFragment"; public static final String TAG = "MapMarkersGroupsFragment";
private MapMarkersGroupsAdapter adapter; private MapMarkersGroupsAdapter adapter;
private Float heading; private Float heading;
private Location location; private Location location;
private boolean locationUpdateStarted; private boolean locationUpdateStarted;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final RecyclerView recyclerView = new RecyclerView(getContext()); final RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
adapter = new MapMarkersGroupsAdapter(mapActivity); adapter = new MapMarkersGroupsAdapter(mapActivity);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
return recyclerView; return recyclerView;
} }
void updateAdapter() { void updateAdapter() {
if (adapter != null) { if (adapter != null) {
adapter.notifyDataSetChanged(); adapter.createDisplayGroups();
} adapter.updateShowDirectionMarkers();
} adapter.notifyDataSetChanged();
}
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity()));
startLocationUpdate(); startLocationUpdate();
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
stopLocationUpdate(); stopLocationUpdate();
} }
void startLocationUpdate() { void startLocationUpdate() {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();

View file

@ -1,7 +1,9 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -43,7 +45,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
} }
((ImageView) mainView.findViewById(R.id.sort_by_icon)) ((ImageView) mainView.findViewById(R.id.sort_by_icon))
.setImageDrawable(getIcon(R.drawable.ic_sort_waypoint_dark, R.color.on_map_icon_color)); .setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark));
OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get();
ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon); ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon);
int imageResId = 0; int imageResId = 0;
@ -55,16 +57,16 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
imageResId = R.drawable.ic_action_device_widget; imageResId = R.drawable.ic_action_device_widget;
break; break;
} }
showDirectionIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); showDirectionIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top));
if (imageResId != 0) { if (imageResId != 0) {
showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue)); showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue));
} }
((ImageView) mainView.findViewById(R.id.build_route_icon)) ((ImageView) mainView.findViewById(R.id.build_route_icon))
.setImageDrawable(getIcon(R.drawable.map_directions, R.color.on_map_icon_color)); .setImageDrawable(getContentIcon(R.drawable.map_directions));
((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)) ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon))
.setImageDrawable(getIcon(R.drawable.ic_action_polygom_dark, R.color.on_map_icon_color)); .setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)) ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon))
.setImageDrawable(getIcon(R.drawable.ic_action_history2, R.color.on_map_icon_color)); .setImageDrawable(getContentIcon(R.drawable.ic_action_history2));
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity())); ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity()));
@ -171,6 +173,11 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
} }
} }
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
}
interface MarkerOptionsFragmentListener { interface MarkerOptionsFragmentListener {
void sortByOnClick(); void sortByOnClick();

View file

@ -1,7 +1,9 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -121,6 +123,11 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment
} }
} }
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, settings.isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
}
private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() {
@Override @Override

View file

@ -1,7 +1,10 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
@ -12,6 +15,7 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
@ -19,6 +23,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -38,8 +43,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final OsmandSettings settings = getMyApplication().getSettings();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
night = !getMyApplication().getSettings().isLightContent(); night = !settings.isLightContent();
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container);
@ -47,7 +53,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
} }
OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get();
highlightSelectedItem(mode, true); highlightSelectedItem(mode, true);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
@ -84,16 +90,44 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
} }
final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch);
showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean newState = !settings.SHOW_ARROWS_TO_FIRST_MARKERS.get();
settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(newState);
showArrowsToggle.setChecked(newState);
if (getMapActivity() != null) {
getMapActivity().refreshMap();
}
}
});
final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean newState = !settings.SHOW_LINES_TO_FIRST_MARKERS.get();
settings.SHOW_LINES_TO_FIRST_MARKERS.set(newState);
showLinesToggle.setChecked(newState);
if (getMapActivity() != null) {
getMapActivity().refreshMap();
}
}
});
ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon);
topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color));
topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue)); topBarIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_topbar));
ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon); ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon);
widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color));
widgetIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_widget, R.color.dashboard_blue)); widgetIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_widget));
ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon);
noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); noneIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top));
mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener); mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener);
mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener); mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener);
@ -157,6 +191,19 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
} }
} }
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
}
private MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity != null) {
return (MapActivity) activity;
}
return null;
}
private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) { private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) {
int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color; int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color;
int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue; int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue;

View file

@ -1,20 +1,26 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.View; import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
final TextView date; final ImageView icon;
final ImageButton optionsBtn; final View iconSpace;
final TextView title;
final SwitchCompat disableGroupSwitch;
public MapMarkerHeaderViewHolder(View itemView) { public MapMarkerHeaderViewHolder(View itemView) {
super(itemView); super(itemView);
date = itemView.findViewById(R.id.date_title); icon = (ImageView) itemView.findViewById(R.id.icon);
optionsBtn = itemView.findViewById(R.id.date_options_button); iconSpace = itemView.findViewById(R.id.icon_space);
title = (TextView) itemView.findViewById(R.id.title);
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
} }
} }

View file

@ -96,7 +96,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
holder.iconDirection.setVisibility(View.GONE); holder.iconDirection.setVisibility(View.GONE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor)); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor));
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.markers_top_bar_background)); holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
holder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white)); holder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color)); holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset)); holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset));

View file

@ -1,16 +1,24 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.GroupHeader;
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,152 +31,251 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private static final int HEADER_TYPE = 1; private static final int HEADER_TYPE = 1;
private static final int MARKER_TYPE = 2; private static final int MARKER_TYPE = 2;
private static final int SHOW_HIDE_HISTORY_TYPE = 3;
private static final int TODAY_HEADER = 56; private static final int TODAY_HEADER = 56;
private static final int YESTERDAY_HEADER = 57; private static final int YESTERDAY_HEADER = 57;
private static final int LAST_SEVEN_DAYS_HEADER = 58; private static final int LAST_SEVEN_DAYS_HEADER = 58;
private static final int THIS_YEAR_HEADER = 59; private static final int THIS_YEAR_HEADER = 59;
private MapActivity mapActivity;
private OsmandApplication app; private OsmandApplication app;
private List<Object> items = new ArrayList<>(); private List<Object> items = new ArrayList<>();
private boolean night; private boolean night;
private int screenOrientation; private int screenOrientation;
private LatLon location; private LatLon location;
private Float heading; private Float heading;
private boolean useCenter; private boolean useCenter;
private boolean showDirectionEnabled;
private List<MapMarker> showDirectionMarkers;
public MapMarkersGroupsAdapter(MapActivity mapActivity) { public MapMarkersGroupsAdapter(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication(); this.mapActivity = mapActivity;
night = !mapActivity.getMyApplication().getSettings().isLightContent(); app = mapActivity.getMyApplication();
night = !mapActivity.getMyApplication().getSettings().isLightContent();
updateShowDirectionMarkers();
createDisplayGroups(); createDisplayGroups();
} }
public void createDisplayGroups() { public void updateShowDirectionMarkers() {
showDirectionEnabled = app.getSettings().MAP_MARKERS_MODE.get() != OsmandSettings.MapMarkersMode.NONE;;
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
int markersCount = mapMarkers.size();
showDirectionMarkers = new ArrayList<>(mapMarkers.subList(0, markersCount > 0 ? markersCount > 1 ? 2 : 1 : 0));
}
public void createDisplayGroups() {
items.clear(); items.clear();
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
for (int i = 0; i < groups.size(); i++) {
MapMarkersGroup group = groups.get(i);
String markerGroupName = group.getName();
if (markerGroupName == null) {
int previousDateHeader = -1;
int monthsDisplayed = 0;
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMarkersSortedByGroup(); Calendar currentDateCalendar = Calendar.getInstance();
currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
int previousDateHeader = -1; int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
String previousNameHeader = ""; int currentMonth = currentDateCalendar.get(Calendar.MONTH);
int monthsDisplayed = 0; int currentYear = currentDateCalendar.get(Calendar.YEAR);
Calendar markerCalendar = Calendar.getInstance();
Calendar currentDateCalendar = Calendar.getInstance(); List<MapMarker> groupMarkers = group.getActiveMarkers();
currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); for (int j = 0; j < groupMarkers.size(); j++) {
int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); MapMarker marker = groupMarkers.get(j);
int currentMonth = currentDateCalendar.get(Calendar.MONTH); markerCalendar.setTimeInMillis(marker.creationDate);
int currentYear = currentDateCalendar.get(Calendar.YEAR); int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
Calendar markerCalendar = Calendar.getInstance(); int markerMonth = markerCalendar.get(Calendar.MONTH);
for (int i = 0; i < markersHistory.size(); i++) { int markerYear = markerCalendar.get(Calendar.YEAR);
MapMarker marker = markersHistory.get(i); if (markerYear == currentYear) {
markerCalendar.setTimeInMillis(marker.creationDate); if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) {
int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); items.add(TODAY_HEADER);
int markerMonth = markerCalendar.get(Calendar.MONTH); previousDateHeader = TODAY_HEADER;
int markerYear = markerCalendar.get(Calendar.YEAR); } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) {
String markerGroupName = marker.groupName; items.add(YESTERDAY_HEADER);
if (markerGroupName != null && markerGroupName.equals("")) { previousDateHeader = YESTERDAY_HEADER;
markerGroupName = app.getString(R.string.shared_string_favorites); } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) {
} items.add(LAST_SEVEN_DAYS_HEADER);
if (markerGroupName == null && markerYear == currentYear) { previousDateHeader = LAST_SEVEN_DAYS_HEADER;
if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) {
items.add(TODAY_HEADER); items.add(markerMonth);
previousDateHeader = TODAY_HEADER; previousDateHeader = markerMonth;
} else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { monthsDisplayed += 1;
items.add(YESTERDAY_HEADER); } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) {
previousDateHeader = YESTERDAY_HEADER; items.add(THIS_YEAR_HEADER);
} else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { previousDateHeader = THIS_YEAR_HEADER;
items.add(LAST_SEVEN_DAYS_HEADER); }
previousDateHeader = LAST_SEVEN_DAYS_HEADER; } else if (previousDateHeader != markerYear) {
} else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { items.add(markerYear);
items.add(markerMonth); previousDateHeader = markerYear;
previousDateHeader = markerMonth; }
monthsDisplayed += 1; items.add(marker);
} else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) { }
items.add(THIS_YEAR_HEADER); } else {
previousDateHeader = THIS_YEAR_HEADER; GroupHeader header = group.getGroupHeader();
items.add(header);
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) {
items.addAll(group.getMarkers());
} else {
items.addAll(group.getActiveMarkers());
}
if (showHideHistoryButton != null) {
items.add(showHideHistoryButton);
} }
} else if (markerGroupName == null && previousDateHeader != markerYear) {
items.add(markerYear);
previousDateHeader = markerYear;
} else if (markerGroupName != null && !previousNameHeader.equals(markerGroupName)) {
items.add(markerGroupName);
previousNameHeader = markerGroupName;
} }
items.add(marker);
} }
} }
public void setLocation(LatLon location) { public void setLocation(LatLon location) {
this.location = location; this.location = location;
} }
public void setHeading(Float heading) { public void setHeading(Float heading) {
this.heading = heading; this.heading = heading;
} }
public void setUseCenter(boolean useCenter) { public void setUseCenter(boolean useCenter) {
this.useCenter = useCenter; this.useCenter = useCenter;
} }
public void setScreenOrientation(int screenOrientation) { public void setScreenOrientation(int screenOrientation) {
this.screenOrientation = screenOrientation; this.screenOrientation = screenOrientation;
} }
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
if (viewType == MARKER_TYPE) { if (viewType == MARKER_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
return new MapMarkerItemViewHolder(view); return new MapMarkerItemViewHolder(view);
} else if (viewType == HEADER_TYPE) { } else if (viewType == HEADER_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_header, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_header, viewGroup, false);
return new MapMarkerHeaderViewHolder(view); return new MapMarkerHeaderViewHolder(view);
} else if (viewType == SHOW_HIDE_HISTORY_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_show_hide_history, viewGroup, false);
return new MapMarkersShowHideHistoryViewHolder(view);
} else { } else {
throw new IllegalArgumentException("Unsupported view type"); throw new IllegalArgumentException("Unsupported view type");
} }
} }
@Override @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
IconsCache iconsCache = app.getIconsCache(); IconsCache iconsCache = app.getIconsCache();
if (holder instanceof MapMarkerItemViewHolder) { if (holder instanceof MapMarkerItemViewHolder) {
final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder; final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
final MapMarker marker = (MapMarker) getItem(position); final MapMarker marker = (MapMarker) getItem(position);
itemViewHolder.iconReorder.setVisibility(View.GONE);
final boolean markerInHistory = marker.history;
int color = MapMarker.getColorId(marker.colorIndex); int color = MapMarker.getColorId(marker.colorIndex);
itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); ImageView markerImageViewToUpdate;
int drawableResToUpdate;
final boolean markerToHighlight = showDirectionMarkers.contains(marker);
if (showDirectionEnabled && markerToHighlight) {
itemViewHolder.iconDirection.setVisibility(View.GONE);
itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, color));
itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, R.color.color_white));
itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
markerImageViewToUpdate = itemViewHolder.icon;
} else {
itemViewHolder.iconDirection.setVisibility(View.VISIBLE);
itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_light_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed));
itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
drawableResToUpdate = R.drawable.ic_direction_arrow;
markerImageViewToUpdate = itemViewHolder.iconDirection;
}
itemViewHolder.title.setText(marker.getName(app)); itemViewHolder.title.setText(marker.getName(app));
itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate)))); if (markerInHistory) {
itemViewHolder.point.setVisibility(View.VISIBLE);
itemViewHolder.description.setVisibility(View.VISIBLE);
itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate))));
} else {
itemViewHolder.point.setVisibility(View.GONE);
itemViewHolder.description.setVisibility(View.GONE);
}
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark)); String markerGroupName = marker.groupName;
final MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByName(markerGroupName);
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() { itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
// int position = itemViewHolder.getAdapterPosition(); int position = itemViewHolder.getAdapterPosition();
// if (position < 0) { if (position < 0) {
// return; return;
// } }
// app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0); if (markerInHistory) {
// notifyItemRemoved(position); app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
if (group != null) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (showHideHistoryButton != null) {
if (group.getHistoryMarkers().size() == 0) {
items.remove(showHideHistoryButton);
group.setShowHideHistoryButton(null);
}
}
}
} else {
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
if (group != null) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (showHideHistoryButton == null) {
items.remove(marker);
showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.setShowHistory(false);
showHideHistoryButton.setMarkerGroup(group);
int index = getLastDisplayItemIndexOfGroup(group);
if (index != -1) {
items.add(index + 1, showHideHistoryButton);
group.setShowHideHistoryButton(showHideHistoryButton);
}
} else if (!showHideHistoryButton.isShowHistory()) {
items.remove(marker);
}
}
}
updateShowDirectionMarkers();
notifyDataSetChanged();
} }
}); });
itemViewHolder.iconReorder.setVisibility(View.GONE);
itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE); itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
itemViewHolder.iconDirection.setVisibility(View.GONE); boolean lastItem = position == getItemCount() - 1;
itemViewHolder.leftPointSpace.setVisibility(View.GONE); if ((getItemCount() > position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) {
itemViewHolder.rightPointSpace.setVisibility(View.GONE);
if (position == getItemCount() - 1) {
itemViewHolder.bottomShadow.setVisibility(View.VISIBLE);
itemViewHolder.divider.setVisibility(View.GONE); itemViewHolder.divider.setVisibility(View.GONE);
} else { } else {
itemViewHolder.bottomShadow.setVisibility(View.GONE);
itemViewHolder.divider.setVisibility(View.VISIBLE); itemViewHolder.divider.setVisibility(View.VISIBLE);
} }
itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
DashLocationFragment.updateLocationView(useCenter, location,
heading, markerImageViewToUpdate, drawableResToUpdate, markerToHighlight ? color : 0,
itemViewHolder.distance, markerLatLon,
screenOrientation, app, mapActivity, true);
} else if (holder instanceof MapMarkerHeaderViewHolder) { } else if (holder instanceof MapMarkerHeaderViewHolder) {
final MapMarkerHeaderViewHolder dateViewHolder = (MapMarkerHeaderViewHolder) holder; final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder;
final Object header = getItem(position); final Object header = getItem(position);
String headerString; String headerString;
if (header instanceof Integer) { if (header instanceof Integer) {
headerViewHolder.icon.setVisibility(View.GONE);
headerViewHolder.iconSpace.setVisibility(View.VISIBLE);
Integer dateHeader = (Integer) header; Integer dateHeader = (Integer) header;
if (dateHeader == TODAY_HEADER) { if (dateHeader == TODAY_HEADER) {
headerString = app.getString(R.string.today); headerString = app.getString(R.string.today);
@ -183,35 +290,77 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else { } else {
headerString = String.valueOf(dateHeader); headerString = String.valueOf(dateHeader);
} }
} else if (header instanceof String) { headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
headerString = (String) header; } else if (header instanceof GroupHeader) {
final GroupHeader groupHeader = (GroupHeader) header;
String groupName = groupHeader.getGroup().getName();
if (groupName.equals("")) {
groupName = app.getString(R.string.shared_string_favorites);
}
headerString = groupName + " \u2014 "
+ groupHeader.getGroup().getActiveMarkers().size()
+ "/" + groupHeader.getGroup().getMarkers().size();
headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
boolean groupIsDisabled = groupHeader.getGroup().isDisabled();
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
groupHeader.getGroup().setDisabled(!b);
notifyDataSetChanged();
}
});
} else { } else {
throw new IllegalArgumentException("Unsupported header"); throw new IllegalArgumentException("Unsupported header");
} }
dateViewHolder.date.setText(headerString); headerViewHolder.title.setText(headerString);
} else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
final boolean showHistory = showHideHistoryButton.isShowHistory();
showHideHistoryViewHolder.title.setText(app.getString(showHistory ? R.string.hide_passed : R.string.show_passed));
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<MapMarker> historyMarkers = showHideHistoryButton.getMapMarkerGroup().getHistoryMarkers();
int pos = holder.getAdapterPosition();
if (showHistory) {
showHideHistoryButton.setShowHistory(false);
items.removeAll(historyMarkers);
} else {
showHideHistoryButton.setShowHistory(true);
items.addAll(pos, historyMarkers);
}
notifyDataSetChanged();
}
});
} }
} }
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
Object item = items.get(position); Object item = items.get(position);
if (item instanceof MapMarker) { if (item instanceof MapMarker) {
return MARKER_TYPE; return MARKER_TYPE;
} else if (item instanceof String || item instanceof Integer) { } else if (item instanceof GroupHeader || item instanceof Integer) {
return HEADER_TYPE; return HEADER_TYPE;
} else if (item instanceof ShowHideHistoryButton) {
return SHOW_HIDE_HISTORY_TYPE;
} else { } else {
throw new IllegalArgumentException("Unsupported view type"); throw new IllegalArgumentException("Unsupported view type");
} }
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return items.size(); return items.size();
} }
public Object getItem(int position) { public Object getItem(int position) {
return items.get(position); return items.get(position);
} }
private String getMonth(int month) { private String getMonth(int month) {
SimpleDateFormat dateFormat = new SimpleDateFormat("LLLL", Locale.getDefault()); SimpleDateFormat dateFormat = new SimpleDateFormat("LLLL", Locale.getDefault());
@ -219,4 +368,22 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
date.setMonth(month); date.setMonth(month);
return dateFormat.format(date); return dateFormat.format(date);
} }
private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) {
List<MapMarker> markers = group.getActiveMarkers();
int index = -1;
for (MapMarker marker : markers) {
int markerIndex = items.indexOf(marker);
if (markerIndex > index) {
index = markerIndex;
}
}
if (index == -1) {
GroupHeader header = group.getGroupHeader();
if (header != null) {
index = items.indexOf(group.getGroupHeader());
}
}
return index;
}
} }

View file

@ -160,7 +160,8 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
} else { } else {
dateString = String.valueOf(dateHeader); dateString = String.valueOf(dateHeader);
} }
dateViewHolder.date.setText(dateString); dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
dateViewHolder.title.setText(dateString);
} }
} }

View file

@ -0,0 +1,16 @@
package net.osmand.plus.mapmarkers.adapters;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import net.osmand.plus.R;
public class MapMarkersShowHideHistoryViewHolder extends RecyclerView.ViewHolder {
final TextView title;
public MapMarkersShowHideHistoryViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.show_hide_history_title);
}
}

View file

@ -69,6 +69,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -90,7 +91,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
final private PointGPXAdapter adapter = new PointGPXAdapter(); final private PointGPXAdapter adapter = new PointGPXAdapter();
private GpxDisplayItemType[] filterTypes = { GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS }; private GpxDisplayItemType[] filterTypes = { GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS };
private boolean selectionMode = false; private boolean selectionMode = false;
private Set<GpxDisplayItem> selectedItems = new LinkedHashSet<>(); private LinkedHashMap<GpxDisplayItemType, Set<GpxDisplayItem>> selectedItems = new LinkedHashMap<>();
private Set<Integer> selectedGroups = new LinkedHashSet<>(); private Set<Integer> selectedGroups = new LinkedHashSet<>();
private ActionMode actionMode; private ActionMode actionMode;
private SearchView searchView; private SearchView searchView;
@ -213,6 +214,26 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
return view; return view;
} }
private int getSelectedItemsCount() {
int count = 0;
for (Set<GpxDisplayItem> set : selectedItems.values()) {
if (set != null) {
count += set.size();
}
}
return count;
}
private Set<GpxDisplayItem> getSelectedItems() {
Set<GpxDisplayItem> result = new LinkedHashSet<>();
for (Set<GpxDisplayItem> set : selectedItems.values()) {
if (set != null) {
result.addAll(set);
}
}
return result;
}
private void addPoint(PointDescription pointDescription) { private void addPoint(PointDescription pointDescription) {
getTrackActivity().addPoint(pointDescription); getTrackActivity().addPoint(pointDescription);
} }
@ -488,9 +509,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void deleteItemsAction() { private void deleteItemsAction() {
if (selectedItems.size() > 0) { int size = getSelectedItemsCount();
if (size > 0) {
AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setMessage(getString(R.string.points_delete_multiple, selectedItems.size())); b.setMessage(getString(R.string.points_delete_multiple, size));
b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -524,7 +546,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
GPXFile gpx = getGpx(); GPXFile gpx = getGpx();
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper(); SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
if (gpx != null) { if (gpx != null) {
for (GpxDisplayItem item : selectedItems) { for (GpxDisplayItem item : getSelectedItems()) {
if (gpx.showCurrentTrack) { if (gpx.showCurrentTrack) {
savingTrackHelper.deletePointData(item.locationStart); savingTrackHelper.deletePointData(item.locationStart);
} else { } else {
@ -606,26 +628,32 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void selectMapMarkersImpl() { private void selectMapMarkersImpl() {
if (!selectedItems.isEmpty()) { if (getSelectedItemsCount() > 0) {
if (getSettings().USE_MAP_MARKERS.get()) { if (getSettings().USE_MAP_MARKERS.get()) {
MapMarkersHelper markersHelper = app.getMapMarkersHelper(); MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<LatLon> points = new ArrayList<>(); List<LatLon> points = new LinkedList<>();
List<PointDescription> names = new ArrayList<>(); List<PointDescription> names = new LinkedList<>();
for(GpxDisplayItem i : selectedItems) { for (Map.Entry<GpxDisplayItemType, Set<GpxDisplayItem>> entry : selectedItems.entrySet()) {
if (i.locationStart != null) { if (entry.getKey() == GpxDisplayItemType.TRACK_POINTS) {
points.add(new LatLon(i.locationStart.lat, i.locationStart.lon)); File gpx = getGpxDataItem().getFile();
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroup(syncGroup);
} else {
for (GpxDisplayItem i : entry.getValue()) {
if (i.locationStart != null) {
points.add(new LatLon(i.locationStart.lat, i.locationStart.lon));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name));
}
}
markersHelper.addMapMarkers(points, names, null);
} }
} }
File gpx = getGpxDataItem().getFile();
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.addMapMarkers(points, names, syncGroup);
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} else { } else {
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
for (GpxDisplayItem i : selectedItems) { for (GpxDisplayItem i : getSelectedItems()) {
if (i.locationStart != null) { if (i.locationStart != null) {
targetPointsHelper.navigateToPoint(new LatLon(i.locationStart.lat, i.locationStart.lon), false, targetPointsHelper.navigateToPoint(new LatLon(i.locationStart.lat, i.locationStart.lon), false,
targetPointsHelper.getIntermediatePoints().size() + 1, targetPointsHelper.getIntermediatePoints().size() + 1,
@ -679,10 +707,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void selectFavoritesImpl() { private void selectFavoritesImpl() {
if (!selectedItems.isEmpty()) { if (getSelectedItemsCount() > 0) {
AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity()); AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity());
final EditText editText = new EditText(getTrackActivity()); final EditText editText = new EditText(getTrackActivity());
String name = selectedItems.iterator().next().group.getName(); String name = getSelectedItems().iterator().next().group.getName();
if(name.indexOf('\n') > 0) { if(name.indexOf('\n') > 0) {
name = name.substring(0, name.indexOf('\n')); name = name.substring(0, name.indexOf('\n'));
} }
@ -700,7 +728,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
actionMode.finish(); actionMode.finish();
} }
FavouritesDbHelper fdb = app.getFavorites(); FavouritesDbHelper fdb = app.getFavorites();
for(GpxDisplayItem i : selectedItems) { for(GpxDisplayItem i : getSelectedItems()) {
if (i.locationStart != null) { if (i.locationStart != null) {
FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString()); FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString());
if (!Algorithms.isEmpty(i.description)) { if (!Algorithms.isEmpty(i.description)) {
@ -719,8 +747,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void updateSelectionMode(ActionMode m) { private void updateSelectionMode(ActionMode m) {
if (selectedItems.size() > 0) { int size = getSelectedItemsCount();
m.setTitle(selectedItems.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); if (size > 0) {
m.setTitle(size + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase));
} else { } else {
m.setTitle(""); m.setTitle("");
} }
@ -733,9 +762,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
ch.setChecked(!ch.isChecked()); ch.setChecked(!ch.isChecked());
if (ch.isChecked()) { if (ch.isChecked()) {
selectedItems.add(item); Set<GpxDisplayItem> set = selectedItems.get(item.group.getType());
if (set != null) {
set.add(item);
} else {
set = new LinkedHashSet<>();
set.add(item);
selectedItems.put(item.group.getType(), set);
}
} else { } else {
selectedItems.remove(item); Set<GpxDisplayItem> set = selectedItems.get(item.group.getType());
if (set != null) {
set.remove(item);
}
} }
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} else { } else {
@ -876,13 +915,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
if (ch.isChecked()) { if (ch.isChecked()) {
selectedGroups.add(groupPosition); selectedGroups.add(groupPosition);
if (items != null) { if (items != null) {
selectedItems.addAll(items); Set<GpxDisplayItem> set = selectedItems.get(group.getType());
if (set != null) {
set.addAll(items);
} else {
set = new LinkedHashSet<>(items);
selectedItems.put(group.getType(), set);
}
} }
} else { } else {
selectedGroups.remove(groupPosition); selectedGroups.remove(groupPosition);
if (items != null) { selectedItems.remove(group.getType());
selectedItems.removeAll(items);
}
} }
adapter.notifyDataSetInvalidated(); adapter.notifyDataSetInvalidated();
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
@ -979,7 +1022,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
if (selectionMode) { if (selectionMode) {
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedItems.contains(gpxItem)); ch.setChecked(selectedItems.get(gpxItem.group.getType()) != null && selectedItems.get(gpxItem.group.getType()).contains(gpxItem));
row.findViewById(R.id.icon).setVisibility(View.GONE); row.findViewById(R.id.icon).setVisibility(View.GONE);
options.setVisibility(View.GONE); options.setVisibility(View.GONE);
ch.setOnClickListener(new View.OnClickListener() { ch.setOnClickListener(new View.OnClickListener() {
@ -987,9 +1030,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (ch.isChecked()) { if (ch.isChecked()) {
selectedItems.add(gpxItem); Set<GpxDisplayItem> set = selectedItems.get(gpxItem.group.getType());
if (set != null) {
set.add(gpxItem);
} else {
set = new LinkedHashSet<>();
set.add(gpxItem);
selectedItems.put(gpxItem.group.getType(), set);
}
} else { } else {
selectedItems.remove(gpxItem); Set<GpxDisplayItem> set = selectedItems.get(gpxItem.group.getType());
if (set != null) {
set.remove(gpxItem);
}
} }
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} }

View file

@ -797,7 +797,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) {
Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
boolean enabled = lastKnownLocation != null && !isLocationOutdated(lastKnownLocation); boolean enabled = lastKnownLocation != null;
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) { if (!enabled) {

View file

@ -8,13 +8,9 @@ import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -23,7 +19,6 @@ import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -36,11 +31,12 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
protected static final int DIST_TO_SHOW = 80; protected static final int DIST_TO_SHOW = 80;
protected static final long USE_FINGER_LOCATION_DELAY = 1000;
private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6;
private final MapActivity map; private final MapActivity map;
private OsmandMapTileView view; private OsmandMapTileView view;
@ -66,16 +62,14 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private Bitmap arrowToDestination; private Bitmap arrowToDestination;
private float[] calculations = new float[2]; private float[] calculations = new float[2];
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private Paint paint; private Paint paint;
private Path path; private Path path;
private List<LatLon> route = new ArrayList<>(); private List<LatLon> route = new ArrayList<>();
private LatLon fingerLocation; private TIntArrayList tx = new TIntArrayList();
private boolean hasMoved; private TIntArrayList ty = new TIntArrayList();
private boolean moving; private Path linePath = new Path();
private boolean useFingerLocation;
private GestureDetector longTapDetector;
private Handler handler;
private ContextMenuLayer contextMenuLayer; private ContextMenuLayer contextMenuLayer;
@ -190,50 +184,23 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
handler = new Handler();
initUI(); initUI();
longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
cancelFingerAction();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
});
} }
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom()); Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
widgetsFactory.updateInfo(myLoc == null
? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom());
OsmandSettings settings = map.getMyApplication().getSettings();
if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) { if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
return; return;
} }
lineAttrs.updatePaints(view, nightMode, tileBox);
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
if (route.size() > 0) { if (route.size() > 0) {
path.reset(); path.reset();
@ -259,6 +226,30 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
} }
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers(); List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) {
int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude());
int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude());
int[] colors = MapMarker.getColors(map);
for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) {
MapMarker marker = activeMapMarkers.get(i);
int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude());
int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude());
linePath.reset();
tx.clear();
ty.clear();
linePath.moveTo(locX, locY);
linePath.lineTo(markerX, markerY);
tx.add(locX);
ty.add(locY);
tx.add(markerX);
ty.add(markerY);
calculatePath(tileBox, tx, ty, linePath);
lineAttrs.paint.setColor(colors[marker.colorIndex]);
canvas.drawPath(linePath, lineAttrs.paint);
}
}
for (MapMarker marker : activeMapMarkers) { for (MapMarker marker : activeMapMarkers) {
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker)
&& !isInMotion(marker)) { && !isInMotion(marker)) {
@ -273,34 +264,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
} }
} }
boolean show = useFingerLocation || if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
(map.getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.WIDGETS LatLon loc = tileBox.getCenterLatLon();
&& map.getMyApplication().getSettings().SHOW_DESTINATION_ARROW.get()); List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
if (show) { int i = 0;
LatLon loc = fingerLocation; for (MapMarker marker : mapMarkers) {
if (!useFingerLocation) { if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
loc = tileBox.getCenterLatLon(); canvas.save();
} net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(),
if (loc != null) { marker.getLatitude(), marker.getLongitude(), calculations);
List<MapMarker> mapMarkers = markersHelper.getMapMarkers(); float bearing = calculations[1] - 90;
int i = 0; float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
for (MapMarker marker : mapMarkers) { final QuadPoint cp = tileBox.getCenterPixelPoint();
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { canvas.rotate(bearing, cp.x, cp.y);
canvas.save(); canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
marker.getLatitude(), marker.getLongitude(), calculations); canvas.restore();
float bearing = calculations[1] - 90; }
float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); i++;
final QuadPoint cp = tileBox.getCenterPixelPoint(); if (i > 1) {
canvas.rotate(bearing, cp.x, cp.y); break;
canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
canvas.restore();
}
i++;
if (i > 1) {
break;
}
} }
} }
} }
@ -354,57 +337,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
public void destroyLayer() { public void destroyLayer() {
} }
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (!longTapDetector.onTouchEvent(event)) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
float x = event.getX();
float y = event.getY();
fingerLocation = tileBox.getLatLonFromPixel(x, y);
hasMoved = false;
moving = true;
break;
case MotionEvent.ACTION_MOVE:
if (!hasMoved) {
if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) {
Message msg = Message.obtain(handler, new Runnable() {
@Override
public void run() {
handler.removeMessages(MAP_REFRESH_MESSAGE);
if (moving) {
if (!useFingerLocation) {
useFingerLocation = true;
map.refreshMap();
}
}
}
});
msg.what = MAP_REFRESH_MESSAGE;
handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY);
}
hasMoved = true;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
cancelFingerAction();
break;
}
}
return super.onTouchEvent(event, tileBox);
}
private void cancelFingerAction() {
handler.removeMessages(MAP_REFRESH_MESSAGE);
useFingerLocation = false;
moving = false;
fingerLocation = null;
map.refreshMap();
}
@Override @Override
public boolean drawInScreenPixels() { public boolean drawInScreenPixels() {
return false; return false;

View file

@ -16,13 +16,11 @@ import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.MotionEvent; import android.view.MotionEvent;
import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree; import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer;
@ -40,8 +38,6 @@ import gnu.trove.list.array.TIntArrayList;
public abstract class OsmandMapLayer { public abstract class OsmandMapLayer {
protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40;
protected List<LatLon> fullObjectsLatLon; protected List<LatLon> fullObjectsLatLon;
protected List<LatLon> smallObjectsLatLon; protected List<LatLon> smallObjectsLatLon;
@ -51,22 +47,6 @@ public abstract class OsmandMapLayer {
TWO_POINTERS_ZOOM_OUT TWO_POINTERS_ZOOM_OUT
} }
private int updatesCounter;
private boolean locationOutdated;
boolean isLocationOutdated(Location location) {
if (location != null && updatesCounter == 0) {
locationOutdated = System.currentTimeMillis() - location.getTime() >
OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON;
}
if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) {
updatesCounter = 0;
} else {
updatesCounter++;
}
return locationOutdated;
}
public boolean isMapGestureAllowed(MapGestureType type) { public boolean isMapGestureAllowed(MapGestureType type) {
return true; return true;
} }

View file

@ -64,8 +64,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
aroundArea.setAntiAlias(true); aroundArea.setAntiAlias(true);
locationProvider = view.getApplication().getLocationProvider(); locationProvider = view.getApplication().getLocationProvider();
updateIcons(view.getSettings().getApplicationMode(), false, updateIcons(view.getSettings().getApplicationMode(), false, locationProvider.getLastKnownLocation() == null);
isLocationOutdated(locationProvider.getLastKnownLocation()));
} }
@Override @Override
@ -86,9 +85,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
} }
// draw // draw
boolean nm = nightMode != null && nightMode.isNightMode(); boolean nm = nightMode != null && nightMode.isNightMode();
Location lastKnownLocation = locationProvider.getLastKnownLocation(); Location lastKnownLocation = locationProvider.getLastStaleKnownLocation();
updateIcons(view.getSettings().getApplicationMode(), nm, updateIcons(view.getSettings().getApplicationMode(), nm,
isLocationOutdated(lastKnownLocation)); view.getApplication().getLocationProvider().getLastKnownLocation() == null);
if(lastKnownLocation == null || view == null){ if(lastKnownLocation == null || view == null){
return; return;
} }