Merge pull request #5146 from osmandapp/waypoint_categories_import
Waypoint categories import
This commit is contained in:
commit
984a71b778
29 changed files with 1666 additions and 2609 deletions
|
@ -30,16 +30,34 @@
|
|||
app:contentInsetLeft="54dp"
|
||||
app:contentInsetStart="54dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/map_markers"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/map_markers"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
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.design.widget.AppBarLayout>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="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="group_deleted">Group deleted</string>
|
||||
<string name="rendering_attr_whiteWaterSports_name">Whitewater sports</string>
|
||||
|
|
|
@ -603,7 +603,6 @@ public class AppInitializer implements IProgress {
|
|||
notifyEvent(InitEvents.LOAD_GPX_TRACKS);
|
||||
saveGPXTracks();
|
||||
notifyEvent(InitEvents.SAVE_GPX_TRACKS);
|
||||
app.mapMarkersHelper.syncAllGroupsAsync();
|
||||
// restore backuped favorites to normal file
|
||||
restoreBackupForFavoritesFiles();
|
||||
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
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.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -110,6 +109,20 @@ public class FavouritesDbHelper {
|
|||
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() {
|
||||
return context.getFileStreamPath(FILE_TO_BACKUP);
|
||||
|
@ -127,7 +140,7 @@ public class FavouritesDbHelper {
|
|||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
for (FavoriteGroup gr : groupsToSync) {
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
runSyncWithMarkers(gr);
|
||||
}
|
||||
}
|
||||
if (groupsToDelete != null) {
|
||||
|
@ -135,7 +148,7 @@ public class FavouritesDbHelper {
|
|||
flatGroups.remove(g.name);
|
||||
favoriteGroups.remove(g);
|
||||
cachedFavoritePoints.removeAll(g.points);
|
||||
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name);
|
||||
removeFromMarkers(g);
|
||||
}
|
||||
}
|
||||
saveCurrentPointsIntoFile();
|
||||
|
@ -150,7 +163,7 @@ public class FavouritesDbHelper {
|
|||
FavoriteGroup group = flatGroups.get(p.getCategory());
|
||||
if (group != null) {
|
||||
group.points.remove(p);
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
runSyncWithMarkers(group);
|
||||
}
|
||||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
|
@ -180,7 +193,7 @@ public class FavouritesDbHelper {
|
|||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
runSyncWithMarkers(group);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -275,7 +288,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
runSyncWithMarkers(getOrCreateGroup(p, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -283,7 +296,7 @@ public class FavouritesDbHelper {
|
|||
p.setLatitude(lat);
|
||||
p.setLongitude(lon);
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
runSyncWithMarkers(getOrCreateGroup(p, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -352,7 +365,7 @@ public class FavouritesDbHelper {
|
|||
if (remove) {
|
||||
flatGroups.remove(group.name);
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name);
|
||||
removeFromMarkers(group);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -603,14 +616,13 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
|
||||
MapMarkersHelper markersHelper = context.getMapMarkersHelper();
|
||||
if (color != 0 && group.color != color) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
group.color = color;
|
||||
for (FavouritePoint p : gr.points) {
|
||||
p.setColor(color);
|
||||
}
|
||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
|
||||
runSyncWithMarkers(gr);
|
||||
}
|
||||
if (group.visible != visible) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
|
@ -618,11 +630,11 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setVisible(visible);
|
||||
}
|
||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
runSyncWithMarkers(gr);
|
||||
}
|
||||
if (!group.name.equals(newName)) {
|
||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||
markersHelper.removeMarkersSyncGroup(group.name);
|
||||
removeFromMarkers(gr);
|
||||
gr.name = newName;
|
||||
FavoriteGroup renamedGroup = flatGroups.get(gr.name);
|
||||
boolean existing = renamedGroup != null;
|
||||
|
@ -638,9 +650,7 @@ public class FavouritesDbHelper {
|
|||
renamedGroup.points.add(p);
|
||||
}
|
||||
}
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroupAsync(syncGroup);
|
||||
addToMarkers(renamedGroup);
|
||||
}
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.data.LatLon;
|
||||
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.TrkSegment;
|
||||
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.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
|
@ -502,7 +499,7 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
}
|
||||
if (syncGroup) {
|
||||
syncGpx(gpx, true, null);
|
||||
syncGpx(gpx);
|
||||
}
|
||||
return sf;
|
||||
}
|
||||
|
@ -539,25 +536,10 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
|
||||
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);
|
||||
if (gpx.exists()) {
|
||||
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
boolean enabled = true;
|
||||
if (createOrDeleteGroup) {
|
||||
boolean show = getSelectedFileByPath(gpx.getAbsolutePath()) != null;
|
||||
enabled = mapMarkersHelper.isGroupSynced(gpx.getAbsolutePath());
|
||||
if (show && !enabled) {
|
||||
mapMarkersHelper.addMarkersSyncGroup(syncGroup);
|
||||
} else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) {
|
||||
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback);
|
||||
mapMarkersHelper.runSynchronization(mapMarkersHelper.getOrCreateGroup(gpx));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,7 +23,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
|
@ -156,49 +156,30 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
|
||||
if (group.points.size() > 0) {
|
||||
items.add(new DividerHalfItem(getContext()));
|
||||
}
|
||||
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final MarkersSyncGroup syncGroup =
|
||||
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
|
||||
final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
|
||||
|
||||
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
|
||||
BaseBottomSheetItem addToMarkersItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_flag_dark))
|
||||
.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))
|
||||
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark))
|
||||
.setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
markersHelper.removeMarkersSyncGroup(syncGroup.getId());
|
||||
if (synced) {
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
} else {
|
||||
markersHelper.syncWithMarkers(markersGr);
|
||||
}
|
||||
dismiss();
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(removeFromMarkersItem);
|
||||
}
|
||||
items.add(markersGroupItem);
|
||||
|
||||
if (group.points.size() > 0) {
|
||||
BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_gshare_dark))
|
||||
.setTitle(getString(R.string.shared_string_share))
|
||||
|
@ -208,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
public void onClick(View view) {
|
||||
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
|
||||
if (fragment != null) {
|
||||
fragment.shareFavorites(group);
|
||||
fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
|
|
@ -36,12 +36,11 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
@ -58,7 +57,6 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -347,13 +345,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
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,
|
||||
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,
|
||||
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, 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);
|
||||
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);
|
||||
// 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
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
enableSelectionMode(true);
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
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,
|
||||
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);
|
||||
}
|
||||
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,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
favoritesSelected.clear();
|
||||
groupsToDelete.clear();
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
|
@ -424,40 +411,25 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
|
||||
private void selectMapMarkersImpl() {
|
||||
if (getSelectedFavoritesCount() > 0) {
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
List<LatLon> points = new LinkedList<>();
|
||||
List<PointDescription> names = new LinkedList<>();
|
||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
MarkersSyncGroup syncGr =
|
||||
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
markersHelper.addMarkersSyncGroup(syncGr);
|
||||
markersHelper.syncGroupAsync(syncGr);
|
||||
} else {
|
||||
for (FavouritePoint fp : entry.getValue()) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names, syncGr);
|
||||
points.clear();
|
||||
names.clear();
|
||||
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
List<LatLon> points = new ArrayList<>();
|
||||
List<PointDescription> names = new ArrayList<>();
|
||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(favGr);
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
markersHelper.syncWithMarkers(markersGr);
|
||||
} else {
|
||||
for (FavouritePoint fp : entry.getValue()) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names, markersGr);
|
||||
points.clear();
|
||||
names.clear();
|
||||
}
|
||||
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);
|
||||
}
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -719,7 +719,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
|
||||
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ public class BaseBottomSheetItem {
|
|||
return view;
|
||||
}
|
||||
|
||||
public Object getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public BaseBottomSheetItem(View view,
|
||||
@LayoutRes int layoutId,
|
||||
Object tag,
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.v4.widget.CompoundButtonCompat;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -16,9 +17,14 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
|
||||
private boolean checked;
|
||||
private ColorStateList buttonTintList;
|
||||
private OnCheckedChangeListener onCheckedChangeListener;
|
||||
|
||||
private CompoundButton compoundButton;
|
||||
|
||||
public boolean isChecked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithCompoundButton(View customView,
|
||||
@LayoutRes int layoutId,
|
||||
Object tag,
|
||||
|
@ -31,7 +37,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
CharSequence description,
|
||||
@ColorRes int descriptionColorId,
|
||||
boolean checked,
|
||||
ColorStateList buttonTintList) {
|
||||
ColorStateList buttonTintList,
|
||||
OnCheckedChangeListener onCheckedChangeListener) {
|
||||
super(customView,
|
||||
layoutId,
|
||||
tag,
|
||||
|
@ -45,6 +52,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
descriptionColorId);
|
||||
this.checked = checked;
|
||||
this.buttonTintList = buttonTintList;
|
||||
this.onCheckedChangeListener = onCheckedChangeListener;
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
|
@ -58,12 +66,14 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
compoundButton = (CompoundButton) view.findViewById(R.id.compound_button);
|
||||
compoundButton.setChecked(checked);
|
||||
CompoundButtonCompat.setButtonTintList(compoundButton, buttonTintList);
|
||||
compoundButton.setOnCheckedChangeListener(onCheckedChangeListener);
|
||||
}
|
||||
|
||||
public static class Builder extends BottomSheetItemWithDescription.Builder {
|
||||
|
||||
protected boolean checked;
|
||||
protected ColorStateList buttonTintList;
|
||||
protected OnCheckedChangeListener onCheckedChangeListener;
|
||||
|
||||
public Builder setChecked(boolean checked) {
|
||||
this.checked = checked;
|
||||
|
@ -75,6 +85,11 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
|
||||
this.onCheckedChangeListener = onCheckedChangeListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithCompoundButton create() {
|
||||
return new BottomSheetItemWithCompoundButton(customView,
|
||||
layoutId,
|
||||
|
@ -88,7 +103,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
description,
|
||||
descriptionColorId,
|
||||
checked,
|
||||
buttonTintList);
|
||||
buttonTintList,
|
||||
onCheckedChangeListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,473 +1,35 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
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.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
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.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
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.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.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
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;
|
||||
private OsmandApplication app;
|
||||
private MapMarkersHelper markersHelper;
|
||||
private MapMarkersDialogHelperCallbacks helperCallbacks;
|
||||
private boolean sorted;
|
||||
private boolean nightMode;
|
||||
private boolean selectionMode;
|
||||
|
||||
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) {
|
||||
public static void updateMapMarkerInfo(final Context ctx,
|
||||
View localView,
|
||||
LatLon loc,
|
||||
Float heading,
|
||||
boolean useCenter,
|
||||
boolean nightMode,
|
||||
int screenOrientation,
|
||||
final MapMarker marker) {
|
||||
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
|
||||
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
|
||||
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
|
||||
|
@ -539,360 +101,29 @@ public class MapMarkerDialogHelper {
|
|||
|
||||
descText.setVisibility(View.GONE);
|
||||
|
||||
if (showDateAndGroup) {
|
||||
Date date = new Date(marker.creationDate);
|
||||
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
|
||||
if (month.length() > 1) {
|
||||
month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
|
||||
Date date = new Date(marker.creationDate);
|
||||
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
|
||||
if (month.length() > 1) {
|
||||
month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
|
||||
}
|
||||
month = month.replaceAll("\\.", "");
|
||||
String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
|
||||
String desc = month + " " + day;
|
||||
String markerGroupName = marker.groupName;
|
||||
if (markerGroupName != null) {
|
||||
if (markerGroupName.equals("")) {
|
||||
markerGroupName = app.getString(R.string.shared_string_favorites);
|
||||
}
|
||||
month = month.replaceAll("\\.", "");
|
||||
String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
|
||||
String desc = month + " " + day;
|
||||
String markerGroupName = marker.groupName;
|
||||
if (markerGroupName != null) {
|
||||
if (markerGroupName.equals("")) {
|
||||
markerGroupName = app.getString(R.string.shared_string_favorites);
|
||||
}
|
||||
desc += " • " + markerGroupName;
|
||||
}
|
||||
dateGroupText.setVisibility(View.VISIBLE);
|
||||
dateGroupText.setText(desc);
|
||||
desc += " • " + markerGroupName;
|
||||
}
|
||||
dateGroupText.setVisibility(View.VISIBLE);
|
||||
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.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;
|
||||
checkBox.setVisibility(View.GONE);
|
||||
checkBox.setOnClickListener(null);
|
||||
}
|
||||
|
||||
public static Drawable getMapMarkerIcon(OsmandApplication app, int 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -836,23 +836,18 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (marker != null) {
|
||||
RenameMarkerBottomSheetDialogFragment
|
||||
.showInstance(mapActivity.getSupportFragmentManager(), marker);
|
||||
} else if (settings.USE_MAP_MARKERS.get()) {
|
||||
if (pointDescription.isMapMarker()) {
|
||||
hide();
|
||||
MapActivity.clearPrevActivityIntent();
|
||||
MapMarkersDialogFragment.showInstance(mapActivity);
|
||||
} else {
|
||||
String mapObjectName = null;
|
||||
if (object instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) object;
|
||||
mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName();
|
||||
}
|
||||
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
|
||||
getPointDescriptionForMarker(), mapObjectName);
|
||||
}
|
||||
} else if (pointDescription.isMapMarker()) {
|
||||
hide();
|
||||
MapActivity.clearPrevActivityIntent();
|
||||
MapMarkersDialogFragment.showInstance(mapActivity);
|
||||
} else {
|
||||
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
|
||||
getPointDescriptionForTarget());
|
||||
String mapObjectName = null;
|
||||
if (object instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) object;
|
||||
mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName();
|
||||
}
|
||||
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
|
||||
getPointDescriptionForMarker(), mapObjectName);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
|
|
@ -10,14 +10,13 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
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.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -180,8 +179,8 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
getMyApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
|
||||
helper.runSynchronization(helper.getOrCreateGroup(gpx));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.os.Bundle;
|
|||
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
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.GroupsAdapter;
|
||||
|
||||
public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
|
||||
|
||||
|
@ -18,16 +18,16 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
|||
}
|
||||
|
||||
@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);
|
||||
if (!group.visible) {
|
||||
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
|
||||
}
|
||||
return new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAdapter() {
|
||||
adapter = new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
|
||||
addAndSyncGroup(getMyApplication().getMapMarkersHelper().getOrCreateGroup(group));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
|
@ -18,20 +17,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
|
||||
public static final String TAG = "AddGroupBottomSheetDialogFragment";
|
||||
|
||||
private AddGroupListener listener;
|
||||
protected View mainView;
|
||||
protected GroupsAdapter adapter;
|
||||
protected MapMarkersHelper mapMarkersHelper;
|
||||
|
||||
public void setListener(AddGroupListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
createAdapter();
|
||||
adapter = createAdapter();
|
||||
adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
int position = recyclerView.getChildAdapterPosition(view);
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
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);
|
||||
|
@ -82,16 +57,12 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
return false;
|
||||
}
|
||||
|
||||
private void showProgressBar() {
|
||||
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
|
||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
protected void addAndSyncGroup(MapMarkersGroup group) {
|
||||
getMyApplication().getMapMarkersHelper().syncWithMarkers(group);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
protected abstract void createAdapter();
|
||||
protected abstract GroupsAdapter createAdapter();
|
||||
|
||||
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position);
|
||||
|
||||
public interface AddGroupListener {
|
||||
void onGroupAdded();
|
||||
}
|
||||
protected abstract void onItemClick(int position);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -8,7 +9,6 @@ import android.view.View;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GPXDatabase;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
|
@ -17,9 +17,10 @@ import net.osmand.plus.GPXUtilities.GPXFile;
|
|||
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
|
||||
import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -33,13 +34,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
|
||||
private ProcessGpxTask asyncProcessor;
|
||||
private List<GpxDataItem> gpxList;
|
||||
private GpxSelectionHelper gpxSelectionHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
gpxSelectionHelper = getMyApplication().getSelectedGpxHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -48,24 +42,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAdapter() {
|
||||
gpxList = new ArrayList<>();
|
||||
adapter = new TracksGroupsAdapter(getContext(), gpxList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
|
||||
GpxDataItem gpxDataItem = gpxList.get(position - 1);
|
||||
File gpx = gpxDataItem.getFile();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
|
||||
if (selectedGpxFile == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(getContext(), gpx);
|
||||
gpxSelectionHelper.selectGpxFile(res, true, false, false);
|
||||
}
|
||||
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -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> {
|
||||
|
||||
private OsmandApplication app = getMyApplication();
|
||||
private Map<File, GpxDataItem> processedDataFiles = new HashMap<>();
|
||||
private GPXDatabase db = app.getGpxDatabase();
|
||||
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);;
|
||||
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
|
||||
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
|
||||
private TextView lookingForTracksText = (TextView) mainView.findViewById(R.id.looking_for_tracks_text);
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment {
|
|||
convertView = getMapActivity().getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
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);
|
||||
remove.setVisibility(View.GONE);
|
||||
AndroidUtils.setListItemBackground(getMapActivity(), convertView, nightMode);
|
||||
|
|
|
@ -5,19 +5,19 @@ import android.support.annotation.Nullable;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
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.OsmandSettings;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
@ -25,7 +25,7 @@ import java.util.Set;
|
|||
|
||||
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";
|
||||
|
||||
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_TYPE = "group_type";
|
||||
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 " +
|
||||
GROUPS_TABLE_NAME + " (" +
|
||||
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
|
||||
GROUPS_COL_NAME + " TEXT, " +
|
||||
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 " +
|
||||
GROUPS_COL_ID + ", " +
|
||||
GROUPS_COL_NAME + ", " +
|
||||
GROUPS_COL_TYPE + ", " +
|
||||
GROUPS_COL_DISABLED +
|
||||
GROUPS_COL_DISABLED + ", " +
|
||||
GROUPS_COL_CATEGORIES +
|
||||
" FROM " + GROUPS_TABLE_NAME;
|
||||
|
||||
public static final String TAIL_NEXT_VALUE = "tail_next";
|
||||
|
@ -156,6 +159,9 @@ public class MapMarkersDbHelper {
|
|||
if (oldVersion < 12) {
|
||||
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() {
|
||||
|
@ -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);
|
||||
if (db != null) {
|
||||
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 {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<MarkersSyncGroup> getAllGroups() {
|
||||
List<MarkersSyncGroup> res = new LinkedList<>();
|
||||
public Map<String, MapMarkersGroup> getAllGroupsMap() {
|
||||
Map<String, MapMarkersGroup> res = new LinkedHashMap<>();
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
|
||||
if (query.moveToFirst()) {
|
||||
do {
|
||||
res.add(readSyncGroup(query));
|
||||
MapMarkersGroup group = readGroup(query);
|
||||
res.put(group.getId(), group);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
query.close();
|
||||
|
@ -219,33 +227,21 @@ public class MapMarkersDbHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
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) {
|
||||
private MapMarkersGroup readGroup(SQLiteCursor query) {
|
||||
String id = query.getString(0);
|
||||
String name = query.getString(1);
|
||||
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);
|
||||
if (db != null) {
|
||||
try {
|
||||
|
@ -256,21 +252,21 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
|
||||
public void removeActiveMarkersFromGroup(String groupId) {
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
|
||||
" WHERE " + MARKERS_COL_GROUP_KEY + " = ?" +
|
||||
" AND " + MARKERS_COL_ACTIVE + " = ?",
|
||||
new Object[]{syncGroupId, 1});
|
||||
new Object[]{groupId, 1});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSyncGroupDisabled(String id, boolean disabled) {
|
||||
public void updateGroupDisabled(String id, boolean disabled) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
|
@ -286,21 +282,17 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isGroupDisabled(String id) {
|
||||
boolean disabled = false;
|
||||
SQLiteConnection db = openConnection(true);
|
||||
public void updateGroupCategories(String id, String categories) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id});
|
||||
if (query.moveToFirst()) {
|
||||
disabled = query.getInt(3) == 1;
|
||||
}
|
||||
query.close();
|
||||
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
|
||||
" SET " + GROUPS_COL_CATEGORIES + " = ? " +
|
||||
"WHERE " + GROUPS_COL_ID + " = ?", new Object[]{categories, id});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public void removeDisabledGroups() {
|
||||
|
@ -385,33 +377,13 @@ public class MapMarkersDbHelper {
|
|||
MARKERS_COL_NEXT_KEY + ", " +
|
||||
MARKERS_COL_DISABLED + ", " +
|
||||
MARKERS_COL_SELECTED + ", " +
|
||||
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
||||
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active,
|
||||
currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex,
|
||||
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
|
||||
public MapMarker getMarker(String id) {
|
||||
MapMarker res = null;
|
||||
|
@ -591,7 +563,7 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
|
||||
public List<MapMarker> getMarkersHistory() {
|
||||
List<MapMarker> markers = new LinkedList<>();
|
||||
List<MapMarker> markers = new ArrayList<>();
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
|
@ -610,26 +582,14 @@ public class MapMarkersDbHelper {
|
|||
return markers;
|
||||
}
|
||||
|
||||
public void removeMarker(MapMarker marker, boolean history) {
|
||||
public void removeMarker(MapMarker marker) {
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
|
||||
" WHERE " + MARKERS_COL_ID + " = ?" +
|
||||
" AND " + MARKERS_COL_ACTIVE + " = ?",
|
||||
new Object[]{marker.id, 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});
|
||||
new Object[]{marker.id, marker.history ? 0 : 1});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef;
|
||||
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
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.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";
|
||||
|
||||
|
@ -62,6 +64,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
private Snackbar snackbar;
|
||||
private LockableViewPager viewPager;
|
||||
private BottomNavigationView bottomNav;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
private boolean lightTheme;
|
||||
private String groupIdToOpen;
|
||||
|
@ -158,6 +161,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager());
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
|
||||
|
||||
bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
|
||||
BottomNavigationViewHelper.disableShiftMode(bottomNav);
|
||||
if (!lightTheme) {
|
||||
|
@ -206,6 +211,35 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
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) {
|
||||
if (activeFr) {
|
||||
activeFragment.startLocationUpdate();
|
||||
|
|
|
@ -69,10 +69,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
if (selectionMarkersGroupFragment != null) {
|
||||
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
|
||||
}
|
||||
Fragment addGroupFragment = getChildFragmentManager().findFragmentByTag(AddGroupBottomSheetDialogFragment.TAG);
|
||||
if (addGroupFragment != null) {
|
||||
((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
|
||||
}
|
||||
Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
|
||||
if (historyMarkerMenuFragment != null) {
|
||||
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
|
||||
|
@ -373,33 +369,21 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
}
|
||||
|
||||
private void openAddGroupMenu(AddGroupBottomSheetDialogFragment fragment) {
|
||||
fragment.setListener(createAddGroupListener());
|
||||
fragment.setUsedOnMap(false);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(getChildFragmentManager(), AddGroupBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
|
||||
private AddGroupBottomSheetDialogFragment.AddGroupListener createAddGroupListener() {
|
||||
return new AddGroupBottomSheetDialogFragment.AddGroupListener() {
|
||||
@Override
|
||||
public void onGroupAdded() {
|
||||
updateAdapter();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private AddMarkersGroupFragmentListener createAddMarkersGroupFragmentListener() {
|
||||
return new AddMarkersGroupFragmentListener() {
|
||||
@Override
|
||||
public void favouritesOnClick() {
|
||||
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
|
||||
openAddGroupMenu(fragment);
|
||||
openAddGroupMenu(new AddFavouritesGroupBottomSheetDialogFragment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waypointsOnClick() {
|
||||
AddTracksGroupBottomSheetDialogFragment fragment = new AddTracksGroupBottomSheetDialogFragment();
|
||||
openAddGroupMenu(fragment);
|
||||
openAddGroupMenu(new AddTracksGroupBottomSheetDialogFragment());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -237,7 +237,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
|||
final int pos = holder.getAdapterPosition();
|
||||
final MapMarker marker = getItem(pos);
|
||||
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) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ import net.osmand.plus.GPXUtilities.GPXFile;
|
|||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.GroupHeader;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
|
||||
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -89,10 +89,15 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
|
||||
private void createDisplayGroups() {
|
||||
items = new ArrayList<>();
|
||||
app.getMapMarkersHelper().updateGroups();
|
||||
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
|
||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
||||
helper.updateGroups();
|
||||
List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
|
||||
groups.addAll(helper.getGroupsForDisplayedGpx());
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
MapMarkersGroup group = groups.get(i);
|
||||
if (!group.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
String markerGroupName = group.getName();
|
||||
if (markerGroupName == null) {
|
||||
int previousDateHeader = -1;
|
||||
|
@ -148,7 +153,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
|
||||
if (!group.isDisabled()) {
|
||||
List<Object> objectsToAdd = new ArrayList<>();
|
||||
if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) {
|
||||
if (showHideHistoryButton != null && showHideHistoryButton.showHistory) {
|
||||
objectsToAdd.addAll(group.getMarkers());
|
||||
} else {
|
||||
objectsToAdd.addAll(group.getActiveMarkers());
|
||||
|
@ -168,7 +173,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
|
||||
public int getGroupHeaderPosition(String groupId) {
|
||||
int pos = -1;
|
||||
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByKey(groupId);
|
||||
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId);
|
||||
if (group != null) {
|
||||
pos = items.indexOf(group.getGroupHeader());
|
||||
}
|
||||
|
@ -374,9 +379,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
if (groupName.equals("")) {
|
||||
groupName = app.getString(R.string.shared_string_favorites);
|
||||
}
|
||||
headerString = groupName + " \u2014 "
|
||||
+ group.getActiveMarkers().size()
|
||||
+ "/" + group.getMarkers().size();
|
||||
if (group.isDisabled()) {
|
||||
headerString = groupName;
|
||||
} else {
|
||||
headerString = groupName + " \u2014 "
|
||||
+ group.getActiveMarkers().size()
|
||||
+ "/" + group.getMarkers().size();
|
||||
}
|
||||
headerViewHolder.icon.setVisibility(View.VISIBLE);
|
||||
headerViewHolder.iconSpace.setVisibility(View.GONE);
|
||||
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() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||
group.setDisabled(!enabled);
|
||||
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
|
||||
updateDisplayedData();
|
||||
if (!enabled) {
|
||||
final GPXFile[] gpxFile = new GPXFile[1];
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getGroupKey());
|
||||
final GPXFile[] gpxFile = new GPXFile[1];
|
||||
boolean disabled = !enabled;
|
||||
if (disabled && group.getType() == MapMarkersGroup.GPX_TYPE) {
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getId());
|
||||
if (selectedGpxFile != null) {
|
||||
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)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (gpxFile[0] != null) {
|
||||
switchGpxVisibility(gpxFile[0], true);
|
||||
} else {
|
||||
headerViewHolder.disableGroupSwitch.setChecked(true);
|
||||
}
|
||||
app.getMapMarkersHelper().updateGroupDisabled(group, false);
|
||||
app.getMapMarkersHelper().syncWithMarkers(group);
|
||||
}
|
||||
});
|
||||
View snackBarView = snackbar.getView();
|
||||
|
@ -426,7 +435,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
} else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
|
||||
final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
|
||||
final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
|
||||
final boolean showHistory = showHideHistoryButton.isShowHistory();
|
||||
final boolean showHistory = showHideHistoryButton.showHistory;
|
||||
if (position == getItemCount() - 1) {
|
||||
showHideHistoryViewHolder.bottomShadow.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
@ -436,7 +445,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showHideHistoryButton.setShowHistory(!showHistory);
|
||||
showHideHistoryButton.showHistory = !showHistory;
|
||||
createDisplayGroups();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
@ -447,12 +456,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) {
|
||||
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
|
||||
gpxHelper.selectGpxFile(gpxFile, visible, false, false);
|
||||
gpxHelper.syncGpx(gpxFile, true, new OnGroupSyncedListener() {
|
||||
@Override
|
||||
public void onSyncDone() {
|
||||
updateDisplayedData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void hideSnackbar() {
|
||||
|
|
|
@ -45,12 +45,10 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
||||
import net.osmand.plus.IconsCache;
|
||||
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.OsmandSettings;
|
||||
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.OsmandActionBarActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
|
@ -71,7 +69,6 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -378,7 +375,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
|
||||
private void selectMapMarkers() {
|
||||
enterMapMarkersMode();
|
||||
if (getGpxDataItem() != null) {
|
||||
addMapMarkersSyncGroup();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectFavorites() {
|
||||
|
@ -580,62 +579,15 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
app.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
||||
helper.runSynchronization(helper.getOrCreateGroup(gpx));
|
||||
}
|
||||
}
|
||||
|
||||
private void addMapMarkersSyncGroup() {
|
||||
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
File gpx = getGpxDataItem().getFile();
|
||||
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroupAsync(syncGroup);
|
||||
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile());
|
||||
markersHelper.syncWithMarkers(markersGr);
|
||||
GPXFile gpxFile = getTrackActivity().getGpx();
|
||||
if (gpxFile != null) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
|
||||
|
@ -648,7 +600,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@ -669,41 +621,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
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() {
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
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.SelectedGpxFile;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -666,8 +664,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
mapMarkersHelper.syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
mapMarkersHelper.runSynchronization(view.getApplication().getMapMarkersHelper().getOrCreateGroup(gpx));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
|
||||
OsmandSettings settings = map.getMyApplication().getSettings();
|
||||
|
||||
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
|
||||
if (tileBox.getZoom() < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
amenities.clear();
|
||||
|
|
|
@ -185,10 +185,6 @@ public class MapMarkersWidgetsFactory {
|
|||
}
|
||||
|
||||
public void updateInfo(LatLon customLocation, int zoom) {
|
||||
if (!map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (customLocation != null) {
|
||||
loc = customLocation;
|
||||
} else {
|
||||
|
|
|
@ -321,26 +321,24 @@ public class MapWidgetRegistry {
|
|||
if (mode != ApplicationMode.DEFAULT) {
|
||||
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)
|
||||
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int position, boolean isChecked, int[] viewCoordinates) {
|
||||
DirectionIndicationDialogFragment fragment = new DirectionIndicationDialogFragment();
|
||||
fragment.setListener(new DirectionIndicationDialogFragment.DirectionIndicationFragmentListener() {
|
||||
@Override
|
||||
public void onMapMarkersModeChanged(boolean showDirectionEnabled) {
|
||||
updateMapMarkersMode(map);
|
||||
cm.getItem(position).setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
fragment.show(map.getSupportFragmentManager(), DirectionIndicationDialogFragment.TAG);
|
||||
return false;
|
||||
}
|
||||
}).setLayout(R.layout.list_item_text_button).createItem());
|
||||
}
|
||||
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map)
|
||||
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int position, boolean isChecked, int[] viewCoordinates) {
|
||||
DirectionIndicationDialogFragment fragment = new DirectionIndicationDialogFragment();
|
||||
fragment.setListener(new DirectionIndicationDialogFragment.DirectionIndicationFragmentListener() {
|
||||
@Override
|
||||
public void onMapMarkersModeChanged(boolean showDirectionEnabled) {
|
||||
updateMapMarkersMode(map);
|
||||
cm.getItem(position).setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
fragment.show(map.getSupportFragmentManager(), DirectionIndicationDialogFragment.TAG);
|
||||
return false;
|
||||
}
|
||||
}).setLayout(R.layout.list_item_text_button).createItem());
|
||||
}
|
||||
|
||||
public void updateMapMarkersMode(MapActivity mapActivity) {
|
||||
|
|
Loading…
Reference in a new issue