This commit is contained in:
PavelRatushny 2017-11-22 18:13:02 +02:00
parent 075e747375
commit 204b6f8310
7 changed files with 97 additions and 120 deletions

View file

@ -457,19 +457,19 @@ public class MapMarkersHelper {
} }
} }
public void syncGroupAsync(MarkersSyncGroup group) { public void syncGroupAsync(@NonNull MarkersSyncGroup group) {
syncGroupAsync(group, true, null); syncGroupAsync(group, true, null);
} }
public void syncGroupAsync(MarkersSyncGroup group, boolean enabled) { public void syncGroupAsync(@NonNull MarkersSyncGroup group, boolean enabled) {
syncGroupAsync(group, enabled, null); syncGroupAsync(group, enabled, null);
} }
public void syncGroupAsync(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) { public void syncGroupAsync(@NonNull MarkersSyncGroup group, @Nullable OnGroupSyncedListener groupSyncedListener) {
syncGroupAsync(group, true, groupSyncedListener); syncGroupAsync(group, true, groupSyncedListener);
} }
private void syncGroupAsync(final MarkersSyncGroup group, final boolean enabled, final OnGroupSyncedListener groupSyncedListener) { private void syncGroupAsync(@NonNull final MarkersSyncGroup group, final boolean enabled, @Nullable final OnGroupSyncedListener groupSyncedListener) {
ctx.runInUIThread(new Runnable() { ctx.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -597,7 +597,13 @@ public class MapMarkersHelper {
return null; return null;
} }
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled, FavouritePoint favouritePoint, WptPt wptPt) { private void addNewMarkerIfNeeded(@NonNull MarkersSyncGroup group,
@NonNull List<MapMarker> markers,
@NonNull LatLon latLon,
@NonNull String name,
boolean enabled,
@Nullable FavouritePoint favouritePoint,
@Nullable WptPt wptPt) {
boolean exists = false; boolean exists = false;
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
@ -880,7 +886,7 @@ public class MapMarkersHelper {
markersDbHelper.removeDisabledGroups(); markersDbHelper.removeDisabledGroups();
} }
public void updateGroupDisabled(MapMarkersGroup group, boolean disabled) { public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
String id = group.getGroupKey(); String id = group.getGroupKey();
if (id != null) { if (id != null) {
markersDbHelper.updateSyncGroupDisabled(id, disabled); markersDbHelper.updateSyncGroupDisabled(id, disabled);
@ -888,7 +894,7 @@ public class MapMarkersHelper {
} }
} }
private void updateSyncGroupDisabled(MapMarkersGroup group, boolean disabled) { private void updateSyncGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
List<MapMarker> groupMarkers = group.getMarkers(); List<MapMarker> groupMarkers = group.getMarkers();
for (MapMarker marker : groupMarkers) { for (MapMarker marker : groupMarkers) {
if (marker.history) { if (marker.history) {
@ -926,20 +932,20 @@ public class MapMarkersHelper {
} }
} }
public void addMapMarker(LatLon point, PointDescription historyName) { public void addMapMarker(@NonNull LatLon point, @Nullable PointDescription historyName) {
addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true); addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true);
} }
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) { public void addMapMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
addMarkers(points, historyNames, group, true); addMarkers(points, historyNames, group, true);
} }
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, boolean enabled) { private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, boolean enabled) {
addMarkers(points, historyNames, group, enabled, null, null); addMarkers(points, historyNames, group, enabled, null, null);
} }
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group,
boolean enabled, List<FavouritePoint> favouritePoints, List<WptPt> wptPts) { boolean enabled, @Nullable List<FavouritePoint> favouritePoints, @Nullable List<WptPt> wptPts) {
if (points.size() > 0) { if (points.size() > 0) {
int colorIndex = -1; int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>(); List<MapMarker> addedMarkers = new ArrayList<>();
@ -1192,7 +1198,7 @@ public class MapMarkersHelper {
} }
} }
private void addMarkersToGroups(List<MapMarker> markers, boolean enabled) { private void addMarkersToGroups(@NonNull List<MapMarker> markers, boolean enabled) {
List<MapMarkersGroup> groups = new ArrayList<>(); List<MapMarkersGroup> groups = new ArrayList<>();
for (int i = 0; i < markers.size(); i++) { for (int i = 0; i < markers.size(); i++) {
MapMarkersGroup group = addMarkerToGroup(markers.get(i)); MapMarkersGroup group = addMarkerToGroup(markers.get(i));
@ -1227,7 +1233,7 @@ public class MapMarkersHelper {
return null; return null;
} }
private MapMarkersGroup createMapMarkerGroup(MapMarker marker) { private MapMarkersGroup createMapMarkerGroup(@NonNull MapMarker marker) {
MapMarkersGroup group = new MapMarkersGroup(); MapMarkersGroup group = new MapMarkersGroup();
if (marker.groupName != null) { if (marker.groupName != null) {
group.setName(marker.groupName); group.setName(marker.groupName);
@ -1246,7 +1252,7 @@ public class MapMarkersHelper {
return group; return group;
} }
private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) { private void createHeaderAndHistoryButtonInGroup(@NonNull MapMarkersGroup group) {
if (group.getName() != null) { if (group.getName() != null) {
GroupHeader header = new GroupHeader(); GroupHeader header = new GroupHeader();
int type = group.getType(); int type = group.getType();

View file

@ -718,6 +718,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point; ? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
} }
public boolean isButtonWaypointEnabled() {
if (menuController != null) {
return menuController.isWaypointButtonEnabled();
}
return true;
}
protected void acquireIcons() { protected void acquireIcons() {
super.acquireIcons(); super.acquireIcons();
if (menuController != null) { if (menuController != null) {

View file

@ -462,16 +462,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId())); buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId()));
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode); AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode);
boolean shouldDeactivateMarkerButton = shouldDeactivateMarkerButton(menu.getObject()); if (menu.isButtonWaypointEnabled()) {
if (shouldDeactivateMarkerButton) {
deactivate(buttonWaypoint);
} else {
buttonWaypoint.setOnClickListener(new View.OnClickListener() { buttonWaypoint.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
menu.buttonWaypointPressed(); menu.buttonWaypointPressed();
} }
}); });
} else {
deactivate(buttonWaypoint);
} }
final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button); final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button);
@ -522,21 +521,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
return view; return view;
} }
private boolean shouldDeactivateMarkerButton(Object object) {
MapMarkersHelper mapMarkersHelper = map.getApplication().getMapMarkersHelper();
boolean shouldDeactivateMarkerButton = false;
if (object instanceof WptPt) {
if (mapMarkersHelper.getMapMarker((WptPt) object) != null) {
shouldDeactivateMarkerButton = true;
}
} else if (object instanceof FavouritePoint) {
if (mapMarkersHelper.getMapMarker((FavouritePoint) object) != null) {
shouldDeactivateMarkerButton = true;
}
}
return shouldDeactivateMarkerButton;
}
private void deactivate(View view) { private void deactivate(View view) {
view.setEnabled(false); view.setEnabled(false);
view.setAlpha(0.5f); view.setAlpha(0.5f);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu; package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -23,6 +24,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -95,6 +97,7 @@ public abstract class MenuController extends BaseMenuController {
private PointDescription pointDescription; private PointDescription pointDescription;
private LatLon latLon; private LatLon latLon;
private boolean active; private boolean active;
private Drawable showOnTopBarIcon;
protected TitleButtonController leftTitleButtonController; protected TitleButtonController leftTitleButtonController;
protected TitleButtonController rightTitleButtonController; protected TitleButtonController rightTitleButtonController;
@ -311,6 +314,10 @@ public abstract class MenuController extends BaseMenuController {
this.currentMenuState = currentMenuState; this.currentMenuState = currentMenuState;
} }
public void setLeftTitleButtonController(TitleButtonController leftDownloadButtonController) {
this.leftTitleButtonController = leftDownloadButtonController;
}
public TitleButtonController getLeftTitleButtonController() { public TitleButtonController getLeftTitleButtonController() {
return leftTitleButtonController; return leftTitleButtonController;
} }
@ -323,6 +330,10 @@ public abstract class MenuController extends BaseMenuController {
return topRightTitleButtonController; return topRightTitleButtonController;
} }
public void setLeftSubtitleButtonController(TitleButtonController leftSubtitleButtonController) {
this.leftSubtitleButtonController = leftSubtitleButtonController;
}
public TitleButtonController getLeftSubtitleButtonController() { public TitleButtonController getLeftSubtitleButtonController() {
return leftSubtitleButtonController; return leftSubtitleButtonController;
} }
@ -421,6 +432,21 @@ public abstract class MenuController extends BaseMenuController {
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point; ? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
} }
public boolean isWaypointButtonEnabled() {
return true;
}
protected Drawable getShowOnTopBarIcon() {
if (showOnTopBarIcon == null) {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
showOnTopBarIcon = new LayerDrawable(new Drawable[]{background, topbar});
}
return showOnTopBarIcon;
}
public String getTypeStr() { public String getTypeStr() {
return ""; return "";
} }

View file

@ -33,26 +33,7 @@ public class FavouritePointMenuController extends MenuController {
final MapMarker mapMarker = markersHelper.getMapMarker(fav); final MapMarker mapMarker = markersHelper.getMapMarker(fav);
if (mapMarker != null) { if (mapMarker != null) {
leftTitleButtonController = new TitleButtonController() { MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
} }
} }
@ -98,6 +79,11 @@ public class FavouritePointMenuController extends MenuController {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), false); return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), false);
} }
@Override
public boolean isWaypointButtonEnabled() {
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(fav) == null;
}
@Override @Override
public Drawable getSecondLineTypeIcon() { public Drawable getSecondLineTypeIcon() {
return getIcon(R.drawable.map_small_group); return getIcon(R.drawable.map_small_group);
@ -144,12 +130,4 @@ public class FavouritePointMenuController extends MenuController {
addMyLocationToPlainItems(latLon); addMyLocationToPlainItems(latLon);
} }
} }
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
}
} }

View file

@ -22,36 +22,7 @@ public class MapMarkerMenuController extends MenuController {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
this.mapMarker = mapMarker; this.mapMarker = mapMarker;
builder.setShowNearestWiki(true); builder.setShowNearestWiki(true);
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
} }
@Override @Override
@ -104,4 +75,31 @@ public class MapMarkerMenuController extends MenuController {
public int getWaypointActionStringId() { public int getWaypointActionStringId() {
return R.string.rename_marker; return R.string.rename_marker;
} }
public static void createMarkerButtons(MenuController menuController, final MapActivity mapActivity, final MapMarker mapMarker, Drawable leftIcon) {
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
TitleButtonController leftTitleButtonController = menuController.new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
mapActivity.getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = mapActivity.getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = menuController.isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
menuController.setLeftTitleButtonController(leftTitleButtonController);
TitleButtonController leftSubtitleButtonController = menuController.new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
mapActivity.getContextMenu().close();
}
};
leftSubtitleButtonController.caption = mapActivity.getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = leftIcon;
menuController.setLeftSubtitleButtonController(leftSubtitleButtonController);
}
} }

View file

@ -28,26 +28,7 @@ public class WptPtMenuController extends MenuController {
final MapMarker mapMarker = markersHelper.getMapMarker(wpt); final MapMarker mapMarker = markersHelper.getMapMarker(wpt);
if (mapMarker != null) { if (mapMarker != null) {
leftTitleButtonController = new TitleButtonController() { MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
} }
} }
@ -100,6 +81,11 @@ public class WptPtMenuController extends MenuController {
} }
} }
@Override
public boolean isWaypointButtonEnabled() {
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(wpt) == null;
}
@Override @Override
public String getTypeStr() { public String getTypeStr() {
return wpt.category != null ? wpt.category : ""; return wpt.category != null ? wpt.category : "";
@ -109,12 +95,4 @@ public class WptPtMenuController extends MenuController {
public String getCommonTypeStr() { public String getCommonTypeStr() {
return getMapActivity().getString(R.string.gpx_wpt); return getMapActivity().getString(R.string.gpx_wpt);
} }
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
}
} }