Refactoring continue
This commit is contained in:
parent
760950ceb7
commit
908544e560
26 changed files with 176 additions and 230 deletions
|
@ -11,7 +11,6 @@ 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.quickaction.actions.AddPOIAction;
|
||||
|
||||
public class TakeAudioNoteAction extends QuickAction {
|
||||
|
||||
|
|
|
@ -31,13 +31,9 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.quickaction.CreateEditActionDialog;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.quickaction.SwitchableAction;
|
||||
import net.osmand.plus.quickaction.actions.MapOverlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MapSourceAction;
|
||||
import net.osmand.plus.quickaction.actions.MapStyleAction;
|
||||
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
|
||||
|
@ -71,7 +67,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
|
||||
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
|
||||
action = quickActionRegistry.getQuickAction(id);
|
||||
action = QuickActionFactory.produceAction(action);
|
||||
action = QuickActionRegistry.produceAction(action);
|
||||
if (action == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -79,22 +75,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
if (savedInstanceState != null) {
|
||||
selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
|
||||
} else {
|
||||
if (action instanceof MapStyleAction) {
|
||||
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
if (current != null) {
|
||||
selectedItem = current.getName();
|
||||
} else {
|
||||
selectedItem = RendererRegistry.DEFAULT_RENDER;
|
||||
}
|
||||
} else if (action instanceof MapSourceAction) {
|
||||
selectedItem = settings.MAP_ONLINE_DATA.get()
|
||||
? settings.MAP_TILE_SOURCES.get()
|
||||
: MapSourceAction.LAYER_OSM_VECTOR;
|
||||
} else if (action instanceof MapUnderlayAction) {
|
||||
selectedItem = settings.MAP_UNDERLAY.get();
|
||||
} else if (action instanceof MapOverlayAction) {
|
||||
selectedItem = settings.MAP_OVERLAY.get();
|
||||
}
|
||||
selectedItem = ((SwitchableAction<?>) action).getSelectedItem(app);
|
||||
}
|
||||
rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId());
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -40,13 +40,6 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.EditPoiData;
|
||||
import net.osmand.plus.osmedit.EditPoiDialogFragment;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapLocalUtil;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapUtil;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
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;
|
|
@ -42,9 +42,6 @@ import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
|
|||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.osmedit.OsmPoint.Action;
|
||||
import net.osmand.plus.quickaction.QuickActionType;
|
||||
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.AddPOIAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -9,8 +9,6 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionType;
|
||||
|
|
@ -11,7 +11,6 @@ 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.quickaction.actions.AddOSMBugAction;
|
||||
|
||||
public class ParkingAction extends QuickAction {
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
|||
.getQuickActions();
|
||||
|
||||
View root = UiUtilities.getInflater(getActivity(), !isLightContent).inflate(R.layout.quick_action_add_dialog, container, false);
|
||||
Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders(active));
|
||||
Adapter adapter = new Adapter(QuickActionRegistry.produceTypeActionsListWithHeaders(active));
|
||||
|
||||
TextView tvTitle = root.findViewById(R.id.tvTitle);
|
||||
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
|
||||
|
@ -161,7 +161,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type);
|
||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
|
||||
dialog.show(getFragmentManager(), CreateEditActionDialog.TAG);
|
||||
|
||||
dismiss();
|
||||
|
|
|
@ -123,8 +123,8 @@ public class CreateEditActionDialog extends DialogFragment {
|
|||
? isNew = actionId == 0
|
||||
: savedInstanceState.getBoolean(KEY_ACTION_IS_NEW);
|
||||
|
||||
action = QuickActionFactory.produceAction(isNew
|
||||
? QuickActionFactory.newActionByType(type)
|
||||
action = QuickActionRegistry.produceAction(isNew
|
||||
? QuickActionRegistry.newActionByType(type)
|
||||
: quickActionRegistry.getQuickAction(actionId));
|
||||
|
||||
setupToolbar(view);
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.osmand.plus.quickaction;
|
|||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
|
@ -158,6 +158,6 @@ public class QuickAction {
|
|||
}
|
||||
|
||||
public boolean hasCustomName(Context context) {
|
||||
return !getName(context).equals(context.getString(getDefaultName()));
|
||||
return !getName(context).equals(getDefaultName(context));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.audionotes.TakeAudioNoteAction;
|
||||
import net.osmand.plus.audionotes.TakePhotoNoteAction;
|
||||
import net.osmand.plus.audionotes.TakeVideoNoteAction;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.parkingpoint.ParkingAction;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.AddPOIAction;
|
||||
import net.osmand.plus.quickaction.actions.ContourLinesAction;
|
||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||
import net.osmand.plus.quickaction.actions.FavoriteAction;
|
||||
import net.osmand.plus.quickaction.actions.GPXAction;
|
||||
import net.osmand.plus.quickaction.actions.HillshadeAction;
|
||||
import net.osmand.plus.quickaction.actions.MapOverlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MapSourceAction;
|
||||
import net.osmand.plus.quickaction.actions.MapStyleAction;
|
||||
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MarkerAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
|
||||
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
|
||||
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
|
||||
import net.osmand.plus.quickaction.actions.NavStartStopAction;
|
||||
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
||||
import net.osmand.plus.quickaction.actions.NewAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class QuickActionFactory {
|
||||
|
||||
public static final QuickActionType TYPE_ADD_ITEMS = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_create_items).category(QuickActionType.CREATE_CATEGORY);
|
||||
public static final QuickActionType TYPE_CONFIGURE_MAP = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_configure_map).category(QuickActionType.CONFIGURE_MAP);
|
||||
public static final QuickActionType TYPE_NAVIGATION = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_navigation).category(QuickActionType.NAVIGATION);
|
||||
)
|
||||
public String quickActionListToString(List<QuickAction> quickActions) {
|
||||
return new Gson().toJson(quickActions);
|
||||
}
|
||||
|
||||
public List<QuickAction> parseActiveActionsList(String json) {
|
||||
Type type = new TypeToken<List<QuickAction>>() {
|
||||
}.getType();
|
||||
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
|
||||
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
||||
}
|
||||
|
||||
|
||||
public static List<QuickActionType> getActionTypes() {
|
||||
List<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(NewAction.TYPE);
|
||||
quickActionTypes.add(FavoriteAction.TYPE);
|
||||
quickActionTypes.add(GPXAction.TYPE);
|
||||
quickActionTypes.add(MarkerAction.TYPE);
|
||||
// configure map
|
||||
quickActionTypes.add(ShowHideFavoritesAction.TYPE);
|
||||
quickActionTypes.add(ShowHideGpxTracksAction.TYPE);
|
||||
quickActionTypes.add(ShowHidePoiAction.TYPE);
|
||||
quickActionTypes.add(MapStyleAction.TYPE);
|
||||
quickActionTypes.add(DayNightModeAction.TYPE);
|
||||
// navigation
|
||||
quickActionTypes.add(NavVoiceAction.TYPE);
|
||||
quickActionTypes.add(NavDirectionsFromAction.TYPE);
|
||||
quickActionTypes.add(NavAddDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAddFirstIntermediateAction.TYPE);
|
||||
quickActionTypes.add(NavReplaceDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAutoZoomMapAction.TYPE);
|
||||
quickActionTypes.add(NavStartStopAction.TYPE);
|
||||
quickActionTypes.add(NavResumePauseAction.TYPE);
|
||||
OsmandPlugin.registerQuickActionTypesPlugins(quickActionTypes);
|
||||
return quickActionTypes;
|
||||
}
|
||||
|
||||
public static List<QuickActionType> produceTypeActionsListWithHeaders(List<QuickAction> active) {
|
||||
List<QuickActionType> quickActions = new ArrayList<>();
|
||||
List<QuickActionType> tps = getActionTypes();
|
||||
filterQuickActions(active, tps, TYPE_ADD_ITEMS, quickActions);
|
||||
filterQuickActions(active, tps, TYPE_CONFIGURE_MAP, quickActions);
|
||||
filterQuickActions(active, tps, TYPE_NAVIGATION, quickActions);
|
||||
return quickActions;
|
||||
}
|
||||
|
||||
private static void filterQuickActions(List<QuickAction> active, List<QuickActionType> allTypes, QuickActionType filter,
|
||||
List<QuickActionType> result) {
|
||||
result.add(filter);
|
||||
for(QuickActionType t : allTypes) {
|
||||
if(t.getCategory() == filter.getCategory()) {
|
||||
if(t.isActionEditable()) {
|
||||
boolean instanceInList = false;
|
||||
for(QuickAction qa : active) {
|
||||
if(qa.getActionType().getId() == t.getId()) {
|
||||
instanceInList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!instanceInList) {
|
||||
result.add(t);
|
||||
}
|
||||
} else {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static QuickAction newActionByType(int type) {
|
||||
for(QuickActionType t : getActionTypes()) {
|
||||
if(t.getId() == type) {
|
||||
return t.createNew();
|
||||
}
|
||||
}
|
||||
return new QuickAction();
|
||||
}
|
||||
|
||||
public static QuickAction produceAction(QuickAction quickAction) {
|
||||
return quickAction.getActionType().createNew(quickAction);
|
||||
}
|
||||
|
||||
}
|
|
@ -220,7 +220,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
|
|||
@Override
|
||||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
||||
int viewType = getItemViewType(position);
|
||||
final QuickAction item = QuickActionFactory.produceAction(itemsList.get(position));
|
||||
final QuickAction item = QuickActionRegistry.produceAction(itemsList.get(position));
|
||||
|
||||
if (viewType == SCREEN_ITEM_TYPE) {
|
||||
final QuickActionItemVH itemVH = (QuickActionItemVH) holder;
|
||||
|
|
|
@ -7,22 +7,24 @@ import com.google.gson.reflect.TypeToken;
|
|||
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.audionotes.TakeAudioNoteAction;
|
||||
import net.osmand.plus.audionotes.TakePhotoNoteAction;
|
||||
import net.osmand.plus.audionotes.TakeVideoNoteAction;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.parkingpoint.ParkingAction;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.AddPOIAction;
|
||||
import net.osmand.plus.quickaction.actions.ContourLinesAction;
|
||||
import net.osmand.plus.quickaction.actions.HillshadeAction;
|
||||
import net.osmand.plus.quickaction.actions.MapSourceAction;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||
import net.osmand.plus.quickaction.actions.FavoriteAction;
|
||||
import net.osmand.plus.quickaction.actions.GPXAction;
|
||||
import net.osmand.plus.quickaction.actions.MapStyleAction;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.quickaction.actions.MarkerAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
|
||||
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
|
||||
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
|
||||
import net.osmand.plus.quickaction.actions.NavStartStopAction;
|
||||
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
||||
import net.osmand.plus.quickaction.actions.NewAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
@ -43,7 +45,14 @@ public class QuickActionRegistry {
|
|||
void onActionsUpdated();
|
||||
}
|
||||
|
||||
private final QuickActionFactory factory;
|
||||
public static final QuickActionType TYPE_ADD_ITEMS = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_create_items).category(QuickActionType.CREATE_CATEGORY);
|
||||
public static final QuickActionType TYPE_CONFIGURE_MAP = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_configure_map).category(QuickActionType.CONFIGURE_MAP);
|
||||
public static final QuickActionType TYPE_NAVIGATION = new QuickActionType(0, "").
|
||||
nameRes(R.string.quick_action_add_navigation).category(QuickActionType.NAVIGATION);
|
||||
|
||||
|
||||
private final OsmandSettings settings;
|
||||
|
||||
private final List<QuickAction> quickActions;
|
||||
|
@ -53,10 +62,8 @@ public class QuickActionRegistry {
|
|||
|
||||
public QuickActionRegistry(OsmandSettings settings) {
|
||||
|
||||
this.factory = new QuickActionFactory();
|
||||
this.settings = settings;
|
||||
|
||||
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
quickActions = parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
|
||||
}
|
||||
|
||||
|
@ -75,7 +82,7 @@ public class QuickActionRegistry {
|
|||
public List<QuickAction> getFilteredQuickActions() {
|
||||
List<QuickAction> actions = getQuickActions();
|
||||
Set<Integer> activeTypesInts = new TreeSet<>();
|
||||
for (QuickActionType activeType : QuickActionFactory.getActionTypes()) {
|
||||
for (QuickActionType activeType : getActionTypes()) {
|
||||
activeTypesInts.add(activeType.getId());
|
||||
}
|
||||
List<QuickAction> filteredActions = new ArrayList<>();
|
||||
|
@ -89,7 +96,7 @@ public class QuickActionRegistry {
|
|||
|
||||
public void addQuickAction(QuickAction action){
|
||||
quickActions.add(action);
|
||||
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
|
||||
settings.QUICK_ACTION_LIST.set(quickActionListToString(quickActions));
|
||||
}
|
||||
|
||||
public void deleteQuickAction(QuickAction action){
|
||||
|
@ -97,7 +104,7 @@ public class QuickActionRegistry {
|
|||
if (index >= 0) {
|
||||
quickActions.remove(index);
|
||||
}
|
||||
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
|
||||
settings.QUICK_ACTION_LIST.set(quickActionListToString(quickActions));
|
||||
}
|
||||
|
||||
public void deleteQuickAction(int id){
|
||||
|
@ -111,7 +118,7 @@ public class QuickActionRegistry {
|
|||
if (index >= 0) {
|
||||
quickActions.remove(index);
|
||||
}
|
||||
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
|
||||
settings.QUICK_ACTION_LIST.set(quickActionListToString(quickActions));
|
||||
}
|
||||
|
||||
public void updateQuickAction(QuickAction action){
|
||||
|
@ -119,13 +126,13 @@ public class QuickActionRegistry {
|
|||
if (index >= 0) {
|
||||
quickActions.set(index, action);
|
||||
}
|
||||
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
|
||||
settings.QUICK_ACTION_LIST.set(quickActionListToString(quickActions));
|
||||
}
|
||||
|
||||
public void updateQuickActions(List<QuickAction> quickActions){
|
||||
this.quickActions.clear();
|
||||
this.quickActions.addAll(quickActions);
|
||||
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(this.quickActions));
|
||||
settings.QUICK_ACTION_LIST.set(quickActionListToString(this.quickActions));
|
||||
}
|
||||
|
||||
public QuickAction getQuickAction(long id){
|
||||
|
@ -177,4 +184,91 @@ public class QuickActionRegistry {
|
|||
|
||||
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String quickActionListToString(List<QuickAction> quickActions) {
|
||||
// FIXME backward compatibiltiy
|
||||
return new Gson().toJson(quickActions);
|
||||
}
|
||||
|
||||
public List<QuickAction> parseActiveActionsList(String json) {
|
||||
// FIXME backward compatibiltiy
|
||||
Type type = new TypeToken<List<QuickAction>>() {
|
||||
}.getType();
|
||||
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
|
||||
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
||||
}
|
||||
|
||||
|
||||
public static List<QuickActionType> getActionTypes() {
|
||||
List<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(NewAction.TYPE);
|
||||
quickActionTypes.add(FavoriteAction.TYPE);
|
||||
quickActionTypes.add(GPXAction.TYPE);
|
||||
quickActionTypes.add(MarkerAction.TYPE);
|
||||
// configure map
|
||||
quickActionTypes.add(ShowHideFavoritesAction.TYPE);
|
||||
quickActionTypes.add(ShowHideGpxTracksAction.TYPE);
|
||||
quickActionTypes.add(ShowHidePoiAction.TYPE);
|
||||
quickActionTypes.add(MapStyleAction.TYPE);
|
||||
quickActionTypes.add(DayNightModeAction.TYPE);
|
||||
// navigation
|
||||
quickActionTypes.add(NavVoiceAction.TYPE);
|
||||
quickActionTypes.add(NavDirectionsFromAction.TYPE);
|
||||
quickActionTypes.add(NavAddDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAddFirstIntermediateAction.TYPE);
|
||||
quickActionTypes.add(NavReplaceDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAutoZoomMapAction.TYPE);
|
||||
quickActionTypes.add(NavStartStopAction.TYPE);
|
||||
quickActionTypes.add(NavResumePauseAction.TYPE);
|
||||
OsmandPlugin.registerQuickActionTypesPlugins(quickActionTypes);
|
||||
return quickActionTypes;
|
||||
}
|
||||
|
||||
public static List<QuickActionType> produceTypeActionsListWithHeaders(List<QuickAction> active) {
|
||||
List<QuickActionType> quickActions = new ArrayList<>();
|
||||
List<QuickActionType> tps = getActionTypes();
|
||||
filterQuickActions(active, tps, TYPE_ADD_ITEMS, quickActions);
|
||||
filterQuickActions(active, tps, TYPE_CONFIGURE_MAP, quickActions);
|
||||
filterQuickActions(active, tps, TYPE_NAVIGATION, quickActions);
|
||||
return quickActions;
|
||||
}
|
||||
|
||||
private static void filterQuickActions(List<QuickAction> active, List<QuickActionType> allTypes, QuickActionType filter,
|
||||
List<QuickActionType> result) {
|
||||
result.add(filter);
|
||||
for(QuickActionType t : allTypes) {
|
||||
if(t.getCategory() == filter.getCategory()) {
|
||||
if(t.isActionEditable()) {
|
||||
boolean instanceInList = false;
|
||||
for(QuickAction qa : active) {
|
||||
if(qa.getActionType().getId() == t.getId()) {
|
||||
instanceInList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!instanceInList) {
|
||||
result.add(t);
|
||||
}
|
||||
} else {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static QuickAction newActionByType(int type) {
|
||||
for(QuickActionType t : getActionTypes()) {
|
||||
if(t.getId() == type) {
|
||||
return t.createNew();
|
||||
}
|
||||
}
|
||||
return new QuickAction();
|
||||
}
|
||||
|
||||
public static QuickAction produceAction(QuickAction quickAction) {
|
||||
return quickAction.getActionType().createNew(quickAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
|
||||
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
|
||||
|
||||
final QuickAction action = QuickActionFactory.produceAction(
|
||||
final QuickAction action = QuickActionRegistry.produceAction(
|
||||
actions.get(i + (position * ELEMENT_PER_PAGE)));
|
||||
|
||||
((ImageView) view.findViewById(imageView))
|
||||
|
|
|
@ -18,6 +18,7 @@ import androidx.fragment.app.FragmentManager;
|
|||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
|
||||
|
@ -118,6 +119,10 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
|||
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
|
||||
}
|
||||
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
|
||||
|
||||
private List<T> itemsList = new ArrayList<>();
|
||||
|
|
|
@ -48,6 +48,16 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
super(quickAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
if (current != null) {
|
||||
return current.getName();
|
||||
} else {
|
||||
return RendererRegistry.DEFAULT_RENDER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MapActivity activity) {
|
||||
List<String> mapStyles = getFilteredStyles();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.rastermaps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -58,6 +58,11 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return app.getSettings().MAP_UNDERLAY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.rastermaps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -59,6 +59,11 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return app.getSettings().MAP_OVERLAY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.rastermaps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -58,6 +58,13 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
|||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return app.getSettings().MAP_ONLINE_DATA.get()
|
||||
? app.getSettings().MAP_TILE_SOURCES.get()
|
||||
: MapSourceAction.LAYER_OSM_VECTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
|
@ -46,9 +46,6 @@ import net.osmand.plus.activities.MapActivityLayers;
|
|||
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
||||
import net.osmand.plus.dialogs.RasterMapMenu;
|
||||
import net.osmand.plus.quickaction.QuickActionType;
|
||||
import net.osmand.plus.quickaction.actions.MapOverlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MapSourceAction;
|
||||
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
|
|
@ -39,7 +39,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
|||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
|
||||
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
|
||||
|
||||
|
@ -218,8 +218,9 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
private Map<Type, List<?>> getAdditionalData() {
|
||||
Map<Type, List<?>> dataList = new HashMap<>();
|
||||
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> actionsList = factory.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get());
|
||||
|
||||
QuickActionRegistry registry = app.getQuickActionRegistry();
|
||||
List<QuickAction> actionsList = registry.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get());
|
||||
if (!actionsList.isEmpty()) {
|
||||
dataList.put(Type.QUICK_ACTIONS, actionsList);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.srtmplugin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
|
@ -1,4 +1,4 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
package net.osmand.plus.srtmplugin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
|
@ -31,8 +31,6 @@ import net.osmand.plus.download.DownloadResources;
|
|||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.quickaction.QuickActionType;
|
||||
import net.osmand.plus.quickaction.actions.ContourLinesAction;
|
||||
import net.osmand.plus.quickaction.actions.HillshadeAction;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.render.RenderingRuleProperty;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
|
|
@ -38,7 +38,6 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
|
|||
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.quickaction.QuickActionsWidget;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
|
|
Loading…
Reference in a new issue