Merge pull request #9871 from osmandapp/Fix_9623

Fix #9623
This commit is contained in:
Vitaliy 2020-10-01 17:56:16 +03:00 committed by GitHub
commit 9fd029b089
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 11 deletions

View file

@ -34,6 +34,7 @@ public class ContextMenuItem {
private boolean hidden;
private int order;
private String description;
private final OnUpdateCallback onUpdateCallback;
private final ContextMenuAdapter.ItemClickListener itemClickListener;
private final ContextMenuAdapter.OnIntegerValueChangedListener integerListener;
private final ContextMenuAdapter.ProgressListener progressListener;
@ -58,6 +59,7 @@ public class ContextMenuItem {
boolean skipPaintingWithoutColor,
int order,
String description,
OnUpdateCallback onUpdateCallback,
ContextMenuAdapter.ItemClickListener itemClickListener,
ContextMenuAdapter.OnIntegerValueChangedListener integerListener,
ContextMenuAdapter.ProgressListener progressListener,
@ -81,6 +83,7 @@ public class ContextMenuItem {
this.skipPaintingWithoutColor = skipPaintingWithoutColor;
this.order = order;
this.description = description;
this.onUpdateCallback = onUpdateCallback;
this.itemClickListener = itemClickListener;
this.integerListener = integerListener;
this.progressListener = progressListener;
@ -245,6 +248,16 @@ public class ContextMenuItem {
return id;
}
public void update() {
if (onUpdateCallback != null) {
onUpdateCallback.onUpdateMenuItem(this);
}
}
public interface OnUpdateCallback {
void onUpdateMenuItem(ContextMenuItem item);
}
public static ItemBuilder createBuilder(String title) {
return new ItemBuilder().setTitle(title);
}
@ -268,6 +281,7 @@ public class ContextMenuItem {
private boolean mIsClickable = true;
private int mOrder = 0;
private String mDescription = null;
private OnUpdateCallback mOnUpdateCallback = null;
private ContextMenuAdapter.ItemClickListener mItemClickListener = null;
private ContextMenuAdapter.OnIntegerValueChangedListener mIntegerListener = null;
private ContextMenuAdapter.ProgressListener mProgressListener = null;
@ -348,6 +362,11 @@ public class ContextMenuItem {
return this;
}
public ItemBuilder setOnUpdateCallback(OnUpdateCallback onUpdateCallback) {
mOnUpdateCallback = onUpdateCallback;
return this;
}
public ItemBuilder setListener(ContextMenuAdapter.ItemClickListener checkBoxListener) {
mItemClickListener = checkBoxListener;
return this;
@ -403,10 +422,12 @@ public class ContextMenuItem {
}
public ContextMenuItem createItem() {
return new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon,
ContextMenuItem item = new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon,
mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor,
mOrder, mDescription, mItemClickListener, mIntegerListener, mProgressListener, mItemDeleteAction,
mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId);
mOrder, mDescription, mOnUpdateCallback, mItemClickListener, mIntegerListener, mProgressListener,
mItemDeleteAction, mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId);
item.update();
return item;
}
}
}

View file

@ -1466,6 +1466,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
protected void onPostExecute(Void result) {
DashboardOnMap dashboard = getDashboard();
if (dashboard != null) {
dashboard.onMapSettingsUpdated();
}
}
}.executeOnExecutor(singleThreadExecutor, (Void) null);

View file

@ -568,7 +568,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
boolean refresh = this.visibleType == type && !appModeChanged;
previousAppMode = currentAppMode;
this.visibleType = type;
visibleType = type;
DashboardOnMap.staticVisible = visible;
DashboardOnMap.staticVisibleType = type;
mapActivity.enableDrawer();
@ -1032,6 +1032,24 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
}
}
public void onMapSettingsUpdated() {
if (DashboardType.CONFIGURE_MAP.equals(visibleType)) {
updateMenuItems();
}
}
public void updateMenuItems() {
if (listAdapter != null) {
for (int i = 0; i < listAdapter.getCount(); i++) {
Object o = listAdapter.getItem(i);
if (o instanceof ContextMenuItem) {
((ContextMenuItem) o).update();
}
}
listAdapter.notifyDataSetChanged();
}
}
public void updateLocation(final boolean centerChanged, final boolean locationChanged,
final boolean compassChanged) {
if (inLocationUpdate) {

View file

@ -277,10 +277,12 @@ public class ConfigureMapMenu {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity)
.setId(MAP_RENDERING_CATEGORY_ID)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity)
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(MAP_STYLE_ID)
.setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {
.setTitleId(R.string.map_widget_renderer, activity)
.setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_map)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked, int[] viewCoordinates) {
@ -290,6 +292,13 @@ public class ConfigureMapMenu {
}
})
.setItemDeleteAction(makeDeleteAction(settings.RENDERER))
.setOnUpdateCallback(new ContextMenuItem.OnUpdateCallback() {
@Override
public void onUpdateMenuItem(ContextMenuItem item) {
String renderDescr = getRenderDescr(app);
item.setDescription(renderDescr);
}
})
.createItem());
String description = "";
@ -942,13 +951,13 @@ public class ConfigureMapMenu {
dialog.show();
}
protected String getRenderDescr(final MapActivity activity) {
RendererRegistry rr = activity.getMyApplication().getRendererRegistry();
protected String getRenderDescr(OsmandApplication app) {
RendererRegistry rr = app.getRendererRegistry();
RenderingRulesStorage storage = rr.getCurrentSelectedRenderer();
if (storage == null) {
return "";
}
String translation = RendererRegistry.getTranslatedRendererName(activity, storage.getName());
String translation = RendererRegistry.getTranslatedRendererName(app, storage.getName());
return translation == null ? storage.getName() : translation;
}