Add the ability to update ContextMenuItem itself
This commit is contained in:
parent
b8a1032295
commit
b01e72b00d
4 changed files with 51 additions and 43 deletions
|
@ -65,7 +65,6 @@ public class ContextMenuAdapter {
|
|||
@LayoutRes
|
||||
private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native;
|
||||
List<ContextMenuItem> items = new ArrayList<>();
|
||||
private ArrayAdapter<ContextMenuItem> arrayAdapter;
|
||||
private boolean profileDependent = false;
|
||||
private boolean nightMode;
|
||||
private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
|
||||
|
@ -202,9 +201,8 @@ public class ContextMenuAdapter {
|
|||
}
|
||||
}
|
||||
items.removeAll(itemsToRemove);
|
||||
arrayAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
|
||||
return new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
|
||||
items.toArray(new ContextMenuItem[items.size()]), app, lightTheme, changeAppModeListener);
|
||||
return arrayAdapter;
|
||||
}
|
||||
|
||||
public class ContextMenuArrayAdapter extends ArrayAdapter<ContextMenuItem> {
|
||||
|
@ -627,12 +625,6 @@ public class ContextMenuAdapter {
|
|||
return visible;
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (arrayAdapter != null) {
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public static OnItemDeleteAction makeDeleteAction(final OsmandPreference... prefs) {
|
||||
return new OnItemDeleteAction() {
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,8 +96,6 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_STYLE_ID;
|
||||
|
||||
public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInformationListener {
|
||||
private static final org.apache.commons.logging.Log LOG =
|
||||
PlatformUtil.getLog(DashboardOnMap.class);
|
||||
|
@ -132,7 +130,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
|
||||
private ArrayAdapter<?> listAdapter;
|
||||
private OnItemClickListener listAdapterOnClickListener;
|
||||
private ConfigureMapMenu configureMapMenu;
|
||||
|
||||
private boolean visible = false;
|
||||
private DashboardType visibleType;
|
||||
|
@ -659,16 +656,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
|
||||
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true);
|
||||
}
|
||||
|
||||
deleteTmpReferences();
|
||||
}
|
||||
mapActivity.updateStatusBarColor();
|
||||
}
|
||||
|
||||
private void deleteTmpReferences() {
|
||||
configureMapMenu = null;
|
||||
}
|
||||
|
||||
public void updateDashboard() {
|
||||
if (visibleType == DashboardType.ROUTE_PREFERENCES) {
|
||||
refreshContent(false);
|
||||
|
@ -714,8 +705,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
if (visibleType == DashboardType.CONFIGURE_SCREEN) {
|
||||
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
|
||||
} else if (visibleType == DashboardType.CONFIGURE_MAP) {
|
||||
configureMapMenu = new ConfigureMapMenu(mapActivity);
|
||||
cm = configureMapMenu.createListAdapter();
|
||||
cm = new ConfigureMapMenu(mapActivity).createListAdapter();
|
||||
} else if (visibleType == DashboardType.LIST_MENU) {
|
||||
cm = mapActivity.getMapActions().createMainOptionsMenu();
|
||||
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
|
||||
|
@ -1043,8 +1033,20 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
}
|
||||
|
||||
public void onMapSettingsUpdated() {
|
||||
if (configureMapMenu != null) {
|
||||
configureMapMenu.updateMenuItem(MAP_STYLE_ID);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,6 @@ public class ConfigureMapMenu {
|
|||
private boolean transliterateNames;
|
||||
|
||||
private MapActivity ma;
|
||||
private ContextMenuAdapter contextMenuAdapter;
|
||||
|
||||
public interface OnClickListener {
|
||||
void onClick();
|
||||
|
@ -143,7 +142,6 @@ public class ConfigureMapMenu {
|
|||
adapter.setNightMode(nightMode);
|
||||
createLayersItems(customRules, adapter, ma, themeRes, nightMode);
|
||||
createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode);
|
||||
this.contextMenuAdapter = adapter;
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
@ -281,16 +279,16 @@ public class ConfigureMapMenu {
|
|||
final OsmandSettings settings = app.getSettings();
|
||||
final int selectedProfileColorRes = settings.APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode);
|
||||
final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes);
|
||||
String renderDescr = getRenderDescr(app);
|
||||
|
||||
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(renderDescr)
|
||||
.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() {
|
||||
.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) {
|
||||
|
@ -300,6 +298,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 = "";
|
||||
|
@ -1119,18 +1124,6 @@ public class ConfigureMapMenu {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateMenuItem(String itemId) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) return;
|
||||
|
||||
if (MAP_STYLE_ID.equals(itemId) && contextMenuAdapter != null) {
|
||||
ContextMenuItem item = contextMenuAdapter.getItemById(MAP_STYLE_ID);
|
||||
String renderDescr = getRenderDescr(app);
|
||||
item.setDescription(renderDescr);
|
||||
contextMenuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return ma.getMyApplication();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue