Refactor
This commit is contained in:
parent
075e747375
commit
204b6f8310
7 changed files with 97 additions and 120 deletions
|
@ -457,19 +457,19 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void syncGroupAsync(MarkersSyncGroup group) {
|
||||
public void syncGroupAsync(@NonNull MarkersSyncGroup group) {
|
||||
syncGroupAsync(group, true, null);
|
||||
}
|
||||
|
||||
public void syncGroupAsync(MarkersSyncGroup group, boolean enabled) {
|
||||
public void syncGroupAsync(@NonNull MarkersSyncGroup group, boolean enabled) {
|
||||
syncGroupAsync(group, enabled, null);
|
||||
}
|
||||
|
||||
public void syncGroupAsync(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) {
|
||||
public void syncGroupAsync(@NonNull MarkersSyncGroup group, @Nullable OnGroupSyncedListener 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() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -597,7 +597,13 @@ public class MapMarkersHelper {
|
|||
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;
|
||||
|
||||
for (MapMarker marker : markers) {
|
||||
|
@ -880,7 +886,7 @@ public class MapMarkersHelper {
|
|||
markersDbHelper.removeDisabledGroups();
|
||||
}
|
||||
|
||||
public void updateGroupDisabled(MapMarkersGroup group, boolean disabled) {
|
||||
public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
|
||||
String id = group.getGroupKey();
|
||||
if (id != null) {
|
||||
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();
|
||||
for (MapMarker marker : groupMarkers) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group,
|
||||
boolean enabled, List<FavouritePoint> favouritePoints, List<WptPt> wptPts) {
|
||||
private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group,
|
||||
boolean enabled, @Nullable List<FavouritePoint> favouritePoints, @Nullable List<WptPt> wptPts) {
|
||||
if (points.size() > 0) {
|
||||
int colorIndex = -1;
|
||||
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<>();
|
||||
for (int i = 0; i < markers.size(); i++) {
|
||||
MapMarkersGroup group = addMarkerToGroup(markers.get(i));
|
||||
|
@ -1227,7 +1233,7 @@ public class MapMarkersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
private MapMarkersGroup createMapMarkerGroup(MapMarker marker) {
|
||||
private MapMarkersGroup createMapMarkerGroup(@NonNull MapMarker marker) {
|
||||
MapMarkersGroup group = new MapMarkersGroup();
|
||||
if (marker.groupName != null) {
|
||||
group.setName(marker.groupName);
|
||||
|
@ -1246,7 +1252,7 @@ public class MapMarkersHelper {
|
|||
return group;
|
||||
}
|
||||
|
||||
private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) {
|
||||
private void createHeaderAndHistoryButtonInGroup(@NonNull MapMarkersGroup group) {
|
||||
if (group.getName() != null) {
|
||||
GroupHeader header = new GroupHeader();
|
||||
int type = group.getType();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
public boolean isButtonWaypointEnabled() {
|
||||
if (menuController != null) {
|
||||
return menuController.isWaypointButtonEnabled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void acquireIcons() {
|
||||
super.acquireIcons();
|
||||
if (menuController != null) {
|
||||
|
|
|
@ -462,16 +462,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
|
||||
buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId()));
|
||||
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode);
|
||||
boolean shouldDeactivateMarkerButton = shouldDeactivateMarkerButton(menu.getObject());
|
||||
if (shouldDeactivateMarkerButton) {
|
||||
deactivate(buttonWaypoint);
|
||||
} else {
|
||||
if (menu.isButtonWaypointEnabled()) {
|
||||
buttonWaypoint.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
menu.buttonWaypointPressed();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
deactivate(buttonWaypoint);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
view.setEnabled(false);
|
||||
view.setAlpha(0.5f);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.mapcontextmenu;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -23,6 +24,7 @@ import net.osmand.map.OsmandRegions;
|
|||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -95,6 +97,7 @@ public abstract class MenuController extends BaseMenuController {
|
|||
private PointDescription pointDescription;
|
||||
private LatLon latLon;
|
||||
private boolean active;
|
||||
private Drawable showOnTopBarIcon;
|
||||
|
||||
protected TitleButtonController leftTitleButtonController;
|
||||
protected TitleButtonController rightTitleButtonController;
|
||||
|
@ -311,6 +314,10 @@ public abstract class MenuController extends BaseMenuController {
|
|||
this.currentMenuState = currentMenuState;
|
||||
}
|
||||
|
||||
public void setLeftTitleButtonController(TitleButtonController leftDownloadButtonController) {
|
||||
this.leftTitleButtonController = leftDownloadButtonController;
|
||||
}
|
||||
|
||||
public TitleButtonController getLeftTitleButtonController() {
|
||||
return leftTitleButtonController;
|
||||
}
|
||||
|
@ -323,6 +330,10 @@ public abstract class MenuController extends BaseMenuController {
|
|||
return topRightTitleButtonController;
|
||||
}
|
||||
|
||||
public void setLeftSubtitleButtonController(TitleButtonController leftSubtitleButtonController) {
|
||||
this.leftSubtitleButtonController = leftSubtitleButtonController;
|
||||
}
|
||||
|
||||
public TitleButtonController getLeftSubtitleButtonController() {
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -33,26 +33,7 @@ public class FavouritePointMenuController extends MenuController {
|
|||
final MapMarker mapMarker = markersHelper.getMapMarker(fav);
|
||||
|
||||
if (mapMarker != null) {
|
||||
leftTitleButtonController = new TitleButtonController() {
|
||||
@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();
|
||||
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +79,11 @@ public class FavouritePointMenuController extends MenuController {
|
|||
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWaypointButtonEnabled() {
|
||||
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(fav) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getSecondLineTypeIcon() {
|
||||
return getIcon(R.drawable.map_small_group);
|
||||
|
@ -144,12 +130,4 @@ public class FavouritePointMenuController extends MenuController {
|
|||
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});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,36 +22,7 @@ public class MapMarkerMenuController extends MenuController {
|
|||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
this.mapMarker = mapMarker;
|
||||
builder.setShowNearestWiki(true);
|
||||
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
|
||||
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});
|
||||
createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,4 +75,31 @@ public class MapMarkerMenuController extends MenuController {
|
|||
public int getWaypointActionStringId() {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -28,26 +28,7 @@ public class WptPtMenuController extends MenuController {
|
|||
final MapMarker mapMarker = markersHelper.getMapMarker(wpt);
|
||||
|
||||
if (mapMarker != null) {
|
||||
leftTitleButtonController = new TitleButtonController() {
|
||||
@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();
|
||||
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker, getShowOnTopBarIcon());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +81,11 @@ public class WptPtMenuController extends MenuController {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWaypointButtonEnabled() {
|
||||
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(wpt) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
return wpt.category != null ? wpt.category : "";
|
||||
|
@ -109,12 +95,4 @@ public class WptPtMenuController extends MenuController {
|
|||
public String getCommonTypeStr() {
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue