Refactor MapMarkerMenuController

This commit is contained in:
Alexey Kulish 2017-11-23 13:38:06 +03:00
parent ebe41d69b1
commit 6764899fd4
4 changed files with 38 additions and 57 deletions

View file

@ -1,7 +1,6 @@
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;
@ -24,7 +23,6 @@ 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;
@ -97,7 +95,6 @@ public abstract class MenuController extends BaseMenuController {
private PointDescription pointDescription;
private LatLon latLon;
private boolean active;
private Drawable showOnTopBarIcon;
protected TitleButtonController leftTitleButtonController;
protected TitleButtonController rightTitleButtonController;
@ -314,10 +311,6 @@ public abstract class MenuController extends BaseMenuController {
this.currentMenuState = currentMenuState;
}
public void setLeftTitleButtonController(TitleButtonController leftDownloadButtonController) {
this.leftTitleButtonController = leftDownloadButtonController;
}
public TitleButtonController getLeftTitleButtonController() {
return leftTitleButtonController;
}
@ -330,10 +323,6 @@ public abstract class MenuController extends BaseMenuController {
return topRightTitleButtonController;
}
public void setLeftSubtitleButtonController(TitleButtonController leftSubtitleButtonController) {
this.leftSubtitleButtonController = leftSubtitleButtonController;
}
public TitleButtonController getLeftSubtitleButtonController() {
return leftSubtitleButtonController;
}
@ -436,17 +425,6 @@ public abstract class MenuController extends BaseMenuController {
return true;
}
public 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 "";
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.app.Fragment;
import net.osmand.data.Amenity;
@ -9,7 +8,6 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
@ -31,9 +29,11 @@ public class FavouritePointMenuController extends MenuController {
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
final MapMarker mapMarker = markersHelper.getMapMarker(fav);
if (mapMarker != null) {
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker);
MapMarkerMenuController markerMenuController =
new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker);
leftTitleButtonController = markerMenuController.getLeftTitleButtonController();
leftSubtitleButtonController = markerMenuController.getLeftSubtitleButtonController();
}
}

View file

@ -22,7 +22,36 @@ public class MapMarkerMenuController extends MenuController {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
this.mapMarker = mapMarker;
builder.setShowNearestWiki(true);
createMarkerButtons(this, mapActivity, mapMarker);
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});
}
@Override
@ -75,31 +104,4 @@ 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) {
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 = menuController.getShowOnTopBarIcon();
menuController.setLeftSubtitleButtonController(leftSubtitleButtonController);
}
}

View file

@ -1,12 +1,10 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.content.ContextCompat;
import net.osmand.data.PointDescription;
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.R;
@ -28,7 +26,10 @@ public class WptPtMenuController extends MenuController {
final MapMarker mapMarker = markersHelper.getMapMarker(wpt);
if (mapMarker != null) {
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker);
MapMarkerMenuController markerMenuController =
new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker);
leftTitleButtonController = markerMenuController.getLeftTitleButtonController();
leftSubtitleButtonController = markerMenuController.getLeftSubtitleButtonController();
}
}