Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-22 03:09:49 +01:00
commit bffd8d3e7a
29 changed files with 1666 additions and 2609 deletions

View file

@ -30,9 +30,14 @@
app:contentInsetLeft="54dp" app:contentInsetLeft="54dp"
app:contentInsetStart="54dp"> app:contentInsetStart="54dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"
@ -40,6 +45,19 @@
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:textSize="@dimen/dialog_header_text_size" android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"/> osmand:typeface="@string/font_roboto_medium"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:indeterminate="true"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>

View file

@ -9,6 +9,8 @@
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="select_waypoints_category_description">You can add all of the track\'s waypoints, or select separate categories.</string>
<string name="shared_string_total">Total</string>
<string name="clear_all_intermediates">Clear all intermediate points</string> <string name="clear_all_intermediates">Clear all intermediate points</string>
<string name="group_deleted">Group deleted</string> <string name="group_deleted">Group deleted</string>
<string name="rendering_attr_whiteWaterSports_name">Whitewater sports</string> <string name="rendering_attr_whiteWaterSports_name">Whitewater sports</string>

View file

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

View file

@ -10,7 +10,6 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
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.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -110,6 +109,20 @@ public class FavouritesDbHelper {
return changed; return changed;
} }
private void runSyncWithMarkers(FavoriteGroup favGroup) {
MapMarkersHelper helper = context.getMapMarkersHelper();
helper.runSynchronization(helper.getOrCreateGroup(favGroup));
}
private void removeFromMarkers(FavoriteGroup favGroup) {
MapMarkersHelper helper = context.getMapMarkersHelper();
helper.removeMarkersGroup(helper.getOrCreateGroup(favGroup));
}
private void addToMarkers(FavoriteGroup favGroup) {
MapMarkersHelper helper = context.getMapMarkersHelper();
helper.syncWithMarkers(helper.getOrCreateGroup(favGroup));
}
private File getInternalFile() { private File getInternalFile() {
return context.getFileStreamPath(FILE_TO_BACKUP); return context.getFileStreamPath(FILE_TO_BACKUP);
@ -127,7 +140,7 @@ public class FavouritesDbHelper {
cachedFavoritePoints.remove(p); cachedFavoritePoints.remove(p);
} }
for (FavoriteGroup gr : groupsToSync) { for (FavoriteGroup gr : groupsToSync) {
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE)); runSyncWithMarkers(gr);
} }
} }
if (groupsToDelete != null) { if (groupsToDelete != null) {
@ -135,7 +148,7 @@ public class FavouritesDbHelper {
flatGroups.remove(g.name); flatGroups.remove(g.name);
favoriteGroups.remove(g); favoriteGroups.remove(g);
cachedFavoritePoints.removeAll(g.points); cachedFavoritePoints.removeAll(g.points);
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name); removeFromMarkers(g);
} }
} }
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
@ -150,7 +163,7 @@ public class FavouritesDbHelper {
FavoriteGroup group = flatGroups.get(p.getCategory()); FavoriteGroup group = flatGroups.get(p.getCategory());
if (group != null) { if (group != null) {
group.points.remove(p); group.points.remove(p);
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE)); runSyncWithMarkers(group);
} }
cachedFavoritePoints.remove(p); cachedFavoritePoints.remove(p);
} }
@ -180,7 +193,7 @@ public class FavouritesDbHelper {
sortAll(); sortAll();
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
} }
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color)); runSyncWithMarkers(group);
return true; return true;
} }
@ -275,7 +288,7 @@ public class FavouritesDbHelper {
} }
sortAll(); sortAll();
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor())); runSyncWithMarkers(getOrCreateGroup(p, 0));
return true; return true;
} }
@ -283,7 +296,7 @@ public class FavouritesDbHelper {
p.setLatitude(lat); p.setLatitude(lat);
p.setLongitude(lon); p.setLongitude(lon);
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor())); runSyncWithMarkers(getOrCreateGroup(p, 0));
return true; return true;
} }
@ -352,7 +365,7 @@ public class FavouritesDbHelper {
if (remove) { if (remove) {
flatGroups.remove(group.name); flatGroups.remove(group.name);
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name); removeFromMarkers(group);
return true; return true;
} }
return false; return false;
@ -603,14 +616,13 @@ public class FavouritesDbHelper {
} }
public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
MapMarkersHelper markersHelper = context.getMapMarkersHelper();
if (color != 0 && group.color != color) { if (color != 0 && group.color != color) {
FavoriteGroup gr = flatGroups.get(group.name); FavoriteGroup gr = flatGroups.get(group.name);
group.color = color; group.color = color;
for (FavouritePoint p : gr.points) { for (FavouritePoint p : gr.points) {
p.setColor(color); p.setColor(color);
} }
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color)); runSyncWithMarkers(gr);
} }
if (group.visible != visible) { if (group.visible != visible) {
FavoriteGroup gr = flatGroups.get(group.name); FavoriteGroup gr = flatGroups.get(group.name);
@ -618,11 +630,11 @@ public class FavouritesDbHelper {
for (FavouritePoint p : gr.points) { for (FavouritePoint p : gr.points) {
p.setVisible(visible); p.setVisible(visible);
} }
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color)); runSyncWithMarkers(gr);
} }
if (!group.name.equals(newName)) { if (!group.name.equals(newName)) {
FavoriteGroup gr = flatGroups.remove(group.name); FavoriteGroup gr = flatGroups.remove(group.name);
markersHelper.removeMarkersSyncGroup(group.name); removeFromMarkers(gr);
gr.name = newName; gr.name = newName;
FavoriteGroup renamedGroup = flatGroups.get(gr.name); FavoriteGroup renamedGroup = flatGroups.get(gr.name);
boolean existing = renamedGroup != null; boolean existing = renamedGroup != null;
@ -638,9 +650,7 @@ public class FavouritesDbHelper {
renamedGroup.points.add(p); renamedGroup.points.add(p);
} }
} }
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color); addToMarkers(renamedGroup);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
} }
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
} }

View file

@ -6,7 +6,6 @@ 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 net.osmand.AndroidUtils;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
@ -16,8 +15,6 @@ import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.Track; import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
@ -502,7 +499,7 @@ public class GpxSelectionHelper {
} }
} }
if (syncGroup) { if (syncGroup) {
syncGpx(gpx, true, null); syncGpx(gpx);
} }
return sf; return sf;
} }
@ -539,25 +536,10 @@ public class GpxSelectionHelper {
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
syncGpx(gpxFile, false, null);
}
public void syncGpx(GPXFile gpxFile, boolean createOrDeleteGroup, @Nullable OnGroupSyncedListener callback) {
File gpx = new File(gpxFile.path); File gpx = new File(gpxFile.path);
if (gpx.exists()) { if (gpx.exists()) {
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); mapMarkersHelper.runSynchronization(mapMarkersHelper.getOrCreateGroup(gpx));
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());
}
}
mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -156,49 +156,30 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
if (group.points.size() > 0) { if (group.points.size() > 0) {
items.add(new DividerHalfItem(getContext())); items.add(new DividerHalfItem(getContext()));
}
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final MarkersSyncGroup syncGroup = final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color); final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) { BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
BaseBottomSheetItem addToMarkersItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark))
.setIcon(getContentIcon(R.drawable.ic_action_flag_dark)) .setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers))
.setTitle(getString(R.string.shared_string_add_to_map_markers))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}
})
.create();
items.add(addToMarkersItem);
}
if (app.getSettings().USE_MAP_MARKERS.get() && groupSyncedWithMarkers) {
BaseBottomSheetItem removeFromMarkersItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_delete_dark))
.setTitle(getString(R.string.remove_from_map_markers))
.setLayoutId(R.layout.bottom_sheet_item_simple) .setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
markersHelper.removeMarkersSyncGroup(syncGroup.getId()); if (synced) {
markersHelper.removeMarkersGroup(markersGr);
} else {
markersHelper.syncWithMarkers(markersGr);
}
dismiss(); dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
}) })
.create(); .create();
items.add(removeFromMarkersItem); items.add(markersGroupItem);
}
if (group.points.size() > 0) {
BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder() BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)) .setIcon(getContentIcon(R.drawable.ic_action_gshare_dark))
.setTitle(getString(R.string.shared_string_share)) .setTitle(getString(R.string.shared_string_share))
@ -208,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
public void onClick(View view) { public void onClick(View view) {
FavoritesTreeFragment fragment = getFavoritesTreeFragment(); FavoritesTreeFragment fragment = getFavoritesTreeFragment();
if (fragment != null) { if (fragment != null) {
fragment.shareFavorites(group); fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
} }
dismiss(); dismiss();
} }

View file

@ -36,12 +36,11 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -58,7 +57,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
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;
@ -347,13 +345,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (getSettings().USE_MAP_MARKERS.get()) {
createMenuItem(menu, SELECT_MAP_MARKERS_ID, R.string.select_map_markers, R.drawable.ic_action_flag_dark, createMenuItem(menu, SELECT_MAP_MARKERS_ID, R.string.select_map_markers, R.drawable.ic_action_flag_dark,
R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} else {
createMenuItem(menu, SELECT_MAP_MARKERS_ID, R.string.select_destination_and_intermediate_points, R.drawable.ic_action_intermediate,
R.drawable.ic_action_intermediate, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark,
R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
// createMenuItem(menu, EXPORT_ID, R.string.shared_string_export, R.drawable.ic_action_gsave_light, // createMenuItem(menu, EXPORT_ID, R.string.shared_string_export, R.drawable.ic_action_gsave_light,
@ -383,15 +376,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
enableSelectionMode(true); enableSelectionMode(true);
if (getSettings().USE_MAP_MARKERS.get()) {
createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.select_map_markers, createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.select_map_markers,
R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark,
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
} else {
createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points,
R.drawable.ic_action_intermediate, R.drawable.ic_action_intermediate,
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
}
favoritesSelected.clear(); favoritesSelected.clear();
groupsToDelete.clear(); groupsToDelete.clear();
favouritesAdapter.notifyDataSetInvalidated(); favouritesAdapter.notifyDataSetInvalidated();
@ -424,40 +411,25 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
private void selectMapMarkersImpl() { private void selectMapMarkersImpl() {
if (getSelectedFavoritesCount() > 0) { if (getSelectedFavoritesCount() > 0) {
if (getSettings().USE_MAP_MARKERS.get()) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = new LinkedList<>(); List<LatLon> points = new ArrayList<>();
List<PointDescription> names = new LinkedList<>(); List<PointDescription> names = new ArrayList<>();
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) { for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
FavoriteGroup favGr = helper.getGroup(entry.getKey()); FavoriteGroup favGr = helper.getGroup(entry.getKey());
MarkersSyncGroup syncGr = MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(favGr);
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
if (entry.getValue().size() == favGr.points.size()) { if (entry.getValue().size() == favGr.points.size()) {
markersHelper.addMarkersSyncGroup(syncGr); markersHelper.syncWithMarkers(markersGr);
markersHelper.syncGroupAsync(syncGr);
} else { } else {
for (FavouritePoint fp : entry.getValue()) { for (FavouritePoint fp : entry.getValue()) {
points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
} }
markersHelper.addMapMarkers(points, names, syncGr); markersHelper.addMapMarkers(points, names, markersGr);
points.clear(); points.clear();
names.clear(); names.clear();
} }
} }
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} else {
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
for (FavouritePoint fp : getSelectedFavorites()) {
targetPointsHelper.navigateToPoint(new LatLon(fp.getLatitude(), fp.getLongitude()), false,
targetPointsHelper.getIntermediatePoints().size() + 1,
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, fp.getName()));
}
if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
targetPointsHelper.updateRouteAndRefresh(true);
}
IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), true);
}
} }
} }

View file

@ -719,7 +719,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) { if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS); Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
if (openMapMarkersGroupsExtra != null) { if (openMapMarkersGroupsExtra != null) {
MapMarkersDialogFragment.showInstance(this, openMapMarkersGroupsExtra.getString(MapMarkersHelper.MarkersSyncGroup.MARKERS_SYNC_GROUP_ID)); MapMarkersDialogFragment.showInstance(this, openMapMarkersGroupsExtra.getString(MapMarkersHelper.MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
} }
setIntent(null); setIntent(null);
} }

View file

@ -26,6 +26,10 @@ public class BaseBottomSheetItem {
return view; return view;
} }
public Object getTag() {
return tag;
}
public BaseBottomSheetItem(View view, public BaseBottomSheetItem(View view,
@LayoutRes int layoutId, @LayoutRes int layoutId,
Object tag, Object tag,

View file

@ -8,6 +8,7 @@ import android.support.v4.widget.CompoundButtonCompat;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -16,9 +17,14 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
private boolean checked; private boolean checked;
private ColorStateList buttonTintList; private ColorStateList buttonTintList;
private OnCheckedChangeListener onCheckedChangeListener;
private CompoundButton compoundButton; private CompoundButton compoundButton;
public boolean isChecked() {
return checked;
}
public BottomSheetItemWithCompoundButton(View customView, public BottomSheetItemWithCompoundButton(View customView,
@LayoutRes int layoutId, @LayoutRes int layoutId,
Object tag, Object tag,
@ -31,7 +37,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
CharSequence description, CharSequence description,
@ColorRes int descriptionColorId, @ColorRes int descriptionColorId,
boolean checked, boolean checked,
ColorStateList buttonTintList) { ColorStateList buttonTintList,
OnCheckedChangeListener onCheckedChangeListener) {
super(customView, super(customView,
layoutId, layoutId,
tag, tag,
@ -45,6 +52,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
descriptionColorId); descriptionColorId);
this.checked = checked; this.checked = checked;
this.buttonTintList = buttonTintList; this.buttonTintList = buttonTintList;
this.onCheckedChangeListener = onCheckedChangeListener;
} }
public void setChecked(boolean checked) { public void setChecked(boolean checked) {
@ -58,12 +66,14 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
compoundButton = (CompoundButton) view.findViewById(R.id.compound_button); compoundButton = (CompoundButton) view.findViewById(R.id.compound_button);
compoundButton.setChecked(checked); compoundButton.setChecked(checked);
CompoundButtonCompat.setButtonTintList(compoundButton, buttonTintList); CompoundButtonCompat.setButtonTintList(compoundButton, buttonTintList);
compoundButton.setOnCheckedChangeListener(onCheckedChangeListener);
} }
public static class Builder extends BottomSheetItemWithDescription.Builder { public static class Builder extends BottomSheetItemWithDescription.Builder {
protected boolean checked; protected boolean checked;
protected ColorStateList buttonTintList; protected ColorStateList buttonTintList;
protected OnCheckedChangeListener onCheckedChangeListener;
public Builder setChecked(boolean checked) { public Builder setChecked(boolean checked) {
this.checked = checked; this.checked = checked;
@ -75,6 +85,11 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
return this; return this;
} }
public Builder setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
this.onCheckedChangeListener = onCheckedChangeListener;
return this;
}
public BottomSheetItemWithCompoundButton create() { public BottomSheetItemWithCompoundButton create() {
return new BottomSheetItemWithCompoundButton(customView, return new BottomSheetItemWithCompoundButton(customView,
layoutId, layoutId,
@ -88,7 +103,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
description, description,
descriptionColorId, descriptionColorId,
checked, checked,
buttonTintList); buttonTintList,
onCheckedChangeListener);
} }
} }
} }

View file

@ -1,473 +1,35 @@
package net.osmand.plus.helpers; package net.osmand.plus.helpers;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.text.format.DateFormat;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.DirectionDrawable;
import net.osmand.plus.views.controls.DynamicListView;
import net.osmand.plus.views.controls.ListDividerShape;
import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.util.MapUtils;
import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Locale; import java.util.Locale;
public class MapMarkerDialogHelper { public class MapMarkerDialogHelper {
public static final int ACTIVE_MARKERS = 0;
public static final int MY_LOCATION = 10;
public static final int MARKERS_HISTORY = 100;
private MapActivity mapActivity; public static void updateMapMarkerInfo(final Context ctx,
private OsmandApplication app; View localView,
private MapMarkersHelper markersHelper; LatLon loc,
private MapMarkersDialogHelperCallbacks helperCallbacks; Float heading,
private boolean sorted; boolean useCenter,
private boolean nightMode; boolean nightMode,
private boolean selectionMode; int screenOrientation,
final MapMarker marker) {
private boolean useCenter;
private LatLon myLoc;
private LatLon loc;
private Float heading;
private int screenOrientation;
private boolean reloading;
private long lastUpdateTime;
private boolean allSelected;
public interface MapMarkersDialogHelperCallbacks {
void reloadAdapter();
void deleteMapMarker(int position);
void showMarkersRouteOnMap();
}
public MapMarkerDialogHelper(MapActivity mapActivity) {
this.mapActivity = mapActivity;
app = mapActivity.getMyApplication();
markersHelper = app.getMapMarkersHelper();
}
public void setHelperCallbacks(MapMarkersDialogHelperCallbacks helperCallbacks) {
this.helperCallbacks = helperCallbacks;
}
public boolean isInSelectionMode() {
return selectionMode;
}
public boolean hasActiveMarkers() {
return markersHelper.getMapMarkers().size() > 0;
}
public void setSelectionMode(boolean selectionMode) {
this.selectionMode = selectionMode;
}
public boolean isNightMode() {
return nightMode;
}
public void setNightMode(boolean nightMode) {
this.nightMode = nightMode;
}
public boolean isSorted() {
return sorted;
}
public void setSorted(boolean sorted) {
this.sorted = sorted;
}
public AdapterView.OnItemClickListener getItemClickListener(final ArrayAdapter<Object> listAdapter) {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
Object obj = listAdapter.getItem(item);
if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
if (selectionMode) {
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
checkBox.setChecked(!checkBox.isChecked());
marker.selected = checkBox.isChecked();
markersHelper.updateMapMarker(marker, false);
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
}
} else {
if (!marker.history) {
showMarkerOnMap(mapActivity, marker);
} else {
showHistoryOnMap(marker);
}
}
} else if (obj instanceof Integer && (Integer) obj == MY_LOCATION && selectionMode) {
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
checkBox.setChecked(!checkBox.isChecked());
markersHelper.setStartFromMyLocation(checkBox.isChecked());
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
}
}
}
};
}
public StableArrayAdapter getMapMarkersListAdapter() {
screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
calculateLocationParams();
final List<Object> objects = getListObjects();
List<Object> activeObjects = getActiveObjects(objects);
allSelected = true;
List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getMapMarkers());
for (MapMarker m : activeMarkers) {
if (!m.selected) {
allSelected = false;
break;
}
}
return new StableArrayAdapter(mapActivity,
R.layout.map_marker_item, R.id.title, objects, activeObjects) {
@Override
public void buildDividers() {
dividers = getCustomDividers(getObjects());
}
@Override
public boolean isEnabled(int position) {
Object obj = getItem(position);
return obj instanceof MapMarker
|| (obj instanceof Integer && (Integer) obj == MY_LOCATION);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
Object obj = getItem(position);
boolean labelView = (obj instanceof Integer);
boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
if (labelView) {
if ((Integer) obj == MY_LOCATION) {
v = updateMyLocationView(v);
} else {
v = createItemForCategory(this, (Integer) obj);
}
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
} else if (topDividerView) {
v = mapActivity.getLayoutInflater().inflate(R.layout.card_top_divider, null);
AndroidUtils.setListBackground(mapActivity, v, nightMode);
} else if (bottomDividerView) {
v = mapActivity.getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
AndroidUtils.setListBackground(mapActivity, v, nightMode);
} else if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
v = updateMapMarkerItemView(this, v, marker);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
}
return v;
}
};
}
private List<Drawable> getCustomDividers(List<Object> points) {
int color;
if (nightMode) {
color = mapActivity.getResources().getColor(R.color.dashboard_divider_dark);
} else {
color = mapActivity.getResources().getColor(R.color.dashboard_divider_light);
}
Shape fullDividerShape = new ListDividerShape(color, 0);
Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(mapActivity, 56f));
final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
int divHeight = AndroidUtils.dpToPx(mapActivity, 1f);
fullDivider.setIntrinsicHeight(divHeight);
halfDivider.setIntrinsicHeight(divHeight);
List<Drawable> res = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
Object obj = points.get(i);
Object objNext = i + 1 < points.size() ? points.get(i + 1) : null;
if (objNext == null) {
break;
}
boolean bottomDividerViewNext = (objNext instanceof Boolean) && !((Boolean) objNext);
boolean mapMarker = (obj instanceof MapMarker);
boolean mapMarkerNext = (objNext instanceof MapMarker);
Drawable d = null;
if (mapMarkerNext) {
if (mapMarker) {
d = halfDivider;
} else {
d = fullDivider;
}
} else if (mapMarker && !bottomDividerViewNext) {
d = fullDivider;
}
res.add(d);
}
return res;
}
protected View createItemForCategory(final ArrayAdapter<Object> listAdapter, final int type) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_header, null);
v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
v.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
if (type == MARKERS_HISTORY) {
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? mapActivity.getResources().getColor(R.color.map_widget_blue)
: mapActivity.getResources().getColor(R.color.osmand_orange));
btn.setText(mapActivity.getString(R.string.shared_string_clear));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setMessage(mapActivity.getString(R.string.clear_markers_history_q))
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated();
markersHelper.removeMarkersHistory();
if (markersHelper.getMapMarkers().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
})
.setNegativeButton(R.string.shared_string_no, null)
.show();
}
});
} else if (type == ACTIVE_MARKERS) {
if (selectionMode) {
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? mapActivity.getResources().getColor(R.color.map_widget_blue)
: mapActivity.getResources().getColor(R.color.osmand_orange));
if (allSelected) {
btn.setText(mapActivity.getString(R.string.shared_string_deselect_all));
} else {
btn.setText(mapActivity.getString(R.string.shared_string_select_all));
}
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<MapMarker> markers = markersHelper.getMapMarkers();
for (MapMarker marker : markers) {
marker.selected = !allSelected;
}
markersHelper.setStartFromMyLocation(!allSelected);
allSelected = !allSelected;
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
});
} else {
final ImageButton btn = (ImageButton) v.findViewById(R.id.image_button);
btn.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_overflow_menu_white, !nightMode));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IconsCache iconsCache = app.getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(mapActivity, v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
item = optionsMenu.getMenu().add(R.string.shared_string_clear)
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setMessage(mapActivity.getString(R.string.clear_active_markers_q))
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated();
markersHelper.moveAllActiveMarkersToHistory();
if (markersHelper.getMapMarkersHistory().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
})
.setNegativeButton(R.string.shared_string_no, null)
.show();
return true;
}
});
if (!sorted && markersHelper.getMapMarkers().size() > 1) {
item = optionsMenu.getMenu().add(R.string.shared_string_reverse_order).setIcon(
iconsCache.getThemedIcon(R.drawable.ic_action_undo_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
markersHelper.reverseActiveMarkersOrder();
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_save_as_gpx).setIcon(
iconsCache.getThemedIcon(R.drawable.ic_action_save));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
generateGPX(markersHelper.getMapMarkers());
return true;
}
});
optionsMenu.show();
}
});
}
}
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getHeader(type));
return v;
}
protected View updateMapMarkerItemView(final StableArrayAdapter adapter, View v, final MapMarker marker) {
if (v == null || v.findViewById(R.id.info_close) == null) {
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
}
updateMapMarkerInfo(mapActivity, v, loc, heading, useCenter, nightMode, screenOrientation,
selectionMode, helperCallbacks, marker, false);
final View more = v.findViewById(R.id.all_points);
final View move = v.findViewById(R.id.info_move);
final View remove = v.findViewById(R.id.info_close);
remove.setVisibility(View.GONE);
more.setVisibility(View.GONE);
if (!marker.history && !sorted) {
move.setVisibility(View.VISIBLE);
((ImageView) move).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_reorder, !nightMode));
if (app.accessibilityEnabled()) {
move.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((DynamicListView.DragIcon)view.getTag()).onClick();
}
});
}
move.setTag(new DynamicListView.DragIcon() {
@Override
public void onClick() {
final PopupMenu optionsMenu = new PopupMenu(mapActivity, move);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
item = optionsMenu.getMenu().add(
R.string.shared_string_remove).setIcon(app.getIconsCache().
getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (helperCallbacks != null) {
int pos = adapter.getPosition(marker);
if (pos != -1) {
helperCallbacks.deleteMapMarker(pos);
}
}
return true;
}
});
optionsMenu.show();
}
});
} else {
move.setVisibility(View.GONE);
move.setTag(null);
}
return v;
}
public static void updateMapMarkerInfo(final Context ctx, View localView, LatLon loc,
Float heading, boolean useCenter, boolean nightMode,
int screenOrientation, boolean selectionMode,
final MapMarkersDialogHelperCallbacks helperCallbacks,
final MapMarker marker, boolean showDateAndGroup) {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text); TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow); TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
@ -539,7 +101,6 @@ public class MapMarkerDialogHelper {
descText.setVisibility(View.GONE); descText.setVisibility(View.GONE);
if (showDateAndGroup) {
Date date = new Date(marker.creationDate); Date date = new Date(marker.creationDate);
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date); String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
if (month.length() > 1) { if (month.length() > 1) {
@ -557,342 +118,12 @@ public class MapMarkerDialogHelper {
} }
dateGroupText.setVisibility(View.VISIBLE); dateGroupText.setVisibility(View.VISIBLE);
dateGroupText.setText(desc); dateGroupText.setText(desc);
}
if (selectionMode) {
checkBox.setChecked(marker.selected);
checkBox.setVisibility(View.VISIBLE);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
marker.selected = checkBox.isChecked();
app.getMapMarkersHelper().updateMapMarker(marker, false);
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
} else if (ctx instanceof MapActivity) {
((MapActivity) ctx).refreshMap();
}
}
});
} else {
checkBox.setVisibility(View.GONE); checkBox.setVisibility(View.GONE);
checkBox.setOnClickListener(null); checkBox.setOnClickListener(null);
} }
/*
String pointDescription = "";
if (descText != null) {
AndroidUtils.setTextSecondaryColor(this, descText, nightMode);
pointDescription = marker.getPointDescription(this).getTypeName();
}
if (descr.equals(pointDescription)) {
pointDescription = "";
}
if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
pointDescription = "" + pointDescription;
}
if (descText != null) {
descText.setText(pointDescription);
}
*/
}
protected void updateMapMarkerArrowDistanceView(View localView, final MapMarker marker) {
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
if (textDist == null || arrow == null) {
return;
}
float[] mes = new float[2];
if (loc != null && marker.point != null) {
Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
}
boolean newImage = false;
int arrowResId = R.drawable.ic_direction_arrow;
DirectionDrawable dd;
if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
newImage = true;
dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight());
} else {
dd = (DirectionDrawable) arrow.getDrawable();
}
if (!marker.history) {
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
} else {
dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light);
}
if (loc == null || heading == null || marker.point == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - heading + 180 + screenOrientation);
}
if (newImage) {
arrow.setImageDrawable(dd);
}
arrow.invalidate();
int dist = (int) mes[0];
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
}
protected View updateMyLocationView(View v) {
if (v == null || v.findViewById(R.id.info_close) == null) {
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
}
updateMyLocationInfo(mapActivity, v, nightMode, selectionMode, helperCallbacks);
final View more = v.findViewById(R.id.all_points);
final View move = v.findViewById(R.id.info_move);
final View remove = v.findViewById(R.id.info_close);
remove.setVisibility(View.GONE);
more.setVisibility(View.GONE);
move.setVisibility(View.GONE);
move.setTag(null);
return v;
}
public static void updateMyLocationInfo(final Context ctx, View localView, boolean nightMode,
boolean selectionMode,
final MapMarkersDialogHelperCallbacks helperCallbacks) {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
ImageView waypointIcon = (ImageView) localView.findViewById(R.id.waypoint_icon);
TextView waypointDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
final CheckBox checkBox = (CheckBox) localView.findViewById(R.id.checkbox);
if (text == null || textDist == null || arrow == null || waypointIcon == null
|| waypointDeviation == null || descText == null) {
return;
}
arrow.setVisibility(View.GONE);
textDist.setVisibility(View.GONE);
waypointDeviation.setVisibility(View.GONE);
final OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
ApplicationMode appMode = app.getSettings().getApplicationMode();
waypointIcon.setImageDrawable(ctx.getResources().getDrawable(appMode.getResourceLocationDay()));
text.setText(ctx.getString(R.string.shared_string_my_location));
descText.setText(ctx.getResources().getString(R.string.starting_point));
descText.setVisibility(View.VISIBLE);
AndroidUtils.setTextPrimaryColor(ctx, text, nightMode);
AndroidUtils.setTextSecondaryColor(ctx, descText, nightMode);
if (selectionMode) {
checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
checkBox.setVisibility(View.VISIBLE);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
app.getMapMarkersHelper().setStartFromMyLocation(checkBox.isChecked());
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
} else if (ctx instanceof MapActivity) {
((MapActivity) ctx).refreshMap();
}
}
});
} else {
checkBox.setVisibility(View.GONE);
checkBox.setOnClickListener(null);
}
}
public static void showMarkerOnMap(MapActivity mapActivity, MapMarker marker) {
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker);
MapActivity.launchMapActivityMoveToTop(mapActivity);
}
public void showHistoryOnMap(MapMarker marker) {
app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION,
marker.getPointDescription(mapActivity).getName()),
false, null);
MapActivity.launchMapActivityMoveToTop(mapActivity);
}
protected String getHeader(int type) {
String str = mapActivity.getString(R.string.map_markers);
switch (type) {
case ACTIVE_MARKERS:
str = mapActivity.getString(R.string.active_markers);
break;
case MARKERS_HISTORY:
str = mapActivity.getString(R.string.shared_string_history);
break;
}
return str;
}
public void reloadListAdapter(ArrayAdapter<Object> listAdapter) {
reloading = true;
listAdapter.setNotifyOnChange(false);
listAdapter.clear();
List<Object> objects = getListObjects();
for (Object point : objects) {
listAdapter.add(point);
}
if (listAdapter instanceof StableArrayAdapter) {
((StableArrayAdapter) listAdapter).updateObjects(objects, getActiveObjects(objects));
}
listAdapter.notifyDataSetChanged();
reloading = false;
}
public void calcDistance(LatLon anchor, List<MapMarker> markers) {
for (MapMarker m : markers) {
m.dist = (int) (MapUtils.getDistance(m.getLatitude(), m.getLongitude(),
anchor.getLatitude(), anchor.getLongitude()));
}
}
protected List<Object> getListObjects() {
final List<Object> objects = new ArrayList<>();
LatLon mapLocation =
new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getMapMarkers());
calcDistance(mapLocation, activeMarkers);
if (sorted) {
Collections.sort(activeMarkers, new Comparator<MapMarker>() {
@Override
public int compare(MapMarker lhs, MapMarker rhs) {
return lhs.dist < rhs.dist ? -1 : (lhs.dist == rhs.dist ? 0 : 1);
}
});
}
if (activeMarkers.size() > 0) {
objects.add(ACTIVE_MARKERS);
if (selectionMode) {
objects.add(MY_LOCATION);
}
objects.addAll(activeMarkers);
objects.add(false);
}
if (!selectionMode) {
List<MapMarker> markersHistory = new ArrayList<>(markersHelper.getMapMarkersHistory());
calcDistance(mapLocation, markersHistory);
if (markersHistory.size() > 0) {
if (activeMarkers.size() > 0) {
objects.add(true);
}
objects.add(MARKERS_HISTORY);
objects.addAll(markersHistory);
objects.add(false);
}
}
return objects;
}
private List<Object> getActiveObjects(List<Object> objects) {
List<Object> activeObjects = new ArrayList<>();
for (Object obj : objects) {
if (obj instanceof MapMarker) {
activeObjects.add(obj);
}
}
return activeObjects;
}
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(colorIndex)); return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(colorIndex));
} }
public void updateLocation(ListView listView, boolean compassChanged) {
if ((compassChanged && !mapActivity.getDashboard().isMapLinkedToLocation())
|| reloading || System.currentTimeMillis() - lastUpdateTime < 100) {
return;
}
lastUpdateTime = System.currentTimeMillis();
try {
LatLon prevMyLoc = myLoc;
calculateLocationParams();
for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) {
Object obj = listView.getItemAtPosition(i);
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
if (obj instanceof MapMarker && v != null) {
updateMapMarkerArrowDistanceView(v, (MapMarker) obj);
}
}
if (selectionMode && markersHelper.isStartFromMyLocation() && prevMyLoc == null && myLoc != null) {
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
} else {
mapActivity.refreshMap();
}
}
} catch (Exception e) {
}
}
public void updateMarkerView(ListView listView, MapMarker marker) {
try {
for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) {
Object obj = listView.getItemAtPosition(i);
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
if (obj == marker) {
updateMapMarkerInfo(mapActivity, v, loc, heading, useCenter, nightMode,
screenOrientation, selectionMode, helperCallbacks, marker, false);
}
}
} catch (Exception e) {
}
}
private void calculateLocationParams() {
DashboardOnMap d = mapActivity.getDashboard();
if (d == null) {
return;
}
float head = d.getHeading();
float mapRotation = d.getMapRotation();
LatLon mw = d.getMapViewLocation();
Location l = d.getMyLocation();
boolean mapLinked = d.isMapLinkedToLocation() && l != null;
myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
useCenter = !mapLinked;
loc = (useCenter ? mw : myLoc);
heading = useCenter ? -mapRotation : head;
}
private void generateGPX(List<MapMarker> markers) {
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
if (!dir.exists()) {
dir.mkdirs();
}
Date date = new Date();
String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date);
File fout = new File(dir, fileName + ".gpx");
int ind = 1;
while (fout.exists()) {
fout = new File(dir, fileName + "_" + (++ind) + ".gpx");
}
GPXFile file = new GPXFile();
for (MapMarker marker : markersHelper.getMapMarkers()) {
WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude();
wpt.setColor(mapActivity.getResources().getColor(MapMarker.getColorId(marker.colorIndex)));
wpt.name = marker.getOnlyName();
//wpt.link = r.getFileName();
//wpt.time = r.getFile().lastModified();
//wpt.category = r.getSearchHistoryType();
file.addPoint(wpt);
}
GPXUtilities.writeGpxFile(fout, file, app);
}
} }

View file

@ -836,8 +836,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (marker != null) { if (marker != null) {
RenameMarkerBottomSheetDialogFragment RenameMarkerBottomSheetDialogFragment
.showInstance(mapActivity.getSupportFragmentManager(), marker); .showInstance(mapActivity.getSupportFragmentManager(), marker);
} else if (settings.USE_MAP_MARKERS.get()) { } else if (pointDescription.isMapMarker()) {
if (pointDescription.isMapMarker()) {
hide(); hide();
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
MapMarkersDialogFragment.showInstance(mapActivity); MapMarkersDialogFragment.showInstance(mapActivity);
@ -850,10 +849,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForMarker(), mapObjectName); getPointDescriptionForMarker(), mapObjectName);
} }
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForTarget());
}
close(); close();
} }

View file

@ -10,14 +10,13 @@ import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.view.View; import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
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; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -180,8 +179,8 @@ public class WptPtEditorFragment extends PointEditorFragment {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path); File gpx = new File(gpxFile.path);
if (gpx.exists()) { if (gpx.exists()) {
getMyApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(), MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE)); helper.runSynchronization(helper.getOrCreateGroup(gpx));
} }
} }

View file

@ -4,8 +4,8 @@ import android.os.Bundle;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter; import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment { public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
@ -18,16 +18,16 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
} }
@Override @Override
public MarkersSyncGroup createMapMarkersSyncGroup(int position) { public GroupsAdapter createAdapter() {
return new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
}
@Override
protected void onItemClick(int position) {
FavoriteGroup group = favouritesDbHelper.getFavoriteGroups().get(position - 1); FavoriteGroup group = favouritesDbHelper.getFavoriteGroups().get(position - 1);
if (!group.visible) { if (!group.visible) {
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true); favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
} }
return new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color); addAndSyncGroup(getMyApplication().getMapMarkersHelper().getOrCreateGroup(group));
}
@Override
public void createAdapter() {
adapter = new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
} }
} }

View file

@ -7,8 +7,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -18,20 +17,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
public static final String TAG = "AddGroupBottomSheetDialogFragment"; public static final String TAG = "AddGroupBottomSheetDialogFragment";
private AddGroupListener listener;
protected View mainView; protected View mainView;
protected GroupsAdapter adapter; 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();
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
@ -41,26 +28,14 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view); final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
createAdapter(); adapter = createAdapter();
adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() { adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {
@Override @Override
public void onItemClick(View view) { public void onItemClick(View view) {
int position = recyclerView.getChildAdapterPosition(view); int position = recyclerView.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
return; AddGroupBottomSheetDialogFragment.this.onItemClick(position);
} }
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); recyclerView.setAdapter(adapter);
@ -82,16 +57,12 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
return false; return false;
} }
private void showProgressBar() { protected void addAndSyncGroup(MapMarkersGroup group) {
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE); getMyApplication().getMapMarkersHelper().syncWithMarkers(group);
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE); dismiss();
} }
protected abstract void createAdapter(); protected abstract GroupsAdapter createAdapter();
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position); protected abstract void onItemClick(int position);
public interface AddGroupListener {
void onGroupAdded();
}
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.annotation.SuppressLint;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -8,7 +9,6 @@ import android.view.View;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
@ -17,9 +17,10 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter; import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter;
import java.io.File; import java.io.File;
@ -33,13 +34,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
private ProcessGpxTask asyncProcessor; private ProcessGpxTask asyncProcessor;
private List<GpxDataItem> gpxList; private List<GpxDataItem> gpxList;
private GpxSelectionHelper gpxSelectionHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gpxSelectionHelper = getMyApplication().getSelectedGpxHelper();
}
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
@ -48,24 +42,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 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 @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
@ -75,12 +51,47 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
} }
} }
@Override
public GroupsAdapter createAdapter() {
gpxList = new ArrayList<>();
return new TracksGroupsAdapter(getContext(), gpxList);
}
@Override
protected void onItemClick(int position) {
GpxDataItem dataItem = gpxList.get(position - 1);
if (dataItem.getAnalysis().wptCategoryNames != null && dataItem.getAnalysis().wptCategoryNames.size() > 1) {
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, dataItem.getFile().getAbsolutePath());
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
dismiss();
} else {
addAndSyncGroup(createMapMarkersSyncGroup(getMyApplication(), dataItem));
}
}
private MapMarkersGroup createMapMarkersSyncGroup(OsmandApplication app, GpxDataItem gpxDataItem) {
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
File gpx = gpxDataItem.getFile();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
if (selectedGpxFile == null) {
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
gpxSelectionHelper.selectGpxFile(res, true, false);
}
return getMyApplication().getMapMarkersHelper().getOrCreateGroup(gpx);
}
@SuppressLint("StaticFieldLeak")
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> { public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {
private OsmandApplication app = getMyApplication(); private OsmandApplication app = getMyApplication();
private Map<File, GpxDataItem> processedDataFiles = new HashMap<>(); private Map<File, GpxDataItem> processedDataFiles = new HashMap<>();
private GPXDatabase db = app.getGpxDatabase(); private GPXDatabase db = app.getGpxDatabase();
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);; private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view); private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
private TextView lookingForTracksText = (TextView) mainView.findViewById(R.id.looking_for_tracks_text); private TextView lookingForTracksText = (TextView) mainView.findViewById(R.id.looking_for_tracks_text);

View file

@ -135,7 +135,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment {
convertView = getMapActivity().getLayoutInflater().inflate(R.layout.map_marker_item, null); convertView = getMapActivity().getLayoutInflater().inflate(R.layout.map_marker_item, null);
} }
MapMarkerDialogHelper.updateMapMarkerInfo(getContext(), convertView, loc, heading, MapMarkerDialogHelper.updateMapMarkerInfo(getContext(), convertView, loc, heading,
useCenter, nightMode, screenOrientation, false, null, marker, true); useCenter, nightMode, screenOrientation, marker);
final View remove = convertView.findViewById(R.id.info_close); final View remove = convertView.findViewById(R.id.info_close);
remove.setVisibility(View.GONE); remove.setVisibility(View.GONE);
AndroidUtils.setListItemBackground(getMapActivity(), convertView, nightMode); AndroidUtils.setListItemBackground(getMapActivity(), convertView, nightMode);

View file

@ -5,19 +5,19 @@ import android.support.annotation.Nullable;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -25,7 +25,7 @@ import java.util.Set;
public class MapMarkersDbHelper { public class MapMarkersDbHelper {
private static final int DB_VERSION = 12; private static final int DB_VERSION = 13;
public static final String DB_NAME = "map_markers_db"; public static final String DB_NAME = "map_markers_db";
private static final String MARKERS_TABLE_NAME = "map_markers"; private static final String MARKERS_TABLE_NAME = "map_markers";
@ -83,19 +83,22 @@ public class MapMarkersDbHelper {
private static final String GROUPS_COL_NAME = "group_name"; private static final String GROUPS_COL_NAME = "group_name";
private static final String GROUPS_COL_TYPE = "group_type"; private static final String GROUPS_COL_TYPE = "group_type";
private static final String GROUPS_COL_DISABLED = "group_disabled"; private static final String GROUPS_COL_DISABLED = "group_disabled";
private static final String GROUPS_COL_CATEGORIES = "group_categories";
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
GROUPS_TABLE_NAME + " (" + GROUPS_TABLE_NAME + " (" +
GROUPS_COL_ID + " TEXT PRIMARY KEY, " + GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
GROUPS_COL_NAME + " TEXT, " + GROUPS_COL_NAME + " TEXT, " +
GROUPS_COL_TYPE + " int, " + GROUPS_COL_TYPE + " int, " +
GROUPS_COL_DISABLED + " int);"; // 1 = true, 0 = false GROUPS_COL_DISABLED + " int, " + // 1 = true, 0 = false
GROUPS_COL_CATEGORIES + " TEXT);";
private static final String GROUPS_TABLE_SELECT = "SELECT " + private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " + GROUPS_COL_ID + ", " +
GROUPS_COL_NAME + ", " + GROUPS_COL_NAME + ", " +
GROUPS_COL_TYPE + ", " + GROUPS_COL_TYPE + ", " +
GROUPS_COL_DISABLED + GROUPS_COL_DISABLED + ", " +
GROUPS_COL_CATEGORIES +
" FROM " + GROUPS_TABLE_NAME; " FROM " + GROUPS_TABLE_NAME;
public static final String TAIL_NEXT_VALUE = "tail_next"; public static final String TAIL_NEXT_VALUE = "tail_next";
@ -156,6 +159,9 @@ public class MapMarkersDbHelper {
if (oldVersion < 12) { if (oldVersion < 12) {
db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT"); db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT");
} }
if (oldVersion < 13) {
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_CATEGORIES + " TEXT");
}
} }
private void saveExistingMarkersToDb() { private void saveExistingMarkersToDb() {
@ -189,26 +195,28 @@ public class MapMarkersDbHelper {
} }
} }
public void addGroup(String id, String name, int type) { public void addGroup(MapMarkersGroup group) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?)", new Object[]{id, name, type, 0}); db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)",
new Object[]{group.getId(), group.getName(), group.getType(), group.isDisabled(), group.getWptCategoriesString()});
} finally { } finally {
db.close(); db.close();
} }
} }
} }
public List<MarkersSyncGroup> getAllGroups() { public Map<String, MapMarkersGroup> getAllGroupsMap() {
List<MarkersSyncGroup> res = new LinkedList<>(); Map<String, MapMarkersGroup> res = new LinkedHashMap<>();
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null); SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
if (query.moveToFirst()) { if (query.moveToFirst()) {
do { do {
res.add(readSyncGroup(query)); MapMarkersGroup group = readGroup(query);
res.put(group.getId(), group);
} while (query.moveToNext()); } while (query.moveToNext());
} }
query.close(); query.close();
@ -219,33 +227,21 @@ public class MapMarkersDbHelper {
return res; return res;
} }
@Nullable private MapMarkersGroup readGroup(SQLiteCursor query) {
public MarkersSyncGroup getGroup(String id) {
MarkersSyncGroup res = null;
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()) {
res = readSyncGroup(query);
}
query.close();
} finally {
db.close();
}
}
return res;
}
private MarkersSyncGroup readSyncGroup(SQLiteCursor query) {
String id = query.getString(0); String id = query.getString(0);
String name = query.getString(1); String name = query.getString(1);
int type = query.getInt(2); int type = query.getInt(2);
boolean disabled = query.getInt(3) == 1;
String categories = query.getString(4);
return new MarkersSyncGroup(id, name, type); MapMarkersGroup res = new MapMarkersGroup(id, name, type);
res.setDisabled(disabled);
res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));
return res;
} }
public void removeMarkersSyncGroup(String id) { public void removeMarkersGroup(String id) {
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
@ -256,21 +252,21 @@ public class MapMarkersDbHelper {
} }
} }
public void removeActiveMarkersFromSyncGroup(String syncGroupId) { public void removeActiveMarkersFromGroup(String groupId) {
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
" WHERE " + MARKERS_COL_GROUP_KEY + " = ?" + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?" +
" AND " + MARKERS_COL_ACTIVE + " = ?", " AND " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{syncGroupId, 1}); new Object[]{groupId, 1});
} finally { } finally {
db.close(); db.close();
} }
} }
} }
public void updateSyncGroupDisabled(String id, boolean disabled) { public void updateGroupDisabled(String id, boolean disabled) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
@ -286,21 +282,17 @@ public class MapMarkersDbHelper {
} }
} }
public boolean isGroupDisabled(String id) { public void updateGroupCategories(String id, String categories) {
boolean disabled = false; SQLiteConnection db = openConnection(false);
SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id}); db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
if (query.moveToFirst()) { " SET " + GROUPS_COL_CATEGORIES + " = ? " +
disabled = query.getInt(3) == 1; "WHERE " + GROUPS_COL_ID + " = ?", new Object[]{categories, id});
}
query.close();
} finally { } finally {
db.close(); db.close();
} }
} }
return disabled;
} }
public void removeDisabledGroups() { public void removeDisabledGroups() {
@ -392,26 +384,6 @@ public class MapMarkersDbHelper {
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName}); marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName});
} }
public List<MapMarker> getMarkersFromGroup(MarkersSyncGroup group) {
List<MapMarker> res = new LinkedList<>();
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?",
new String[]{group.getId()});
if (query.moveToFirst()) {
do {
res.add(readItem(query));
} while (query.moveToNext());
}
query.close();
} finally {
db.close();
}
}
return res;
}
@Nullable @Nullable
public MapMarker getMarker(String id) { public MapMarker getMarker(String id) {
MapMarker res = null; MapMarker res = null;
@ -591,7 +563,7 @@ public class MapMarkersDbHelper {
} }
public List<MapMarker> getMarkersHistory() { public List<MapMarker> getMarkersHistory() {
List<MapMarker> markers = new LinkedList<>(); List<MapMarker> markers = new ArrayList<>();
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
@ -610,26 +582,14 @@ public class MapMarkersDbHelper {
return markers; return markers;
} }
public void removeMarker(MapMarker marker, boolean history) { public void removeMarker(MapMarker marker) {
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
" WHERE " + MARKERS_COL_ID + " = ?" + " WHERE " + MARKERS_COL_ID + " = ?" +
" AND " + MARKERS_COL_ACTIVE + " = ?", " AND " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{marker.id, history ? 0 : 1}); new Object[]{marker.id, marker.history ? 0 : 1});
} finally {
db.close();
}
}
}
public void clearAllMarkersHistory() {
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{0});
} finally { } finally {
db.close(); db.close();
} }

View file

@ -18,6 +18,7 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -26,6 +27,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -45,7 +47,7 @@ import java.util.List;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.GROUPS_MARKERS_MENU; import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.GROUPS_MARKERS_MENU;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.HISTORY_MARKERS_MENU; import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.HISTORY_MARKERS_MENU;
public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment { public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment implements OnGroupSyncedListener {
public static final String TAG = "MapMarkersDialogFragment"; public static final String TAG = "MapMarkersDialogFragment";
@ -62,6 +64,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private Snackbar snackbar; private Snackbar snackbar;
private LockableViewPager viewPager; private LockableViewPager viewPager;
private BottomNavigationView bottomNav; private BottomNavigationView bottomNav;
private ProgressBar progressBar;
private boolean lightTheme; private boolean lightTheme;
private String groupIdToOpen; private String groupIdToOpen;
@ -158,6 +161,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager()); final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);
progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
BottomNavigationViewHelper.disableShiftMode(bottomNav); BottomNavigationViewHelper.disableShiftMode(bottomNav);
if (!lightTheme) { if (!lightTheme) {
@ -206,6 +211,35 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
return mainView; return mainView;
} }
@Override
public void onResume() {
super.onResume();
getMyApplication().getMapMarkersHelper().addSyncListener(this);
}
@Override
public void onPause() {
super.onPause();
getMyApplication().getMapMarkersHelper().removeSyncListener(this);
}
@Override
public void onSyncStarted() {
switchProgressbarVisibility(true);
}
@Override
public void onSyncDone() {
updateAdapters();
switchProgressbarVisibility(false);
}
private void switchProgressbarVisibility(boolean visible) {
if (progressBar != null) {
progressBar.setVisibility(visible ? View.VISIBLE : View.GONE);
}
}
private void setupLocationUpdate(boolean activeFr, boolean groupsFr) { private void setupLocationUpdate(boolean activeFr, boolean groupsFr) {
if (activeFr) { if (activeFr) {
activeFragment.startLocationUpdate(); activeFragment.startLocationUpdate();

View file

@ -69,10 +69,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
if (selectionMarkersGroupFragment != null) { if (selectionMarkersGroupFragment != null) {
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener()); ((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
} }
Fragment addGroupFragment = getChildFragmentManager().findFragmentByTag(AddGroupBottomSheetDialogFragment.TAG);
if (addGroupFragment != null) {
((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
}
Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG); Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
if (historyMarkerMenuFragment != null) { if (historyMarkerMenuFragment != null) {
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener()); ((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
@ -373,33 +369,21 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
} }
private void openAddGroupMenu(AddGroupBottomSheetDialogFragment fragment) { private void openAddGroupMenu(AddGroupBottomSheetDialogFragment fragment) {
fragment.setListener(createAddGroupListener());
fragment.setUsedOnMap(false); fragment.setUsedOnMap(false);
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.show(getChildFragmentManager(), AddGroupBottomSheetDialogFragment.TAG); fragment.show(getChildFragmentManager(), AddGroupBottomSheetDialogFragment.TAG);
} }
private AddGroupBottomSheetDialogFragment.AddGroupListener createAddGroupListener() {
return new AddGroupBottomSheetDialogFragment.AddGroupListener() {
@Override
public void onGroupAdded() {
updateAdapter();
}
};
}
private AddMarkersGroupFragmentListener createAddMarkersGroupFragmentListener() { private AddMarkersGroupFragmentListener createAddMarkersGroupFragmentListener() {
return new AddMarkersGroupFragmentListener() { return new AddMarkersGroupFragmentListener() {
@Override @Override
public void favouritesOnClick() { public void favouritesOnClick() {
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment(); openAddGroupMenu(new AddFavouritesGroupBottomSheetDialogFragment());
openAddGroupMenu(fragment);
} }
@Override @Override
public void waypointsOnClick() { public void waypointsOnClick() {
AddTracksGroupBottomSheetDialogFragment fragment = new AddTracksGroupBottomSheetDialogFragment(); openAddGroupMenu(new AddTracksGroupBottomSheetDialogFragment());
openAddGroupMenu(fragment);
} }
}; };
} }

View file

@ -0,0 +1,159 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment";
public static final String GPX_FILE_PATH_KEY = "gpx_file_path";
private GPXFile gpxFile;
private Set<String> selectedCategories = new HashSet<>();
private List<BottomSheetItemWithCompoundButton> categoryItems = new ArrayList<>();
@Override
public void createMenuItems(Bundle savedInstanceState) {
gpxFile = getGpxFile();
if (gpxFile == null) {
return;
}
items.add(new TitleItem(getGpxName(gpxFile)));
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setDescription(getString(R.string.shared_string_total) + ": " + gpxFile.getPoints().size())
.setIcon(getContentIcon(R.drawable.ic_action_group_select_all))
.setTitle(getString(R.string.shared_string_select_all))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !selectAllItem[0].isChecked();
selectAllItem[0].setChecked(checked);
for (BottomSheetItemWithCompoundButton item : categoryItems) {
item.setChecked(checked);
}
}
})
.create();
items.add(selectAllItem[0]);
items.add(new DividerItem(getContext()));
Map<String, List<WptPt>> pointsByCategories = gpxFile.getPointsByCategories();
for (String category : pointsByCategories.keySet()) {
final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1];
categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
selectedCategories.add((String) categoryItem[0].getTag());
} else {
selectedCategories.remove((String) categoryItem[0].getTag());
}
}
})
.setDescription(String.valueOf(pointsByCategories.get(category).size()))
.setIcon(getContentIcon(R.drawable.ic_action_folder))
.setTitle(category.equals("") ? getString(R.string.waypoints) : category)
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
.setTag(category)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
categoryItem[0].setChecked(!categoryItem[0].isChecked());
selectAllItem[0].setChecked(isAllChecked());
}
})
.create();
items.add(categoryItem[0]);
categoryItems.add(categoryItem[0]);
}
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_import;
}
@Override
protected void onRightBottomButtonClick() {
OsmandApplication app = getMyApplication();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path);
if (selectedGpxFile == null) {
gpxSelectionHelper.selectGpxFile(gpxFile, true, false);
}
MapMarkersGroup markersGr = mapMarkersHelper.getOrCreateGroup(new File(gpxFile.path));
markersGr.setWptCategories(selectedCategories);
mapMarkersHelper.syncWithMarkers(markersGr);
dismiss();
}
private boolean isAllChecked() {
for (BottomSheetItemWithCompoundButton item : categoryItems) {
if (!item.isChecked()) {
return false;
}
}
return true;
}
private String getGpxName(GPXFile gpxFile) {
return new File(gpxFile.path).getName()
.replace(".gpx", "")
.replace("/", " ")
.replace("_", " ");
}
@Nullable
private GPXFile getGpxFile() {
String filePath = getArguments().getString(GPX_FILE_PATH_KEY);
if (filePath != null) {
OsmandApplication app = getMyApplication();
SelectedGpxFile selectedGpx = app.getSelectedGpxHelper().getSelectedFileByPath(filePath);
if (selectedGpx != null && selectedGpx.getGpxFile() != null) {
return selectedGpx.getGpxFile();
}
return GPXUtilities.loadGPXFile(app, new File(filePath));
}
return null;
}
}

View file

@ -237,7 +237,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
final int pos = holder.getAdapterPosition(); final int pos = holder.getAdapterPosition();
final MapMarker marker = getItem(pos); final MapMarker marker = getItem(pos);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker); mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName); MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey);
if (group != null) { if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group); mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
} }

View file

@ -16,10 +16,10 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.GroupHeader; import net.osmand.plus.MapMarkersHelper.GroupHeader;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton; import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -89,10 +89,15 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private void createDisplayGroups() { private void createDisplayGroups() {
items = new ArrayList<>(); items = new ArrayList<>();
app.getMapMarkersHelper().updateGroups(); MapMarkersHelper helper = app.getMapMarkersHelper();
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups(); helper.updateGroups();
List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
groups.addAll(helper.getGroupsForDisplayedGpx());
for (int i = 0; i < groups.size(); i++) { for (int i = 0; i < groups.size(); i++) {
MapMarkersGroup group = groups.get(i); MapMarkersGroup group = groups.get(i);
if (!group.isVisible()) {
continue;
}
String markerGroupName = group.getName(); String markerGroupName = group.getName();
if (markerGroupName == null) { if (markerGroupName == null) {
int previousDateHeader = -1; int previousDateHeader = -1;
@ -148,7 +153,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (!group.isDisabled()) { if (!group.isDisabled()) {
List<Object> objectsToAdd = new ArrayList<>(); List<Object> objectsToAdd = new ArrayList<>();
if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) { if (showHideHistoryButton != null && showHideHistoryButton.showHistory) {
objectsToAdd.addAll(group.getMarkers()); objectsToAdd.addAll(group.getMarkers());
} else { } else {
objectsToAdd.addAll(group.getActiveMarkers()); objectsToAdd.addAll(group.getActiveMarkers());
@ -168,7 +173,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
public int getGroupHeaderPosition(String groupId) { public int getGroupHeaderPosition(String groupId) {
int pos = -1; int pos = -1;
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByKey(groupId); MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId);
if (group != null) { if (group != null) {
pos = items.indexOf(group.getGroupHeader()); pos = items.indexOf(group.getGroupHeader());
} }
@ -374,9 +379,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
if (groupName.equals("")) { if (groupName.equals("")) {
groupName = app.getString(R.string.shared_string_favorites); groupName = app.getString(R.string.shared_string_favorites);
} }
if (group.isDisabled()) {
headerString = groupName;
} else {
headerString = groupName + " \u2014 " headerString = groupName + " \u2014 "
+ group.getActiveMarkers().size() + group.getActiveMarkers().size()
+ "/" + group.getMarkers().size(); + "/" + group.getMarkers().size();
}
headerViewHolder.icon.setVisibility(View.VISIBLE); headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE); headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color)); headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
@ -385,27 +394,27 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() { CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) { public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
group.setDisabled(!enabled);
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
updateDisplayedData();
if (!enabled) {
final GPXFile[] gpxFile = new GPXFile[1]; final GPXFile[] gpxFile = new GPXFile[1];
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getGroupKey()); boolean disabled = !enabled;
if (disabled && group.getType() == MapMarkersGroup.GPX_TYPE) {
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getId());
if (selectedGpxFile != null) { if (selectedGpxFile != null) {
gpxFile[0] = selectedGpxFile.getGpxFile(); gpxFile[0] = selectedGpxFile.getGpxFile();
if (gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], false); switchGpxVisibility(gpxFile[0], false);
} }
} }
app.getMapMarkersHelper().updateGroupDisabled(group, disabled);
app.getMapMarkersHelper().syncWithMarkers(group);
if (disabled) {
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_deleted), Snackbar.LENGTH_LONG) snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_deleted), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() { .setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (gpxFile[0] != null) { if (gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], true); switchGpxVisibility(gpxFile[0], true);
} else {
headerViewHolder.disableGroupSwitch.setChecked(true);
} }
app.getMapMarkersHelper().updateGroupDisabled(group, false);
app.getMapMarkersHelper().syncWithMarkers(group);
} }
}); });
View snackBarView = snackbar.getView(); View snackBarView = snackbar.getView();
@ -426,7 +435,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else if (holder instanceof MapMarkersShowHideHistoryViewHolder) { } else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder; final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position); final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
final boolean showHistory = showHideHistoryButton.isShowHistory(); final boolean showHistory = showHideHistoryButton.showHistory;
if (position == getItemCount() - 1) { if (position == getItemCount() - 1) {
showHideHistoryViewHolder.bottomShadow.setVisibility(View.VISIBLE); showHideHistoryViewHolder.bottomShadow.setVisibility(View.VISIBLE);
} else { } else {
@ -436,7 +445,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() { showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
showHideHistoryButton.setShowHistory(!showHistory); showHideHistoryButton.showHistory = !showHistory;
createDisplayGroups(); createDisplayGroups();
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -447,12 +456,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) { private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper(); GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
gpxHelper.selectGpxFile(gpxFile, visible, false, false); gpxHelper.selectGpxFile(gpxFile, visible, false, false);
gpxHelper.syncGpx(gpxFile, true, new OnGroupSyncedListener() {
@Override
public void onSyncDone() {
updateDisplayedData();
}
});
} }
public void hideSnackbar() { public void hideSnackbar() {

View file

@ -45,12 +45,10 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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;
import net.osmand.plus.activities.IntermediatePointsDialog;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
@ -71,7 +69,6 @@ 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;
@ -378,7 +375,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void selectMapMarkers() { private void selectMapMarkers() {
enterMapMarkersMode(); if (getGpxDataItem() != null) {
addMapMarkersSyncGroup();
}
} }
private void selectFavorites() { private void selectFavorites() {
@ -580,62 +579,15 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path); File gpx = new File(gpxFile.path);
if (gpx.exists()) { if (gpx.exists()) {
app.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(), MapMarkersHelper helper = app.getMapMarkersHelper();
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE)); helper.runSynchronization(helper.getOrCreateGroup(gpx));
}
}
private void enterMapMarkersMode() {
if (getSettings().USE_MAP_MARKERS.get()) {
if (getGpxDataItem() != null) {
addMapMarkersSyncGroup();
}
} else {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
enableSelectionMode(true);
createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points,
R.drawable.ic_action_intermediate, R.drawable.ic_action_intermediate,
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
selectedItems.clear();
selectedGroups.clear();
adapter.notifyDataSetInvalidated();
updateSelectionMode(mode);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
enableSelectionMode(false);
adapter.notifyDataSetInvalidated();
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == SELECT_MAP_MARKERS_ACTION_MODE_ID) {
mode.finish();
selectMapMarkersImpl();
}
return true;
}
});
} }
} }
private void addMapMarkersSyncGroup() { private void addMapMarkersSyncGroup() {
MapMarkersHelper markersHelper = app.getMapMarkersHelper(); MapMarkersHelper markersHelper = app.getMapMarkersHelper();
File gpx = getGpxDataItem().getFile(); final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile());
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), markersHelper.syncWithMarkers(markersGr);
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.syncGroupAsync(syncGroup);
GPXFile gpxFile = getTrackActivity().getGpx(); GPXFile gpxFile = getTrackActivity().getGpx();
if (gpxFile != null) { if (gpxFile != null) {
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false); app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
@ -648,7 +600,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(MarkersSyncGroup.MARKERS_SYNC_GROUP_ID, syncGroup.getId()); args.putString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID, markersGr.getId());
MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS, args); MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS, args);
} }
}); });
@ -669,41 +621,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
menuFab.setVisibility(visible ? View.VISIBLE : View.GONE); menuFab.setVisibility(visible ? View.VISIBLE : View.GONE);
} }
private void selectMapMarkersImpl() {
if (getSelectedItemsCount() > 0) {
if (getSettings().USE_MAP_MARKERS.get()) {
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<LatLon> points = new LinkedList<>();
List<PointDescription> names = new LinkedList<>();
for (Map.Entry<GpxDisplayItemType, Set<GpxDisplayItem>> entry : selectedItems.entrySet()) {
if (entry.getKey() != GpxDisplayItemType.TRACK_POINTS) {
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);
}
}
MapActivity.launchMapActivityMoveToTop(getActivity());
} else {
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
for (GpxDisplayItem i : getSelectedItems()) {
if (i.locationStart != null) {
targetPointsHelper.navigateToPoint(new LatLon(i.locationStart.lat, i.locationStart.lon), false,
targetPointsHelper.getIntermediatePoints().size() + 1,
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, i.name));
}
}
if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
targetPointsHelper.updateRouteAndRefresh(true);
}
IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), true);
}
}
}
private void enterFavoritesMode() { private void enterFavoritesMode() {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() { actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {

View file

@ -20,7 +20,6 @@ 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 net.osmand.AndroidUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -36,7 +35,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -666,8 +664,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path); File gpx = new File(gpxFile.path);
if (gpx.exists()) { if (gpx.exists()) {
mapMarkersHelper.syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(), mapMarkersHelper.runSynchronization(view.getApplication().getMapMarkersHelper().getOrCreateGroup(gpx));
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
} }
} }

View file

@ -319,7 +319,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom()); widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
OsmandSettings settings = map.getMyApplication().getSettings(); OsmandSettings settings = map.getMyApplication().getSettings();
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { if (tileBox.getZoom() < 3) {
return; return;
} }
@ -514,7 +514,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
@Override @Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) { public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) { if (tileBox.getZoom() < 3) {
return; return;
} }
amenities.clear(); amenities.clear();

View file

@ -185,10 +185,6 @@ public class MapMarkersWidgetsFactory {
} }
public void updateInfo(LatLon customLocation, int zoom) { public void updateInfo(LatLon customLocation, int zoom) {
if (!map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
return;
}
if (customLocation != null) { if (customLocation != null) {
loc = customLocation; loc = customLocation;
} else { } else {

View file

@ -321,7 +321,6 @@ public class MapWidgetRegistry {
if (mode != ApplicationMode.DEFAULT) { if (mode != ApplicationMode.DEFAULT) {
addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
} }
if (settings.USE_MAP_MARKERS.get()) {
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map) cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map)
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map)) .setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
.setListener(new ContextMenuAdapter.ItemClickListener() { .setListener(new ContextMenuAdapter.ItemClickListener() {
@ -341,7 +340,6 @@ public class MapWidgetRegistry {
} }
}).setLayout(R.layout.list_item_text_button).createItem()); }).setLayout(R.layout.list_item_text_button).createItem());
} }
}
public void updateMapMarkersMode(MapActivity mapActivity) { public void updateMapMarkersMode(MapActivity mapActivity) {
for (MapWidgetRegInfo info : rightWidgetSet) { for (MapWidgetRegInfo info : rightWidgetSet) {