Refactorign continue

This commit is contained in:
Victor Shcherb 2020-03-20 17:18:12 +01:00
parent 8c4ac76b98
commit acb464e8cc
15 changed files with 102 additions and 281 deletions

View file

@ -71,6 +71,7 @@ public class QuickActionFactory {
public static List<QuickActionType> getActionTypes() {
List<QuickActionType> quickActionsTypes = new ArrayList<>();
quickActionsTypes.add(NewAction.TYPE);
quickActionsTypes.add(FavoriteAction.TYPE);
quickActionsTypes.add(GPXAction.TYPE);
quickActionsTypes.add(MarkerAction.TYPE);
@ -160,213 +161,28 @@ public class QuickActionFactory {
}
public static QuickAction newActionByType(int type) {
// FIXME
switch (type) {
case NewAction.TYPE:
return new NewAction();
case MarkerAction.TYPE:
return new MarkerAction();
case FavoriteAction.TYPE:
return new FavoriteAction();
case ShowHideFavoritesAction.TYPE:
return new ShowHideFavoritesAction();
case ShowHidePoiAction.TYPE:
return new ShowHidePoiAction();
case GPXAction.TYPE:
return new GPXAction();
case ParkingAction.TYPE:
return new ParkingAction();
case TakeAudioNoteAction.TYPE:
return new TakeAudioNoteAction();
case TakePhotoNoteAction.TYPE:
return new TakePhotoNoteAction();
case TakeVideoNoteAction.TYPE:
return new TakeVideoNoteAction();
case NavVoiceAction.TYPE:
return new NavVoiceAction();
case ShowHideOSMBugAction.TYPE:
return new ShowHideOSMBugAction();
case AddPOIAction.TYPE:
return new AddPOIAction();
case MapStyleAction.TYPE:
return new MapStyleAction();
case MapSourceAction.TYPE:
return new MapSourceAction();
case MapOverlayAction.TYPE:
return new MapOverlayAction();
case MapUnderlayAction.TYPE:
return new MapUnderlayAction();
case NavDirectionsFromAction.TYPE:
return new NavDirectionsFromAction();
case NavAddDestinationAction.TYPE:
return new NavAddDestinationAction();
case NavAddFirstIntermediateAction.TYPE:
return new NavAddFirstIntermediateAction();
case NavReplaceDestinationAction.TYPE:
return new NavReplaceDestinationAction();
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction();
case NavStartStopAction.TYPE:
return new NavStartStopAction();
case NavResumePauseAction.TYPE:
return new NavResumePauseAction();
case DayNightModeAction.TYPE:
return new DayNightModeAction();
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction();
case ContourLinesAction.TYPE:
return new ContourLinesAction();
case HillshadeAction.TYPE:
return new HillshadeAction();
default:
return new QuickAction();
for(QuickActionType t : getActionTypes()) {
if(t.getId() == type) {
return t.createNew();
}
}
return new QuickAction();
}
public static QuickAction produceAction(QuickAction quickAction) {
// FIXME
switch (quickAction.type) {
case NewAction.TYPE:
return new NewAction(quickAction);
case MarkerAction.TYPE:
return new MarkerAction(quickAction);
case FavoriteAction.TYPE:
return new FavoriteAction(quickAction);
case ShowHideFavoritesAction.TYPE:
return new ShowHideFavoritesAction(quickAction);
case ShowHidePoiAction.TYPE:
return new ShowHidePoiAction(quickAction);
case GPXAction.TYPE:
return new GPXAction(quickAction);
case ParkingAction.TYPE:
return new ParkingAction(quickAction);
case TakeAudioNoteAction.TYPE:
return new TakeAudioNoteAction(quickAction);
case TakePhotoNoteAction.TYPE:
return new TakePhotoNoteAction(quickAction);
case TakeVideoNoteAction.TYPE:
return new TakeVideoNoteAction(quickAction);
case NavVoiceAction.TYPE:
return new NavVoiceAction(quickAction);
case ShowHideOSMBugAction.TYPE:
return new ShowHideOSMBugAction(quickAction);
case AddPOIAction.TYPE:
return new AddPOIAction(quickAction);
case MapStyleAction.TYPE:
return new MapStyleAction(quickAction);
case MapSourceAction.TYPE:
return new MapSourceAction(quickAction);
case MapOverlayAction.TYPE:
return new MapOverlayAction(quickAction);
case MapUnderlayAction.TYPE:
return new MapUnderlayAction(quickAction);
case NavDirectionsFromAction.TYPE:
return new NavDirectionsFromAction(quickAction);
case NavAddDestinationAction.TYPE:
return new NavAddDestinationAction(quickAction);
case NavAddFirstIntermediateAction.TYPE:
return new NavAddFirstIntermediateAction(quickAction);
case NavReplaceDestinationAction.TYPE:
return new NavReplaceDestinationAction(quickAction);
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction(quickAction);
case NavStartStopAction.TYPE:
return new NavStartStopAction(quickAction);
case NavResumePauseAction.TYPE:
return new NavResumePauseAction(quickAction);
case DayNightModeAction.TYPE:
return new DayNightModeAction(quickAction);
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction(quickAction);
case ContourLinesAction.TYPE:
return new ContourLinesAction(quickAction);
case HillshadeAction.TYPE:
return new HillshadeAction(quickAction);
default:
return quickAction;
}
return quickAction.getActionType().createNew(quickAction);
}
public static @DrawableRes int getActionIcon(int type) {
switch (type) {
case NewAction.TYPE:
return R.drawable.ic_action_plus;
case MarkerAction.TYPE:
return R.drawable.ic_action_flag_dark;
case FavoriteAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHideFavoritesAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHidePoiAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case GPXAction.TYPE:
return R.drawable.ic_action_flag_dark;
case ParkingAction.TYPE:
return R.drawable.ic_action_parking_dark;
@ -379,14 +195,9 @@ public class QuickActionFactory {
case TakeVideoNoteAction.TYPE:
return R.drawable.ic_action_video_dark;
case NavVoiceAction.TYPE:
return R.drawable.ic_action_volume_up;
case ShowHideOSMBugAction.TYPE:
return R.drawable.ic_action_bug_dark;
case AddPOIAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case MapStyleAction.TYPE:
return R.drawable.ic_map;
@ -400,27 +211,6 @@ public class QuickActionFactory {
case MapUnderlayAction.TYPE:
return R.drawable.ic_layer_bottom;
case NavDirectionsFromAction.TYPE:
return R.drawable.ic_action_route_direction_from_here;
case NavAddDestinationAction.TYPE:
return R.drawable.ic_action_point_add_destination;
case NavAddFirstIntermediateAction.TYPE:
return R.drawable.ic_action_intermediate;
case NavReplaceDestinationAction.TYPE:
return R.drawable.ic_action_point_add_destination;
case NavAutoZoomMapAction.TYPE:
return R.drawable.ic_action_search_dark;
case NavStartStopAction.TYPE:
return R.drawable.ic_action_start_navigation;
case NavResumePauseAction.TYPE:
return R.drawable.ic_play_dark;
case DayNightModeAction.TYPE:
return R.drawable.ic_action_map_day;
@ -442,24 +232,12 @@ public class QuickActionFactory {
switch (type) {
case NewAction.TYPE:
return R.string.quick_action_new_action;
case MarkerAction.TYPE:
return R.string.quick_action_add_marker;
case FavoriteAction.TYPE:
return R.string.quick_action_add_favorite;
case ShowHideFavoritesAction.TYPE:
return R.string.quick_action_showhide_favorites_title;
case ShowHidePoiAction.TYPE:
return R.string.quick_action_showhide_poi_title;
case GPXAction.TYPE:
return R.string.quick_action_add_gpx;
case ParkingAction.TYPE:
return R.string.quick_action_add_parking;
@ -472,14 +250,9 @@ public class QuickActionFactory {
case TakeVideoNoteAction.TYPE:
return R.string.quick_action_take_video_note;
case NavVoiceAction.TYPE:
return R.string.quick_action_navigation_voice;
case ShowHideOSMBugAction.TYPE:
return R.string.quick_action_showhide_osmbugs_title;
case AddPOIAction.TYPE:
return R.string.quick_action_add_poi;
case MapStyleAction.TYPE:
return R.string.quick_action_map_style;
@ -496,27 +269,6 @@ public class QuickActionFactory {
case DayNightModeAction.TYPE:
return R.string.quick_action_day_night_switch_mode;
case NavDirectionsFromAction.TYPE:
return R.string.context_menu_item_directions_from;
case NavAddDestinationAction.TYPE:
return R.string.quick_action_add_destination;
case NavAddFirstIntermediateAction.TYPE:
return R.string.quick_action_add_first_intermediate;
case NavReplaceDestinationAction.TYPE:
return R.string.quick_action_replace_destination;
case NavAutoZoomMapAction.TYPE:
return R.string.quick_action_auto_zoom;
case NavStartStopAction.TYPE:
return R.string.quick_action_start_stop_navigation;
case NavResumePauseAction.TYPE:
return R.string.quick_action_resume_pause_navigation;
case ShowHideGpxTracksAction.TYPE:
return R.string.quick_action_show_hide_gpx_tracks;
@ -534,24 +286,13 @@ public class QuickActionFactory {
public static boolean isActionEditable(int type) {
switch (type) {
case NewAction.TYPE:
case MarkerAction.TYPE:
case ShowHideFavoritesAction.TYPE:
case ShowHidePoiAction.TYPE:
case ParkingAction.TYPE:
case TakeAudioNoteAction.TYPE:
case TakePhotoNoteAction.TYPE:
case TakeVideoNoteAction.TYPE:
case NavVoiceAction.TYPE:
case NavDirectionsFromAction.TYPE:
case NavAddDestinationAction.TYPE:
case NavAddFirstIntermediateAction.TYPE:
case NavReplaceDestinationAction.TYPE:
case NavAutoZoomMapAction.TYPE:
case ShowHideOSMBugAction.TYPE:
case NavStartStopAction.TYPE:
case NavResumePauseAction.TYPE:
case DayNightModeAction.TYPE:
case ShowHideGpxTracksAction.TYPE:
case ContourLinesAction.TYPE:

View file

@ -3,6 +3,8 @@ package net.osmand.plus.quickaction;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import java.lang.reflect.InvocationTargetException;
public class QuickActionType {
public static final int CREATE_CATEGORY = 0;
@ -26,6 +28,7 @@ public class QuickActionType {
this.id = id;
this.stringId = stringId;
this.cl = cl;
this.actionEditable = cl != null;
}
public QuickActionType nameRes(int nameRes) {
@ -43,8 +46,8 @@ public class QuickActionType {
return this;
}
public QuickActionType editable() {
actionEditable = true;
public QuickActionType nonEditable() {
actionEditable = false;
return this;
}
@ -64,6 +67,24 @@ public class QuickActionType {
}
}
public QuickAction createNew(QuickAction q) {
if(cl != null) {
try {
return cl.getConstructor(QuickAction.class).newInstance(q);
} catch (InstantiationException e) {
throw new UnsupportedOperationException(e);
} catch (IllegalAccessException e) {
throw new UnsupportedOperationException(e);
} catch (NoSuchMethodException e) {
throw new UnsupportedOperationException(e);
} catch (InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
} else {
return new QuickAction(q);
}
}
public int getId() {
return id;
}

View file

@ -50,6 +50,7 @@ import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.quickaction.CreateEditActionDialog;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms;
@ -66,7 +67,10 @@ import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet;
import static net.osmand.plus.osmedit.EditPoiData.POI_TYPE_TAG;
public class AddPOIAction extends QuickAction {
public static final int TYPE = 13;
public static final QuickActionType TYPE = new QuickActionType(13,
"osmpoi.add", AddPOIAction.class).
nameRes(R.string.quick_action_add_poi).iconRes(R.drawable.ic_action_gabout_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_TAG = "key_tag";
public static final String KEY_DIALOG = "dialog";

View file

@ -23,12 +23,16 @@ import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
public class FavoriteAction extends QuickAction {
public static final int TYPE = 3;
public static final QuickActionType TYPE = new QuickActionType(3,
"fav.add", FavoriteAction.class).
nameRes(R.string.quick_action_add_favorite).iconRes(R.drawable.ic_action_fav_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_NAME = "name";
public static final String KEY_DIALOG = "dialog";
public static final String KEY_CATEGORY_NAME = "category_name";

View file

@ -17,11 +17,15 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
public class GPXAction extends QuickAction {
public static final int TYPE = 6;
public static final QuickActionType TYPE = new QuickActionType(6,
"gpx.add", GPXAction.class).
nameRes(R.string.quick_action_add_gpx).iconRes(R.drawable.ic_action_flag_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_NAME = "name";
public static final String KEY_DIALOG = "dialog";

View file

@ -10,10 +10,15 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class MarkerAction extends QuickAction {
public static final int TYPE = 2;
public static final QuickActionType TYPE = new QuickActionType(2,
"marker.add", MarkerAction.class).
nameRes(R.string.quick_action_add_marker).iconRes(R.drawable.ic_action_flag_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public MarkerAction() {
super(TYPE);

View file

@ -9,10 +9,15 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAddDestinationAction extends QuickAction {
public static final int TYPE = 20;
public static final QuickActionType TYPE = new QuickActionType(20,
"nav.destination.add", NavAddDestinationAction.class).
nameRes(R.string.quick_action_add_destination).iconRes(R.drawable.ic_action_point_add_destination).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAddDestinationAction() {
super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAddFirstIntermediateAction extends QuickAction {
public static final int TYPE = 22;
public static final QuickActionType TYPE = new QuickActionType(22,
"nav.intermediate.add", NavAddFirstIntermediateAction.class).
nameRes(R.string.quick_action_add_first_intermediate).iconRes(R.drawable.ic_action_intermediate).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAddFirstIntermediateAction() {
super(TYPE);

View file

@ -11,10 +11,15 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAutoZoomMapAction extends QuickAction {
public static final int TYPE = 23;
public static final QuickActionType TYPE = new QuickActionType(23,
"nav.autozoom", NavAutoZoomMapAction.class).
nameRes(R.string.quick_action_auto_zoom).iconRes(R.drawable.ic_action_search_dark).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAutoZoomMapAction() {
super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavDirectionsFromAction extends QuickAction {
public static final int TYPE = 19;
public static final QuickActionType TYPE = new QuickActionType(19,
"nav.directions", NavDirectionsFromAction.class).
nameRes(R.string.context_menu_item_directions_from).iconRes(R.drawable.ic_action_route_direction_from_here).nonEditable().
category(QuickActionType.NAVIGATION);
public NavDirectionsFromAction() {
super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavReplaceDestinationAction extends QuickAction {
public static final int TYPE = 21;
public static final QuickActionType TYPE = new QuickActionType(21,
"nav.destination.replace", NavReplaceDestinationAction.class).
nameRes(R.string.quick_action_replace_destination).iconRes(R.drawable.ic_action_point_add_destination).nonEditable().
category(QuickActionType.NAVIGATION);
public NavReplaceDestinationAction() {
super(TYPE);

View file

@ -10,11 +10,16 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.routing.RoutingHelper;
public class NavResumePauseAction extends QuickAction {
public static final int TYPE = 26;
public static final QuickActionType TYPE = new QuickActionType(26,
"nav.resumepause", NavResumePauseAction .class).
nameRes(R.string.quick_action_resume_pause_navigation).iconRes(R.drawable.ic_play_dark).nonEditable().
category(QuickActionType.NAVIGATION);
public NavResumePauseAction() {
super(TYPE);

View file

@ -12,12 +12,18 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.routing.RoutingHelper;
public class NavStartStopAction extends QuickAction {
public static final int TYPE = 25;
private static final String KEY_DIALOG = "dialog";
public static final QuickActionType TYPE = new QuickActionType(25,
"nav.startstop", NavStartStopAction .class).
nameRes(R.string.quick_action_start_stop_navigation).iconRes(R.drawable.ic_action_start_navigation).nonEditable().
category(QuickActionType.NAVIGATION);
public NavStartStopAction() {
super(TYPE);

View file

@ -9,9 +9,13 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavVoiceAction extends QuickAction {
public static final int TYPE = 11;
public static final QuickActionType TYPE = new QuickActionType(11,
"nav.voice", NavVoiceAction.class).
nameRes(R.string.quick_action_navigation_voice).iconRes(R.drawable.ic_action_volume_up).nonEditable().
category(QuickActionType.NAVIGATION);
public NavVoiceAction() {
super(TYPE);

View file

@ -2,13 +2,18 @@ package net.osmand.plus.quickaction.actions;
import android.view.ViewGroup;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.AddQuickActionDialog;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NewAction extends QuickAction {
public static final int TYPE = 1;
public static final QuickActionType TYPE = new QuickActionType(1, "new",
NewAction.class).
nonEditable().iconRes(R.drawable.ic_action_plus).nameRes(R.string.quick_action_new_action);
public NewAction() {
super(TYPE);