Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-05-25 16:45:22 +02:00
commit af41c7262c

View file

@ -64,10 +64,8 @@ public class QuickActionRegistry {
} }
public List<QuickAction> getQuickActions() { public List<QuickAction> getQuickActions() {
List<QuickAction> actions = new ArrayList<>(); List<QuickAction> actions = new ArrayList<>();
actions.addAll(quickActions); actions.addAll(quickActions);
return actions; return actions;
} }
@ -77,146 +75,120 @@ public class QuickActionRegistry {
List<QuickAction> filteredActions = new ArrayList<>(); List<QuickAction> filteredActions = new ArrayList<>();
for (QuickAction action : actions) { for (QuickAction action : actions) {
boolean skip = false; boolean skip = false;
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) == null) {
if (action.type == TakeAudioNoteAction.TYPE || if (action.type == TakeAudioNoteAction.TYPE || action.type == TakePhotoNoteAction.TYPE
action.type == TakePhotoNoteAction.TYPE || || action.type == TakeVideoNoteAction.TYPE) {
action.type == TakeVideoNoteAction.TYPE) {
skip = true; skip = true;
} }
} }
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) == null) {
if (action.type == ParkingAction.TYPE) { if (action.type == ParkingAction.TYPE) {
skip = true; skip = true;
} }
} }
if (OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null) {
if (action.type == MapStyleAction.TYPE) { if (action.type == MapStyleAction.TYPE) {
if (((MapStyleAction) QuickActionFactory.produceAction(action)).getFilteredStyles().isEmpty()) { if (((MapStyleAction) QuickActionFactory.produceAction(action)).getFilteredStyles().isEmpty()) {
skip = true; skip = true;
} }
} }
} }
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
if (action.type == MapSourceAction.TYPE) { if (action.type == MapSourceAction.TYPE) {
skip = true; skip = true;
} }
} }
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) == null) {
if (action.type == AddPOIAction.TYPE) { if (action.type == AddPOIAction.TYPE) {
skip = true; skip = true;
} }
if (action.type == AddOSMBugAction.TYPE) { if (action.type == AddOSMBugAction.TYPE) {
skip = true; skip = true;
} }
} }
if (!skip) {
if (!skip) filteredActions.add(action); filteredActions.add(action);
}
} }
return filteredActions; return filteredActions;
} }
public void addQuickAction(QuickAction action){ public void addQuickAction(QuickAction action){
quickActions.add(action); quickActions.add(action);
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
} }
public void deleteQuickAction(QuickAction action){ public void deleteQuickAction(QuickAction action){
int index = quickActions.indexOf(action); int index = quickActions.indexOf(action);
if (index >= 0) {
if (index >= 0) quickActions.remove(index); quickActions.remove(index);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
} }
public void deleteQuickAction(int id){ public void deleteQuickAction(int id){
int index = -1; int index = -1;
for (QuickAction action: quickActions){ for (QuickAction action: quickActions){
if (action.id == id) {
if (action.id == id)
index = quickActions.indexOf(action); index = quickActions.indexOf(action);
} }
}
if (index >= 0) quickActions.remove(index); if (index >= 0) {
quickActions.remove(index);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
} }
public void updateQuickAction(QuickAction action){ public void updateQuickAction(QuickAction action){
int index = quickActions.indexOf(action); int index = quickActions.indexOf(action);
if (index >= 0) {
if (index >= 0) quickActions.set(index, action); quickActions.set(index, action);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
} }
public void updateQuickActions(List<QuickAction> quickActions){ public void updateQuickActions(List<QuickAction> quickActions){
this.quickActions.clear(); this.quickActions.clear();
this.quickActions.addAll(quickActions); this.quickActions.addAll(quickActions);
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(this.quickActions)); settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(this.quickActions));
} }
public QuickAction getQuickAction(long id){ public QuickAction getQuickAction(long id){
for (QuickAction action: quickActions){ for (QuickAction action: quickActions){
if (action.id == id) {
if (action.id == id) return action; return action;
}
} }
return null; return null;
} }
public boolean isNameUnique(QuickAction action, Context context){ public boolean isNameUnique(QuickAction action, Context context){
for (QuickAction a: quickActions){ for (QuickAction a: quickActions){
if (action.id != a.id) { if (action.id != a.id) {
if (action.getName(context).equals(a.getName(context))) {
if (action.getName(context).equals(a.getName(context)))
return false; return false;
} }
} }
}
return true; return true;
} }
public QuickAction generateUniqueName(QuickAction action, Context context) { public QuickAction generateUniqueName(QuickAction action, Context context) {
int number = 0; int number = 0;
String name = action.getName(context); String name = action.getName(context);
while (true) { while (true) {
number++; number++;
action.setName(name + " (" + number + ")"); action.setName(name + " (" + number + ")");
if (isNameUnique(action, context)) {
if (isNameUnique(action, context)) return action; return action;
}
} }
} }