Merge pull request #5554 from osmandapp/QuickActionsImprovements
Quick actions improvements
This commit is contained in:
commit
3ca22f8ec3
6 changed files with 66 additions and 16 deletions
|
@ -179,7 +179,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
||||||
List<String> stylesList = mapStyleAction.getFilteredStyles();
|
List<String> stylesList = mapStyleAction.getFilteredStyles();
|
||||||
for (String entry : stylesList) {
|
for (String entry : stylesList) {
|
||||||
boolean selected = entry.equals(selectedItem);
|
boolean selected = entry.equals(selectedItem);
|
||||||
createItemRow(selected, counter, entry, entry);
|
createItemRow(selected, counter, mapStyleAction.getTranslatedItemName(context, entry), entry);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
} else if (action instanceof SwitchableAction) {
|
} else if (action instanceof SwitchableAction) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback();
|
final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback();
|
||||||
final ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback);
|
final ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback);
|
||||||
|
|
||||||
final Adapter adapter = new Adapter(new QuickActionListFragment.OnStartDragListener() {
|
final Adapter adapter = new Adapter(activity, new QuickActionListFragment.OnStartDragListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
|
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
|
||||||
touchHelper.startDrag(viewHolder);
|
touchHelper.startDrag(viewHolder);
|
||||||
|
@ -107,6 +107,8 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
|
|
||||||
public abstract void executeWithParams(MapActivity activity, String params);
|
public abstract void executeWithParams(MapActivity activity, String params);
|
||||||
|
|
||||||
|
public abstract String getTranslatedItemName(Context context, String item);
|
||||||
|
|
||||||
protected void showChooseDialog(FragmentManager fm) {
|
protected void showChooseDialog(FragmentManager fm) {
|
||||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
@ -119,8 +121,10 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
|
|
||||||
private List<T> itemsList = new ArrayList<>();
|
private List<T> itemsList = new ArrayList<>();
|
||||||
private final QuickActionListFragment.OnStartDragListener onStartDragListener;
|
private final QuickActionListFragment.OnStartDragListener onStartDragListener;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
public Adapter(QuickActionListFragment.OnStartDragListener onStartDragListener) {
|
public Adapter(Context context, QuickActionListFragment.OnStartDragListener onStartDragListener) {
|
||||||
|
this.context = context;
|
||||||
this.onStartDragListener = onStartDragListener;
|
this.onStartDragListener = onStartDragListener;
|
||||||
this.itemsList = new ArrayList<>();
|
this.itemsList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -135,7 +139,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
public void onBindViewHolder(final Adapter.ItemHolder holder, final int position) {
|
public void onBindViewHolder(final Adapter.ItemHolder holder, final int position) {
|
||||||
final T item = itemsList.get(position);
|
final T item = itemsList.get(position);
|
||||||
|
|
||||||
holder.title.setText(getItemName(item));
|
holder.title.setText(getItemName(context, item));
|
||||||
|
|
||||||
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
|
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -274,7 +278,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
|
|
||||||
protected abstract void saveListToParams(List<T> list);
|
protected abstract void saveListToParams(List<T> list);
|
||||||
|
|
||||||
protected abstract String getItemName(T item);
|
protected abstract String getItemName(Context context, T item);
|
||||||
|
|
||||||
protected abstract
|
protected abstract
|
||||||
@StringRes
|
@StringRes
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.quickaction.actions;
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -69,7 +70,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getItemName(Pair<String, String> item) {
|
protected String getItemName(Context context, Pair<String, String> item) {
|
||||||
return item.second;
|
return item.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +118,17 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
settings.MAP_OVERLAY_PREVIOUS.set(null);
|
settings.MAP_OVERLAY_PREVIOUS.set(null);
|
||||||
}
|
}
|
||||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
|
plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
|
||||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, params), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch,
|
||||||
|
getTranslatedItemName(activity, params)), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTranslatedItemName(Context context, String item) {
|
||||||
|
if (item.equals(KEY_NO_OVERLAY)) {
|
||||||
|
return context.getString(R.string.no_overlay);
|
||||||
|
} else {
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.quickaction.actions;
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -108,7 +109,17 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
||||||
settings.MAP_ONLINE_DATA.set(true);
|
settings.MAP_ONLINE_DATA.set(true);
|
||||||
activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES);
|
activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES);
|
||||||
}
|
}
|
||||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch, params), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch,
|
||||||
|
getTranslatedItemName(activity, params)), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTranslatedItemName(Context context, String item) {
|
||||||
|
if (item.equals(LAYER_OSM_VECTOR)) {
|
||||||
|
return context.getString(R.string.vector_data);
|
||||||
|
} else {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -178,7 +189,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getItemName(Pair<String, String> item) {
|
protected String getItemName(Context context, Pair<String, String> item) {
|
||||||
return item.second;
|
return item.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.quickaction.actions;
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
@ -69,12 +70,20 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
app.getRendererRegistry().setCurrentSelectedRender(loaded);
|
app.getRendererRegistry().setCurrentSelectedRender(loaded);
|
||||||
ConfigureMapMenu.refreshMapComplete(activity);
|
ConfigureMapMenu.refreshMapComplete(activity);
|
||||||
|
|
||||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, params), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch,
|
||||||
|
getTranslatedItemName(activity, params)), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTranslatedItemName(Context context, String item) {
|
||||||
|
String translation = RendererRegistry.getTranslatedRendererName(context, item);
|
||||||
|
return translation != null ? translation
|
||||||
|
: item.replace('_', ' ').replace('-', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getFilteredStyles() {
|
public List<String> getFilteredStyles() {
|
||||||
|
|
||||||
List<String> filtered = new ArrayList<>();
|
List<String> filtered = new ArrayList<>();
|
||||||
|
@ -192,9 +201,13 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getItemName(String item) {
|
protected String getItemName(Context context, String item) {
|
||||||
|
if (context != null) {
|
||||||
|
return getTranslatedItemName(context, item);
|
||||||
|
} else {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle(List<String> filters) {
|
protected String getTitle(List<String> filters) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.quickaction.actions;
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -69,7 +70,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getItemName(Pair<String, String> item) {
|
protected String getItemName(Context context, Pair<String, String> item) {
|
||||||
return item.second;
|
return item.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +121,17 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
hidePolygonsPref.set(hasUnderlay);
|
hidePolygonsPref.set(hasUnderlay);
|
||||||
|
|
||||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
|
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
|
||||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, params), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch,
|
||||||
|
getTranslatedItemName(activity, params)), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTranslatedItemName(Context context, String item) {
|
||||||
|
if (item.equals(KEY_NO_UNDERLAY)) {
|
||||||
|
return context.getString(R.string.no_underlay);
|
||||||
|
} else {
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue