Merge branch 'master' of ssh://github.com/osmandapp/Osmand into new_notes_ui

# Conflicts:
#	OsmAnd/res/values/strings.xml
This commit is contained in:
Alexander Sytnyk 2017-11-17 10:50:46 +02:00
commit 1d4dd760b9
35 changed files with 874 additions and 388 deletions

View file

@ -1,16 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/favourites_group_recycler_view"
android:id="@+id/groups_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"
android:clipToPadding="false"/>
android:clipToPadding="false"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
android:visibility="gone"
tools:visibility="visible"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/looking_for_tracks_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@null"
android:text="@string/looking_for_tracks_with_waypoints"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:visibility="gone"
osmand:typeface="@string/font_roboto_medium"
tools:visibility="visible"/>
<View
android:layout_width="match_parent"

View file

@ -46,4 +46,10 @@
</LinearLayout>
<include
android:id="@+id/bottom_shadow"
layout="@layout/card_bottom_divider"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout>

View file

@ -2920,4 +2920,5 @@ U vypadku, kali vy lubіcie OsmAnd і OSM і chočacie padtrymać jaho, heta іd
<string name="empty_state_markers_history">\@string/shared_string_history</string>
<string name="shared_string_right">Naprava</string>
<string name="shared_string_left">Nalieva</string>
<string name="shared_string_more_without_dots">Boĺš</string>
</resources>

View file

@ -2969,4 +2969,5 @@
<string name="empty_state_markers_history">\@string/shared_string_history</string>
<string name="shared_string_right">Направа</string>
<string name="shared_string_left">Налева</string>
<string name="shared_string_more_without_dots">Больш</string>
</resources>

View file

@ -2722,4 +2722,5 @@ Abasta l\'àrea: %1$s x %2$s</string>
<string name="show_arrows_descr">Mostra una o dues fletxes indicant la direcció dels marcadors actius.</string>
<string name="distance_indication_descr">Seleccioneu com indicar la distància als marcadors actius.</string>
<string name="active_markers_descr">Trieu quants indicadors de direcció es mostren.</string>
<string name="shared_string_more_without_dots">Més</string>
</resources>

View file

@ -2953,4 +2953,5 @@ OsmAnd (Automated Navigation Directions) 是一個地圖和導航的應用程式
<string name="empty_state_markers_history_desc">標記為已通過的標點將顯現在此螢幕上。</string>
<string name="show_guide_line_descr">從您的位置顯示指引路線到現行的標記位置。</string>
<string name="show_arrows_descr">顯示一個或兩個箭頭指示方向到現行的標記。</string>
<string name="shared_string_more_without_dots">更多</string>
</resources>

View file

@ -12,10 +12,11 @@
<string name="notes_by_date">Notes by date</string>
<string name="by_date">By date</string>
<string name="by_type">By type</string>
<string name="looking_for_tracks_with_waypoints">Looking for tracks with waypoints</string>
<string name="shared_string_more_without_dots">More</string>
<string name="appearance_on_the_map">Appearance on the map</string>
<string name="add_track_to_markers_descr">Select track waypoints of which OsmAnd will add to markers</string>
<string name="add_favourites_group_to_markers_descr">Select favorite groups you want to add to the markers.</string>
<string name="add_favourites_group_to_markers_descr">Select favorite group you want to add to markers. We show only tracks with waypoints</string>
<string name="track_waypoints">Track waypoints</string>
<string name="favourites_group">Favorites group</string>
<string name="add_group">Add group</string>

View file

@ -522,7 +522,7 @@ public class AppInitializer implements IProgress {
notifyEvent(InitEvents.LOAD_GPX_TRACKS);
saveGPXTracks();
notifyEvent(InitEvents.SAVE_GPX_TRACKS);
app.mapMarkersHelper.syncAllGroups();
app.mapMarkersHelper.syncAllGroupsAsync();
// restore backuped favorites to normal file
restoreBackupForFavoritesFiles();
notifyEvent(InitEvents.RESTORE_BACKUPS);

View file

@ -124,7 +124,7 @@ public class FavouritesDbHelper {
cachedFavoritePoints.remove(p);
}
for (FavoriteGroup gr : groupsToSync) {
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
}
}
if (groupsToDelete != null) {
@ -147,7 +147,7 @@ public class FavouritesDbHelper {
FavoriteGroup group = flatGroups.get(p.getCategory());
if (group != null) {
group.points.remove(p);
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
}
cachedFavoritePoints.remove(p);
}
@ -177,7 +177,7 @@ public class FavouritesDbHelper {
sortAll();
saveCurrentPointsIntoFile();
}
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
return true;
}
@ -272,7 +272,7 @@ public class FavouritesDbHelper {
}
sortAll();
saveCurrentPointsIntoFile();
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
return true;
}
@ -280,7 +280,7 @@ public class FavouritesDbHelper {
p.setLatitude(lat);
p.setLongitude(lon);
saveCurrentPointsIntoFile();
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
return true;
}
@ -597,7 +597,7 @@ public class FavouritesDbHelper {
for (FavouritePoint p : gr.points) {
p.setColor(color);
}
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
}
if (group.visible != visible) {
FavoriteGroup gr = flatGroups.get(group.name);
@ -605,7 +605,7 @@ public class FavouritesDbHelper {
for (FavouritePoint p : gr.points) {
p.setVisible(visible);
}
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
}
if (!group.name.equals(newName)) {
FavoriteGroup gr = flatGroups.remove(group.name);
@ -627,7 +627,7 @@ public class FavouritesDbHelper {
}
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
}
saveCurrentPointsIntoFile();
}

View file

@ -392,7 +392,7 @@ public class GpxSelectionHelper {
public void setGpxFileToDisplay(GPXFile... gpxs) {
// special case for gpx current route
for (GPXFile gpx : gpxs) {
selectGpxFileImpl(gpx, true, false);
selectGpxFileImpl(gpx, true, false, true);
}
saveCurrentSelections();
}
@ -458,7 +458,7 @@ public class GpxSelectionHelper {
app.getSettings().SELECTED_GPX.set(ar.toString());
}
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup) {
boolean displayed;
SelectedGpxFile sf;
if (gpx != null && gpx.showCurrentTrack) {
@ -482,12 +482,18 @@ public class GpxSelectionHelper {
selectedGPXFiles.remove(sf);
}
}
syncGpx(gpx);
if (syncGroup) {
syncGpx(gpx, true);
}
return sf;
}
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, show, notShowNavigationDialog);
return selectGpxFile(gpx, show, notShowNavigationDialog, true);
}
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, show, notShowNavigationDialog, syncGroup);
saveCurrentSelections();
return sf;
}
@ -514,10 +520,25 @@ public class GpxSelectionHelper {
}
private void syncGpx(GPXFile gpxFile) {
syncGpx(gpxFile, false);
}
private void syncGpx(GPXFile gpxFile, boolean createOrDeleteGroup) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
boolean enabled = true;
if (createOrDeleteGroup) {
boolean show = getSelectedFileByPath(gpx.getAbsolutePath()) != null;
enabled = mapMarkersHelper.isGroupSynced(gpx.getAbsolutePath());
if (show && !enabled) {
mapMarkersHelper.addMarkersSyncGroup(syncGroup);
} else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) {
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true);
}
}
mapMarkersHelper.syncGroupAsync(syncGroup, enabled);
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus;
import android.content.Context;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
@ -23,11 +24,12 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -42,6 +44,7 @@ public class MapMarkersHelper {
private OsmandApplication ctx;
private MapMarkersDbHelper markersDbHelper;
private boolean startFromMyLocation;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private MarkersPlanRouteContext planRouteContext;
@ -51,6 +54,10 @@ public class MapMarkersHelper {
void onMapMarkersChanged();
}
public interface OnGroupSyncedListener {
void onSyncDone();
}
public static class MapMarker implements LocationPoint {
private static int[] colors;
@ -188,6 +195,8 @@ public class MapMarkersHelper {
public static final int FAVORITES_TYPE = 0;
public static final int GPX_TYPE = 1;
public static final String MARKERS_SYNC_GROUP_ID = "markers_sync_group_id";
private String id;
private String name;
private int type;
@ -262,22 +271,96 @@ public class MapMarkersHelper {
}
private void loadMarkers() {
mapMarkers.clear();
mapMarkersHistory.clear();
mapMarkers = new LinkedList<>();
mapMarkersHistory = new LinkedList<>();
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
mapMarkers.addAll(activeMarkers);
addToMapMarkersList(activeMarkers);
reorderActiveMarkersIfNeeded();
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
mapMarkersHistory.addAll(markersHistory);
addToMapMarkersHistoryList(markersHistory);
if (!ctx.isApplicationInitializing()) {
lookupAddressAll();
}
}
private void removeFromMapMarkersList(List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
copyList.removeAll(markers);
mapMarkers = copyList;
}
private void removeFromMapMarkersList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
copyList.remove(marker);
mapMarkers = copyList;
}
private void addToMapMarkersList(MapMarker marker) {
addToMapMarkersList(mapMarkers.size(), marker);
}
private void addToMapMarkersList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
copyList.add(position, marker);
mapMarkers = copyList;
}
private void addToMapMarkersList(List<MapMarker> markers) {
addToMapMarkersList(mapMarkers.size(), markers);
}
private void addToMapMarkersList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
copyList.addAll(position, markers);
mapMarkers = copyList;
}
private void removeFromMapMarkersHistoryList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
copyList.remove(marker);
mapMarkersHistory = copyList;
}
private void addToMapMarkersHistoryList(MapMarker marker) {
addToMapMarkersHistoryList(mapMarkersHistory.size(), marker);
}
private void addToMapMarkersHistoryList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
copyList.add(position, marker);
mapMarkersHistory = copyList;
}
private void addToMapMarkersHistoryList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
copyList.addAll(position, markers);
mapMarkersHistory = copyList;
}
private void addToMapMarkersHistoryList(List<MapMarker> markers) {
addToMapMarkersHistoryList(mapMarkersHistory.size(), markers);
}
private void removeFromGroupsList(MapMarkersGroup group) {
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.remove(group);
mapMarkersGroups = copyList;
}
private void addToGroupsList(int position, MapMarkersGroup group) {
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.add(position, group);
mapMarkersGroups = copyList;
}
private void addToGroupsList(MapMarkersGroup group) {
addToGroupsList(mapMarkersGroups.size(), group);
}
public void reorderActiveMarkersIfNeeded() {
if (!mapMarkers.isEmpty()) {
if (mapMarkers.size() > 1) {
@ -361,65 +444,123 @@ public class MapMarkersHelper {
return markersDbHelper.getGroup(id) != null;
}
public void syncAllGroups() {
public boolean isGroupDisabled(String id) {
return markersDbHelper.isGroupDisabled(id);
}
public void syncAllGroupsAsync() {
List<MarkersSyncGroup> groups = markersDbHelper.getAllGroups();
for (MarkersSyncGroup gr : groups) {
syncGroup(gr);
syncGroupAsync(gr);
}
}
public void syncGroup(MarkersSyncGroup group) {
if (!isGroupSynced(group.getId())) {
return;
public void syncGroupAsync(MarkersSyncGroup group) {
syncGroupAsync(group, true, null);
}
public void syncGroupAsync(MarkersSyncGroup group, boolean enabled) {
syncGroupAsync(group, enabled, null);
}
public void syncGroupAsync(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) {
syncGroupAsync(group, true, groupSyncedListener);
}
private void syncGroupAsync(final MarkersSyncGroup group, final boolean enabled, final OnGroupSyncedListener groupSyncedListener) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
SyncGroupTask syncGroupTask = new SyncGroupTask(group, enabled, groupSyncedListener);
syncGroupTask.executeOnExecutor(executorService);
}
});
}
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
private MarkersSyncGroup group;
private boolean enabled;
private OnGroupSyncedListener listener;
SyncGroupTask(MarkersSyncGroup group, boolean enabled, OnGroupSyncedListener listener) {
this.group = group;
this.enabled = enabled;
this.listener = listener;
}
List<MapMarker> dbMarkers = markersDbHelper.getMarkersFromGroup(group);
if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) {
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
if (!favGroup.visible) {
removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return;
}
if (group.getColor() == -1) {
group.setColor(favGroup.color);
}
@Override
protected Void doInBackground(Void... voids) {
runGroupSynchronization();
return null;
}
for (FavouritePoint fp : favGroup.points) {
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName());
}
removeOldMarkersIfNeeded(dbMarkers);
} else if (group.getType() == MarkersSyncGroup.GPX_TYPE) {
GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
File file = new File(group.getId());
if (!file.exists()) {
private void runGroupSynchronization() {
if (!isGroupSynced(group.getId())) {
return;
}
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
if (gpx == null) {
removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return;
}
List<MapMarker> dbMarkers = markersDbHelper.getMarkersFromGroup(group);
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor));
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name);
}
if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) {
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
if (!favGroup.visible) {
removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return;
}
if (group.getColor() == -1) {
group.setColor(favGroup.color);
}
removeOldMarkersIfNeeded(dbMarkers);
for (FavouritePoint fp : favGroup.points) {
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled);
}
removeOldMarkersIfNeeded(dbMarkers);
} else if (group.getType() == MarkersSyncGroup.GPX_TYPE) {
GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
File file = new File(group.getId());
if (!file.exists()) {
return;
}
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
if (gpx == null) {
removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return;
}
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor));
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled);
}
removeOldMarkersIfNeeded(dbMarkers);
}
}
@Override
protected void onPostExecute(Void aVoid) {
if (listener != null) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
listener.onSyncDone();
}
});
}
}
}
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name) {
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled) {
boolean exists = false;
for (MapMarker marker : markers) {
@ -441,7 +582,7 @@ public class MapMarkersHelper {
if (!exists) {
addMarkers(Collections.singletonList(latLon),
Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, name)), group);
Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, name)), group, enabled);
}
}
@ -451,7 +592,7 @@ public class MapMarkersHelper {
for (MapMarker marker : markers) {
if (!marker.history) {
markersDbHelper.removeMarker(marker, false);
mapMarkers.remove(marker);
removeFromMapMarkersList(marker);
removeMarkerFromGroup(marker);
needRefresh = true;
}
@ -467,10 +608,10 @@ public class MapMarkersHelper {
if (marker != null) {
cancelPointAddressRequests(marker.point);
markersDbHelper.moveMarkerToHistory(marker);
mapMarkers.remove(marker);
removeFromMapMarkersList(marker);
marker.history = true;
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
mapMarkersHistory.add(marker);
addToMapMarkersHistoryList(marker);
reorderActiveMarkersIfNeeded();
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh();
@ -480,11 +621,9 @@ public class MapMarkersHelper {
public void addMarkers(List<MapMarker> markers) {
if (markers != null) {
markersDbHelper.addMarkers(markers);
mapMarkers.addAll(markers);
addToMapMarkersList(markers);
reorderActiveMarkersIfNeeded();
for (MapMarker marker : markers) {
addMarkerToGroup(marker);
}
addMarkersToGroups(markers, true);
refresh();
}
}
@ -493,10 +632,10 @@ public class MapMarkersHelper {
if (marker != null) {
markersDbHelper.addMarker(marker);
if (marker.history) {
mapMarkersHistory.add(marker);
addToMapMarkersHistoryList(marker);
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
} else {
mapMarkers.add(marker);
addToMapMarkersList(marker);
reorderActiveMarkersIfNeeded();
}
addMarkerToGroup(marker);
@ -507,9 +646,9 @@ public class MapMarkersHelper {
public void restoreMarkerFromHistory(MapMarker marker, int position) {
if (marker != null) {
markersDbHelper.restoreMapMarkerFromHistory(marker);
mapMarkersHistory.remove(marker);
removeFromMapMarkersHistoryList(marker);
marker.history = false;
mapMarkers.add(position, marker);
addToMapMarkersList(position, marker);
reorderActiveMarkersIfNeeded();
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
refresh();
@ -520,9 +659,9 @@ public class MapMarkersHelper {
if (markers != null) {
for (MapMarker marker : markers) {
markersDbHelper.restoreMapMarkerFromHistory(marker);
mapMarkersHistory.remove(marker);
removeFromMapMarkersHistoryList(marker);
marker.history = false;
mapMarkers.add(marker);
addToMapMarkersList(marker);
}
reorderActiveMarkersIfNeeded();
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
@ -536,9 +675,9 @@ public class MapMarkersHelper {
boolean history = marker.history;
markersDbHelper.removeMarker(marker, history);
if (history) {
mapMarkersHistory.remove(marker);
removeFromMapMarkersHistoryList(marker);
} else {
mapMarkers.remove(marker);
removeFromMapMarkersList(marker);
}
removeMarkerFromGroup(marker);
refresh();
@ -613,8 +752,8 @@ public class MapMarkersHelper {
return;
}
mapMarkers.removeAll(markersToRemove);
mapMarkers.addAll(0, markers);
removeFromMapMarkersList(markersToRemove);
addToMapMarkersList(0, markers);
reorderActiveMarkersIfNeeded();
ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
}
@ -661,8 +800,8 @@ public class MapMarkersHelper {
marker.history = true;
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
}
mapMarkersHistory.addAll(mapMarkers);
mapMarkers.clear();
addToMapMarkersHistoryList(mapMarkers);
mapMarkers = new LinkedList<>();
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
updateGroups();
refresh();
@ -671,7 +810,7 @@ public class MapMarkersHelper {
public void removeMarkersHistory() {
cancelAddressRequests();
markersDbHelper.clearAllMarkersHistory();
mapMarkersHistory.clear();
mapMarkersHistory = new LinkedList<>();
refresh();
removeHistoryMarkersFromGroups();
}
@ -690,9 +829,9 @@ public class MapMarkersHelper {
if (removeActiveMarkers) {
removeActiveMarkersFromSyncGroup(id);
}
MapMarkersGroup group = getMapMarkerGroupByName(id);
MapMarkersGroup group = getMapMarkerGroupByKey(id);
if (group != null) {
mapMarkersGroups.remove(group);
removeFromGroupsList(group);
}
}
}
@ -714,15 +853,15 @@ public class MapMarkersHelper {
for (MapMarker marker : groupMarkers) {
if (marker.history) {
if (disabled) {
mapMarkersHistory.remove(marker);
removeFromMapMarkersHistoryList(marker);
} else {
mapMarkersHistory.add(marker);
addToMapMarkersHistoryList(marker);
}
} else {
if (disabled) {
mapMarkers.remove(marker);
removeFromMapMarkersList(marker);
} else {
mapMarkers.add(marker);
addToMapMarkersList(marker);
}
}
}
@ -734,10 +873,12 @@ public class MapMarkersHelper {
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
if (syncGroupId != null) {
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
for (Iterator<MapMarker> iterator = mapMarkers.iterator(); iterator.hasNext(); ) {
String groupKey = iterator.next().groupKey;
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
for (int i = 0; i < copyList.size(); i++) {
MapMarker marker = copyList.get(i);
String groupKey = marker.groupKey;
if (groupKey != null && groupKey.equals(syncGroupId)) {
iterator.remove();
removeFromMapMarkersList(marker);
}
}
reorderActiveMarkersIfNeeded();
@ -746,16 +887,17 @@ public class MapMarkersHelper {
}
public void addMapMarker(LatLon point, PointDescription historyName) {
addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null);
addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true);
}
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
addMarkers(points, historyNames, group);
addMarkers(points, historyNames, group, true);
}
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, boolean enabled) {
if (points.size() > 0) {
int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
LatLon point = points.get(i);
PointDescription historyName = historyNames.get(i);
@ -790,11 +932,14 @@ public class MapMarkersHelper {
marker.history = false;
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
markersDbHelper.addMarker(marker);
mapMarkers.add(0, marker);
addMarkerToGroup(marker);
if (enabled) {
addToMapMarkersList(0, marker);
}
addedMarkers.add(marker);
reorderActiveMarkersIfNeeded();
lookupAddress(marker);
}
addMarkersToGroups(addedMarkers, enabled);
}
}
@ -810,8 +955,8 @@ public class MapMarkersHelper {
public void moveMarkerToTop(MapMarker marker) {
int i = mapMarkers.indexOf(marker);
if (i != -1 && mapMarkers.size() > 1) {
mapMarkers.remove(i);
mapMarkers.add(0, marker);
removeFromMapMarkersList(marker);
addToMapMarkersList(0, marker);
reorderActiveMarkersIfNeeded();
refresh();
}
@ -879,16 +1024,26 @@ public class MapMarkersHelper {
listeners.remove(l);
}
private void refreshMarker(MapMarker marker) {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkerChanged(marker);
}
private void refreshMarker(final MapMarker marker) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkerChanged(marker);
}
}
});
}
private void refreshMarkers() {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkersChanged();
}
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkersChanged();
}
}
});
}
public void refresh() {
@ -971,7 +1126,7 @@ public class MapMarkersHelper {
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
if (mapMarkersGroup.getMarkers().size() == 0) {
mapMarkersGroups.remove(mapMarkersGroup);
removeFromGroupsList(mapMarkersGroup);
return;
}
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
@ -988,7 +1143,23 @@ public class MapMarkersHelper {
}
}
private void addMarkerToGroup(MapMarker marker) {
private void addMarkersToGroups(List<MapMarker> markers, boolean enabled) {
List<MapMarkersGroup> groups = new ArrayList<>();
for (int i = 0; i < markers.size(); i++) {
MapMarkersGroup group = addMarkerToGroup(markers.get(i));
if (group != null && !groups.contains(group)) {
groups.add(group);
}
}
if (!enabled) {
for (MapMarkersGroup mapMarkersGroup : groups) {
mapMarkersGroup.setDisabled(true);
updateGroupDisabled(mapMarkersGroup, true);
}
}
}
private MapMarkersGroup addMarkerToGroup(MapMarker marker) {
if (marker != null) {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName);
if (mapMarkersGroup != null) {
@ -998,11 +1169,13 @@ public class MapMarkersHelper {
sortMarkers(mapMarkersGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
}
} else {
MapMarkersGroup group = createMapMarkerGroup(marker);
group.getMarkers().add(marker);
createHeaderAndHistoryButtonInGroup(group);
mapMarkersGroup = createMapMarkerGroup(marker);
mapMarkersGroup.getMarkers().add(marker);
createHeaderAndHistoryButtonInGroup(mapMarkersGroup);
}
return mapMarkersGroup;
}
return null;
}
private MapMarkersGroup createMapMarkerGroup(MapMarker marker) {
@ -1019,7 +1192,7 @@ public class MapMarkersHelper {
group.setColor(MapMarker.getColorId(marker.colorIndex));
}
group.setCreationDate(marker.creationDate);
mapMarkersGroups.add(group);
addToGroupsList(group);
sortGroups();
return group;
}
@ -1092,7 +1265,7 @@ public class MapMarkersHelper {
}
mapMarkersGroups = new ArrayList<>(groupsMap.values());
if (noGroup != null) {
mapMarkersGroups.add(noGroup);
addToGroupsList(noGroup);
}
sortGroups();
@ -1108,7 +1281,8 @@ public class MapMarkersHelper {
MapMarkersGroup group = mapMarkersGroups.get(i);
if (group.getName() == null) {
sortMarkers(group.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
noGroup = mapMarkersGroups.remove(i);
removeFromGroupsList(group);
noGroup = group;
}
}
Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
@ -1126,7 +1300,7 @@ public class MapMarkersHelper {
}
});
if (noGroup != null) {
mapMarkersGroups.add(0, noGroup);
addToGroupsList(0, noGroup);
}
}
}

View file

@ -23,9 +23,6 @@ import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.IconsCache;
@ -37,9 +34,6 @@ import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = "EditFavoriteGroupDialogFragment";
@ -188,7 +182,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
@Override
public void onClick(View v) {
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}

View file

@ -412,7 +412,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
if (entry.getValue().size() == favGr.points.size()) {
markersHelper.addMarkersSyncGroup(syncGr);
markersHelper.syncGroup(syncGr);
markersHelper.syncGroupAsync(syncGr);
} else {
for (FavouritePoint fp : entry.getValue()) {
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));

View file

@ -60,6 +60,7 @@ import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OnDismissDialogFragmentListener;
@ -714,7 +715,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
}
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
MapMarkersDialogFragment.showInstance(this, true);
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
if (openMapMarkersGroupsExtra != null) {
MapMarkersDialogFragment.showInstance(this, openMapMarkersGroupsExtra.getString(MapMarkersHelper.MarkersSyncGroup.MARKERS_SYNC_GROUP_ID));
}
setIntent(null);
}
}
mapView.refreshMap(true);
@ -1460,7 +1465,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return mapLayers;
}
public static void launchMapActivityMoveToTop(Context activity, String intentExtraActionName) {
public static void launchMapActivityMoveToTop(Context activity, String intentExtraActionName, Bundle intentExtraActionValue) {
if (activity instanceof MapActivity) {
if (((MapActivity) activity).getDashboard().isVisible()) {
((MapActivity) activity).getDashboard().hideDashboard();
@ -1483,14 +1488,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
.getAppCustomization().getMapActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (intentExtraActionName != null) {
newIntent.putExtra(intentExtraActionName, true);
newIntent.putExtra(intentExtraActionName, intentExtraActionValue);
}
activity.startActivity(newIntent);
}
}
public static void launchMapActivityMoveToTop(Context activity) {
launchMapActivityMoveToTop(activity, null);
launchMapActivityMoveToTop(activity, null, null);
}
public static void clearPrevActivityIntent() {

View file

@ -180,7 +180,7 @@ public class WptPtEditorFragment extends PointEditorFragment {
private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
getMyApplication().getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
getMyApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
}
}

View file

@ -1,84 +1,33 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter;
import java.util.List;
public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
public class AddFavouritesGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "AddFavouritesGroupBottomSheetDialogFragment";
private AddFavouriteGroupListener listener;
private List<FavoriteGroup> favoriteGroups;
private MapMarkersHelper mapMarkersHelper;
public void setListener(AddFavouriteGroupListener listener) {
this.listener = listener;
}
private FavouritesDbHelper favouritesDbHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
favoriteGroups = getMyApplication().getFavorites().getFavoriteGroups();
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
favouritesDbHelper = getMyApplication().getFavorites();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_favourites_group_bottom_sheet_dialog, container);
final RecyclerView recyclerView = mainView.findViewById(R.id.favourites_group_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final FavouritesGroupsAdapter adapter = new FavouritesGroupsAdapter(getContext(), favoriteGroups);
adapter.setAdapterListener(new FavouritesGroupsAdapter.FavouritesGroupsAdapterListener() {
@Override
public void onItemClick(View view) {
int position = recyclerView.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) {
return;
}
FavoriteGroup group = favoriteGroups.get(position - 1);
MarkersSyncGroup markersSyncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
mapMarkersHelper.addMarkersSyncGroup(markersSyncGroup);
mapMarkersHelper.syncGroup(markersSyncGroup);
if (listener != null) {
listener.onFavouriteGroupAdded();
}
dismiss();
}
});
recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.favourites_group_recycler_view);
return mainView;
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
FavoriteGroup group = favouritesDbHelper.getFavoriteGroups().get(position - 1);
if (!group.visible) {
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
}
return new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
}
public interface AddFavouriteGroupListener {
void onFavouriteGroupAdded();
@Override
public void createAdapter() {
adapter = new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
}
}

View file

@ -0,0 +1,103 @@
package net.osmand.plus.mapmarkers;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = "AddGroupBottomSheetDialogFragment";
private AddGroupListener listener;
protected View mainView;
protected GroupsAdapter adapter;
protected MapMarkersHelper mapMarkersHelper;
public void setListener(AddGroupListener listener) {
this.listener = listener;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, container);
final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
createAdapter();
adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {
@Override
public void onItemClick(View view) {
int position = recyclerView.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) {
return;
}
showProgressBar();
MarkersSyncGroup group = createMapMarkersSyncGroup(position);
mapMarkersHelper.addMarkersSyncGroup(group);
mapMarkersHelper.syncGroupAsync(group, new MapMarkersHelper.OnGroupSyncedListener() {
@Override
public void onSyncDone() {
if (listener != null) {
listener.onGroupAdded();
}
dismiss();
}
});
}
});
recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.groups_recycler_view);
return mainView;
}
@Override
public void onDestroyView() {
Dialog dialog = getDialog();
if (dialog != null && getRetainInstance()) {
dialog.setDismissMessage(null);
}
super.onDestroyView();
}
private void showProgressBar() {
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
}
protected abstract void createAdapter();
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position);
public interface AddGroupListener {
void onGroupAdded();
}
}

View file

@ -0,0 +1,157 @@
package net.osmand.plus.mapmarkers;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
private ProcessGpxTask asyncProcessor;
private List<GpxDataItem> gpxList;
private GpxSelectionHelper gpxSelectionHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gpxSelectionHelper = getMyApplication().getSelectedGpxHelper();
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
asyncProcessor = new ProcessGpxTask();
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void createAdapter() {
gpxList = new ArrayList<>();
adapter = new TracksGroupsAdapter(getContext(), gpxList);
}
@Override
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
GpxDataItem gpxDataItem = gpxList.get(position - 1);
File gpx = gpxDataItem.getFile();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
if (selectedGpxFile == null) {
GPXFile res = GPXUtilities.loadGPXFile(getContext(), gpx);
gpxSelectionHelper.selectGpxFile(res, true, false, false);
}
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (asyncProcessor != null) {
asyncProcessor.cancel(false);
asyncProcessor = null;
}
}
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {
private OsmandApplication app = getMyApplication();
private Map<File, GpxDataItem> processedDataFiles = new HashMap<>();
private GPXDatabase db = app.getGpxDatabase();
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);;
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
private TextView lookingForTracksText = (TextView) mainView.findViewById(R.id.looking_for_tracks_text);
ProcessGpxTask() {
List<GpxDataItem> dataItems = db.getItems();
for (GpxDataItem item : dataItems) {
processedDataFiles.put(item.getFile(), item);
}
}
@Override
protected void onPreExecute() {
recyclerView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
lookingForTracksText.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
File gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
if (gpxPath.canRead()) {
processGPXFolder(gpxPath, "");
}
return null;
}
private File[] listFilesSorted(File dir) {
File[] listFiles = dir.listFiles();
if (listFiles == null) {
return new File[0];
}
Arrays.sort(listFiles);
return listFiles;
}
private void processGPXFolder(File gpxPath, String gpxSubfolder) {
for (File gpxFile : listFilesSorted(gpxPath)) {
if (gpxFile.isDirectory()) {
String sub = gpxSubfolder.length() == 0 ?
gpxFile.getName() : gpxSubfolder + "/" + gpxFile.getName();
processGPXFolder(gpxFile, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxDataItem item = processedDataFiles.get(gpxFile);
if (item == null || item.getFileLastModifiedTime() != gpxFile.lastModified()) {
GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile);
GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified());
if (item == null) {
item = new GpxDataItem(gpxFile, analysis);
db.add(item);
} else {
db.updateAnalysis(item, analysis);
}
}
processedDataFiles.put(gpxFile, item);
if (item.getAnalysis().wptPoints > 0) {
gpxList.add(item);
}
}
if (isCancelled()) {
break;
}
}
}
@Override
protected void onPostExecute(Void aVoid) {
asyncProcessor = null;
adapter.notifyDataSetChanged();
progressBar.setVisibility(View.GONE);
lookingForTracksText.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
}
}

View file

@ -159,6 +159,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
void updateAdapter() {
if (adapter != null) {
adapter.changeMarkers();
adapter.notifyDataSetChanged();
}
}

View file

@ -87,7 +87,8 @@ public class MapMarkersDbHelper {
private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " +
GROUPS_COL_NAME + ", " +
GROUPS_COL_TYPE +
GROUPS_COL_TYPE + ", " +
GROUPS_COL_DISABLED +
" FROM " + GROUPS_TABLE_NAME;
public static final String TAIL_NEXT_VALUE = "tail_next";
@ -275,6 +276,23 @@ public class MapMarkersDbHelper {
}
}
public boolean isGroupDisabled(String id) {
boolean disabled = false;
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id});
if (query.moveToFirst()) {
disabled = query.getInt(3) == 1;
}
query.close();
} finally {
db.close();
}
}
return disabled;
}
public void removeDisabledGroups() {
SQLiteConnection db = openConnection(false);
if (db != null) {

View file

@ -62,6 +62,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private BottomNavigationView bottomNav;
private boolean lightTheme;
private String groupIdToOpen;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -88,11 +89,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
Bundle args = getArguments();
boolean openGroups = false;
if (args != null && args.getBoolean(OPEN_MAP_MARKERS_GROUPS)) {
openGroups = true;
}
List<Fragment> fragments = getChildFragmentManager().getFragments();
if (fragments != null) {
for (Fragment fragment : fragments) {
@ -167,10 +163,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
}
if (openGroups) {
if (groupIdToOpen != null) {
activeFragment.stopLocationUpdate();
groupsFragment.startLocationUpdate();
groupsFragment.updateAdapter();
groupsFragment.setGroupIdToOpen(groupIdToOpen);
viewPager.setCurrentItem(GROUPS_POSITION, false);
}
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -246,6 +242,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
}
}
private void setGroupIdToOpen(String groupIdToOpen) {
this.groupIdToOpen = groupIdToOpen;
}
private void updateAdapters() {
activeFragment.updateAdapter();
groupsFragment.updateAdapter();
@ -470,20 +470,16 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
}
public static boolean showInstance(@NonNull MapActivity mapActivity) {
return showInstance(mapActivity, false);
return showInstance(mapActivity, null);
}
public static boolean showInstance(@NonNull MapActivity mapActivity, boolean openGroups) {
public static boolean showInstance(@NonNull MapActivity mapActivity, String groupIdToOpen) {
try {
if (mapActivity.isActivityDestroyed()) {
return false;
}
MapMarkersDialogFragment fragment = new MapMarkersDialogFragment();
if (openGroups) {
Bundle args = new Bundle();
args.putBoolean(OPEN_MAP_MARKERS_GROUPS, true);
fragment.setArguments(args);
}
fragment.setGroupIdToOpen(groupIdToOpen);
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {

View file

@ -33,10 +33,9 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.mapmarkers.AddFavouritesGroupBottomSheetDialogFragment.AddFavouriteGroupListener;
import net.osmand.plus.mapmarkers.AddMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter;
import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.widgets.EmptyStateRecyclerView;
import net.osmand.util.MapUtils;
@ -54,6 +53,7 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
private Snackbar snackbar;
private boolean compassUpdateAllowed = true;
private View mainView;
private String groupIdToOpen;
@Nullable
@Override
@ -62,13 +62,13 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false);
Fragment addMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(AddMarkersGroupBottomSheetDialogFragment.TAG);
if (addMarkersGroupFragment != null) {
((AddMarkersGroupBottomSheetDialogFragment) addMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
Fragment selectionMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(SelectionMarkersGroupBottomSheetDialogFragment.TAG);
if (selectionMarkersGroupFragment != null) {
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
}
Fragment addFavouritesGroupFragment = getChildFragmentManager().findFragmentByTag(AddFavouritesGroupBottomSheetDialogFragment.TAG);
if (addFavouritesGroupFragment != null) {
((AddFavouritesGroupBottomSheetDialogFragment) addFavouritesGroupFragment).setListener(createAddFavouritesGroupListener());
Fragment addGroupFragment = getChildFragmentManager().findFragmentByTag(AddGroupBottomSheetDialogFragment.TAG);
if (addGroupFragment != null) {
((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
}
final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
@ -185,10 +185,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
int snackbarStringRes;
if (direction == ItemTouchHelper.RIGHT) {
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName);
if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
}
snackbarStringRes = R.string.marker_moved_to_history;
} else {
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
@ -270,31 +266,43 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
openAddGroupMenu();
}
});
if (groupIdToOpen != null) {
int groupHeaderPosition = adapter.getGroupHeaderPosition(groupIdToOpen);
if (groupHeaderPosition != -1) {
((EmptyStateRecyclerView) mainView.findViewById(R.id.list)).scrollToPosition(groupHeaderPosition);
}
}
return mainView;
}
void setGroupIdToOpen(String groupIdToOpen) {
this.groupIdToOpen = groupIdToOpen;
}
private void changeFabVisibilityIfNeeded() {
mainView.findViewById(R.id.add_group_fab).setVisibility(adapter.getItemCount() > 0 ? View.VISIBLE : View.GONE);
}
private void openAddGroupMenu() {
AddMarkersGroupBottomSheetDialogFragment fragment = new AddMarkersGroupBottomSheetDialogFragment();
SelectionMarkersGroupBottomSheetDialogFragment fragment = new SelectionMarkersGroupBottomSheetDialogFragment();
fragment.setListener(createAddMarkersGroupFragmentListener());
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), AddMarkersGroupBottomSheetDialogFragment.TAG);
fragment.show(getChildFragmentManager(), SelectionMarkersGroupBottomSheetDialogFragment.TAG);
}
private void openAddFavouritesGroupMenu() {
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
fragment.setListener(createAddFavouritesGroupListener());
private void openAddGroupMenu(AddGroupBottomSheetDialogFragment fragment) {
fragment.setListener(createAddGroupListener());
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), AddFavouritesGroupBottomSheetDialogFragment.TAG);
fragment.setRetainInstance(true);
fragment.show(getChildFragmentManager(), AddGroupBottomSheetDialogFragment.TAG);
}
private AddFavouriteGroupListener createAddFavouritesGroupListener() {
return new AddFavouriteGroupListener() {
private AddGroupBottomSheetDialogFragment.AddGroupListener createAddGroupListener() {
return new AddGroupBottomSheetDialogFragment.AddGroupListener() {
@Override
public void onFavouriteGroupAdded() {
public void onGroupAdded() {
updateAdapter();
}
};
@ -304,12 +312,14 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
return new AddMarkersGroupFragmentListener() {
@Override
public void favouritesOnClick() {
openAddFavouritesGroupMenu();
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
openAddGroupMenu(fragment);
}
@Override
public void waypointsOnClick() {
AddTracksGroupBottomSheetDialogFragment fragment = new AddTracksGroupBottomSheetDialogFragment();
openAddGroupMenu(fragment);
}
};
}

View file

@ -158,7 +158,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
app.getMapMarkersHelper().removeMarker((MapMarker) item);
snackbarStringRes = R.string.item_removed;
}
adapter.notifyItemRemoved(pos);
snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
@ -231,7 +230,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
adapter.notifyItemRemoved(pos);
}
}
@ -240,7 +238,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
app.getMapMarkersHelper().removeMarker((MapMarker) item);
adapter.notifyItemRemoved(pos);
}
}
};

View file

@ -12,9 +12,9 @@ import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
public class AddMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "AddMarkersGroupBottomSheetDialogFragment";
public final static String TAG = "SelectionMarkersGroupBottomSheetDialogFragment";
private AddMarkersGroupFragmentListener listener;

View file

@ -14,43 +14,13 @@ import net.osmand.plus.R;
import java.util.List;
public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class FavouritesGroupsAdapter extends GroupsAdapter {
private static final int TYPE_HEADER = 12;
private static final int TYPE_ITEM = 13;
private FavouritesGroupsAdapterListener listener;
private OsmandApplication app;
private List<FavoriteGroup> favoriteGroups;
private IconsCache iconsCache;
public FavouritesGroupsAdapter(Context context, List<FavoriteGroup> favoriteGroups) {
this.app = (OsmandApplication) context.getApplicationContext();
super(context);
this.favoriteGroups = favoriteGroups;
this.iconsCache = app.getIconsCache();
}
public void setAdapterListener(FavouritesGroupsAdapterListener listener) {
this.listener = listener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_favourites_group_header, parent, false);
return new MapMarkersGroupHeaderViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.markers_group_view_holder, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onItemClick(view);
}
}
});
return new MapMarkersGroupViewHolder(view);
}
}
@Override
@ -69,11 +39,6 @@ public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
}
@Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
}
@Override
public int getItemCount() {
return favoriteGroups.size() + 1;
@ -82,8 +47,4 @@ public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private FavoriteGroup getItem(int position) {
return favoriteGroups.get(position - 1);
}
public interface FavouritesGroupsAdapterListener {
void onItemClick(View view);
}
}

View file

@ -0,0 +1,58 @@
package net.osmand.plus.mapmarkers.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public abstract class GroupsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 12;
private static final int TYPE_ITEM = 13;
private GroupsAdapterListener listener;
protected OsmandApplication app;
protected IconsCache iconsCache;
public GroupsAdapter(Context context) {
this.app = (OsmandApplication) context.getApplicationContext();
this.iconsCache = app.getIconsCache();
}
public void setAdapterListener(GroupsAdapterListener listener) {
this.listener = listener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_markers_group_header, parent, false);
return new MapMarkersGroupHeaderViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.markers_group_view_holder, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onItemClick(view);
}
}
});
return new MapMarkersGroupViewHolder(view);
}
}
@Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
}
public interface GroupsAdapterListener {
void onItemClick(View view);
}
}

View file

@ -15,6 +15,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
final View iconSpace;
final TextView title;
final SwitchCompat disableGroupSwitch;
final View bottomShadow;
public MapMarkerHeaderViewHolder(View itemView) {
super(itemView);
@ -22,5 +23,6 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
iconSpace = itemView.findViewById(R.id.icon_space);
title = (TextView) itemView.findViewById(R.id.title);
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
bottomShadow = itemView.findViewById(R.id.bottom_shadow);
}
}

View file

@ -42,6 +42,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
private boolean night;
public MapMarkersActiveAdapter(MapActivity mapActivity) {
setHasStableIds(true);
this.mapActivity = mapActivity;
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
night = !mapActivity.getMyApplication().getSettings().isLightContent();
@ -172,24 +173,16 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
final MapMarker marker = markers.get(position);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
notifyItemRemoved(position);
if (showDirectionEnabled && position < 2 && getItemCount() > 1) {
notifyItemChanged(1);
} else if (position == getItemCount()) {
notifyItemChanged(position - 1);
}
changeMarkers();
notifyDataSetChanged();
snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
notifyItemInserted(position);
if (showDirectionEnabled && position < 2 && getItemCount() > 2) {
notifyItemChanged(2);
} else if (position == getItemCount() - 1) {
notifyItemChanged(position - 1);
}
changeMarkers();
notifyDataSetChanged();
}
});
View snackBarView = snackbar.getView();
@ -218,6 +211,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
return markers;
}
public void changeMarkers() {
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
}
public void hideSnackbar() {
if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss();
@ -245,23 +242,15 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
}
notifyItemRemoved(pos);
if (showDirectionEnabled && pos < 2 && getItemCount() > 1) {
notifyItemChanged(1);
} else if (pos == getItemCount()) {
notifyItemChanged(pos - 1);
}
changeMarkers();
notifyDataSetChanged();
snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
notifyItemInserted(pos);
if (showDirectionEnabled && pos < 2 && getItemCount() > 2) {
notifyItemChanged(2);
} else if (pos == getItemCount() - 1) {
notifyItemChanged(pos - 1);
}
changeMarkers();
notifyDataSetChanged();
}
});
View snackBarView = snackbar.getView();
@ -270,6 +259,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
snackbar.show();
}
@Override
public long getItemId(int position) {
return getItem(position).hashCode();
}
@Override
public void onItemDismiss(RecyclerView.ViewHolder holder) {
listener.onDragOrSwipeEnded(holder);

View file

@ -84,7 +84,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
public void createDisplayGroups() {
items.clear();
items = new ArrayList<>();
app.getMapMarkersHelper().updateGroups();
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
for (int i = 0; i < groups.size(); i++) {
@ -134,19 +134,43 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else {
GroupHeader header = group.getGroupHeader();
items.add(header);
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
populateAdapterWithGroupMarkers(group, getItemCount());
}
}
}
private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) {
if (position != RecyclerView.NO_POSITION) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (!group.isDisabled()) {
List<Object> objectsToAdd = new ArrayList<>();
if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) {
items.addAll(group.getMarkers());
objectsToAdd.addAll(group.getMarkers());
} else {
items.addAll(group.getActiveMarkers());
objectsToAdd.addAll(group.getActiveMarkers());
}
if (showHideHistoryButton != null) {
items.add(showHideHistoryButton);
objectsToAdd.add(showHideHistoryButton);
}
items.addAll(position, objectsToAdd);
} else {
items.removeAll(group.getActiveMarkers());
if (showHideHistoryButton != null) {
items.remove(showHideHistoryButton);
}
}
}
}
public int getGroupHeaderPosition(String groupId) {
int pos = -1;
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByKey(groupId);
if (group != null) {
pos = items.indexOf(group.getGroupHeader());
}
return pos;
}
public void setLocation(LatLon location) {
this.location = location;
}
@ -267,8 +291,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
itemViewHolder.description.setVisibility(View.GONE);
}
final String markerGroupName = marker.groupName;
final MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByName(markerGroupName);
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -278,42 +300,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
if (markerInHistory) {
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);
if (markerGroupName != null) {
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 {
boolean firstItemInDisplayGroup = position - 1 != -1 && getItem(position - 1) instanceof Integer;
boolean lastItemInDisplayGroup = position == getItemCount() || !(getItem(position) instanceof MapMarker);
if (firstItemInDisplayGroup && lastItemInDisplayGroup) {
items.remove(position - 1);
}
}
} else if (!showHideHistoryButton.isShowHistory()) {
items.remove(marker);
}
}
}
createDisplayGroups();
updateShowDirectionMarkers();
notifyDataSetChanged();
if (!markerInHistory) {
@ -386,19 +376,19 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
boolean groupIsDisabled = group.isDisabled();
headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
group.setDisabled(!enabled);
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
createDisplayGroups();
updateShowDirectionMarkers();
notifyDataSetChanged();
if (!enabled) {
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
group.setDisabled(false);
app.getMapMarkersHelper().updateGroupDisabled(group, false);
headerViewHolder.disableGroupSwitch.setChecked(true);
}
});
@ -408,11 +398,15 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
snackbar.show();
}
}
});
};
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null);
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(checkedChangeListener);
} else {
throw new IllegalArgumentException("Unsupported header");
}
headerViewHolder.title.setText(headerString);
headerViewHolder.bottomShadow.setVisibility(position == getItemCount() - 1 ? View.VISIBLE : View.GONE);
} else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
@ -426,15 +420,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
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);
}
showHideHistoryButton.setShowHistory(!showHistory);
createDisplayGroups();
notifyDataSetChanged();
}
});
@ -481,24 +468,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
return monthStr;
}
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;
}
public interface MapMarkersGroupsAdapterListener {
void onItemClick(View view);

View file

@ -43,10 +43,8 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
}
public void createHeaders() {
items.clear();
items = new ArrayList<>();
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
int previousHeader = -1;
int monthsDisplayed = 0;
@ -151,14 +149,12 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
return;
}
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
notifyItemRemoved(position);
snackbar = Snackbar.make(itemViewHolder.itemView, app.getString(R.string.marker_moved_to_active), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
notifyDataSetChanged();
}
});
View snackBarView = snackbar.getView();

View file

@ -0,0 +1,43 @@
package net.osmand.plus.mapmarkers.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.R;
import java.util.List;
public class TracksGroupsAdapter extends GroupsAdapter {
private List<GpxDataItem> gpxFiles;
public TracksGroupsAdapter(Context context, List<GpxDataItem> gpxFiles) {
super(context);
this.gpxFiles = gpxFiles;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof MapMarkersGroupHeaderViewHolder) {
MapMarkersGroupHeaderViewHolder markersGroupHeaderViewHolder = (MapMarkersGroupHeaderViewHolder) holder;
markersGroupHeaderViewHolder.title.setText(app.getText(R.string.shared_string_tracks));
markersGroupHeaderViewHolder.description.setText(app.getText(R.string.add_track_to_markers_descr));
} else if (holder instanceof MapMarkersGroupViewHolder) {
GpxDataItem gpx = getItem(position);
MapMarkersGroupViewHolder markersGroupViewHolder = (MapMarkersGroupViewHolder) holder;
markersGroupViewHolder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_polygom_dark));
markersGroupViewHolder.name.setText(gpx.getFile().getName().replace(".gpx", "").replace("/", " ").replace("_", " "));
markersGroupViewHolder.numberCount.setText(String.valueOf(gpx.getAnalysis().wptPoints));
}
}
@Override
public int getItemCount() {
return gpxFiles.size() + 1;
}
private GpxDataItem getItem(int position) {
return gpxFiles.get(position - 1);
}
}

View file

@ -580,7 +580,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
app.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
}
}
@ -632,10 +632,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
private void addMapMarkersSyncGroup() {
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
File gpx = getGpxDataItem().getFile();
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
GPXFile gpxFile = getTrackActivity().getGpx();
if (gpxFile != null) {
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
@ -647,7 +647,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
.setAction(getResources().getString(R.string.view), new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
Bundle args = new Bundle();
args.putString(MarkersSyncGroup.MARKERS_SYNC_GROUP_ID, syncGroup.getId());
MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS, args);
}
});
snackbar.addCallback(new Snackbar.Callback() {

View file

@ -643,7 +643,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
view.getApplication().getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
view.getApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
}
}

View file

@ -313,12 +313,13 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : (myLoc == null
? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude())), tileBox.getZoom());
OsmandSettings settings = map.getMyApplication().getSettings();
int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
return;
}
int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
for (MapMarker marker : markersHelper.getMapMarkers()) {