Fix #9623 part 2 (Refactoring)
This commit is contained in:
parent
a577b26e7f
commit
2e388a0606
5 changed files with 38 additions and 77 deletions
|
@ -202,9 +202,9 @@ public class ContextMenuAdapter {
|
|||
}
|
||||
}
|
||||
items.removeAll(itemsToRemove);
|
||||
this.arrayAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
|
||||
arrayAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
|
||||
items.toArray(new ContextMenuItem[items.size()]), app, lightTheme, changeAppModeListener);
|
||||
return this.arrayAdapter;
|
||||
return arrayAdapter;
|
||||
}
|
||||
|
||||
public class ContextMenuArrayAdapter extends ArrayAdapter<ContextMenuItem> {
|
||||
|
@ -628,8 +628,8 @@ public class ContextMenuAdapter {
|
|||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (this.arrayAdapter != null) {
|
||||
this.arrayAdapter.notifyDataSetChanged();
|
||||
if (arrayAdapter != null) {
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ 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);
|
||||
|
@ -130,7 +132,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
|
||||
private ArrayAdapter<?> listAdapter;
|
||||
private OnItemClickListener listAdapterOnClickListener;
|
||||
private DashboardStateListener dashboardStateListener;
|
||||
private ConfigureMapMenu configureMapMenu;
|
||||
|
||||
private boolean visible = false;
|
||||
private DashboardType visibleType;
|
||||
|
@ -657,20 +659,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
|
||||
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true);
|
||||
}
|
||||
|
||||
deleteTmpReferences();
|
||||
}
|
||||
notifyDashboardVisibilityStateListener(visible);
|
||||
mapActivity.updateStatusBarColor();
|
||||
}
|
||||
|
||||
private void notifyDashboardVisibilityStateListener(boolean visible) {
|
||||
if (dashboardStateListener != null) {
|
||||
if (visible) {
|
||||
dashboardStateListener.onShowDashboard();
|
||||
} else {
|
||||
dashboardStateListener.onHideDashboard();
|
||||
dashboardStateListener = null;
|
||||
}
|
||||
}
|
||||
private void deleteTmpReferences() {
|
||||
configureMapMenu = null;
|
||||
}
|
||||
|
||||
public void updateDashboard() {
|
||||
|
@ -718,8 +714,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 configureMapMenu = new ConfigureMapMenu(mapActivity);
|
||||
dashboardStateListener = configureMapMenu;
|
||||
configureMapMenu = new ConfigureMapMenu(mapActivity);
|
||||
cm = configureMapMenu.createListAdapter(mapActivity);
|
||||
} else if (visibleType == DashboardType.LIST_MENU) {
|
||||
cm = mapActivity.getMapActions().createMainOptionsMenu();
|
||||
|
@ -1047,6 +1042,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
}
|
||||
}
|
||||
|
||||
public void onMapSettingsUpdated() {
|
||||
if (configureMapMenu != null) {
|
||||
configureMapMenu.updateMenuItem(MAP_STYLE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLocation(final boolean centerChanged, final boolean locationChanged,
|
||||
final boolean compassChanged) {
|
||||
if (inLocationUpdate) {
|
||||
|
@ -1330,12 +1331,4 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
@Override
|
||||
public void routeWasFinished() {
|
||||
}
|
||||
|
||||
public interface DashboardStateListener {
|
||||
|
||||
void onShowDashboard();
|
||||
|
||||
void onHideDashboard();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,11 +37,9 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.render.RendererRegistry.OnChangeRenderingRuleListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.ListStringPreference;
|
||||
|
@ -100,7 +98,7 @@ import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAI
|
|||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDE;
|
||||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_ROUTES;
|
||||
|
||||
public class ConfigureMapMenu implements DashboardOnMap.DashboardStateListener {
|
||||
public class ConfigureMapMenu {
|
||||
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
|
||||
public static final String TAG = ConfigureMapMenu.class.getName();
|
||||
public static final String HIKING_ROUTES_OSMC_ATTR = "hikingRoutesOSMC";
|
||||
|
@ -284,9 +282,7 @@ public class ConfigureMapMenu implements DashboardOnMap.DashboardStateListener {
|
|||
final OsmandSettings settings = app.getSettings();
|
||||
final int selectedProfileColorRes = settings.APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode);
|
||||
final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes);
|
||||
RendererRegistry rr = app.getRendererRegistry();
|
||||
RenderingRulesStorage storage = rr.getCurrentSelectedRenderer();
|
||||
String renderDescr = getRenderDescr(activity, storage);
|
||||
String renderDescr = getRenderDescr(app);
|
||||
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity)
|
||||
.setId(MAP_RENDERING_CATEGORY_ID)
|
||||
|
@ -957,11 +953,13 @@ public class ConfigureMapMenu implements DashboardOnMap.DashboardStateListener {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
protected String getRenderDescr(Context ctx, RenderingRulesStorage storage) {
|
||||
protected String getRenderDescr(OsmandApplication app) {
|
||||
RendererRegistry rr = app.getRendererRegistry();
|
||||
RenderingRulesStorage storage = rr.getCurrentSelectedRenderer();
|
||||
if (storage == null) {
|
||||
return "";
|
||||
}
|
||||
String translation = RendererRegistry.getTranslatedRendererName(ctx, storage.getName());
|
||||
String translation = RendererRegistry.getTranslatedRendererName(app, storage.getName());
|
||||
return translation == null ? storage.getName() : translation;
|
||||
}
|
||||
|
||||
|
@ -1122,25 +1120,16 @@ public class ConfigureMapMenu implements DashboardOnMap.DashboardStateListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowDashboard() {
|
||||
getMyApplication().getRendererRegistry()
|
||||
.addOnChangeRenderingRuleListener(TAG, new OnChangeRenderingRuleListener() {
|
||||
@Override
|
||||
public void onRenderingRuleChanged(RenderingRulesStorage currentSelectedRender) {
|
||||
if (contextMenuAdapter != null) {
|
||||
ContextMenuItem item = contextMenuAdapter.getItemById(MAP_STYLE_ID);
|
||||
String renderDescr = getRenderDescr(mapActivity, currentSelectedRender);
|
||||
item.setDescription(renderDescr);
|
||||
contextMenuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public void updateMenuItem(String itemId) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) return;
|
||||
|
||||
@Override
|
||||
public void onHideDashboard() {
|
||||
getMyApplication().getRendererRegistry().removeOnChangeRenderingRuleListener(TAG);
|
||||
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() {
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
@ -50,8 +49,7 @@ public class RendererRegistry {
|
|||
|
||||
private RenderingRulesStorage defaultRender = null;
|
||||
private RenderingRulesStorage currentSelectedRender = null;
|
||||
private Map<String, OnChangeRenderingRuleListener> onChangeRenderingRuleListeners = new HashMap<>();
|
||||
|
||||
|
||||
private Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
|
||||
private Map<String, String> internalRenderers = new LinkedHashMap<String, String>();
|
||||
|
||||
|
@ -338,20 +336,6 @@ public class RendererRegistry {
|
|||
|
||||
public void setCurrentSelectedRender(final RenderingRulesStorage currentSelectedRender) {
|
||||
this.currentSelectedRender = currentSelectedRender;
|
||||
notifyChangeRenderRuleListeners();
|
||||
}
|
||||
|
||||
public void notifyChangeRenderRuleListeners() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (OnChangeRenderingRuleListener listener : onChangeRenderingRuleListeners.values()) {
|
||||
if (listener != null) {
|
||||
listener.onRenderingRuleChanged(currentSelectedRender);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setRendererLoadedEventListener(IRendererLoadedEventListener listener) {
|
||||
|
@ -378,15 +362,6 @@ public class RendererRegistry {
|
|||
return externalRenderers;
|
||||
}
|
||||
|
||||
public void addOnChangeRenderingRuleListener(@NonNull String key,
|
||||
@NonNull OnChangeRenderingRuleListener listener) {
|
||||
onChangeRenderingRuleListeners.put(key, listener);
|
||||
}
|
||||
|
||||
public void removeOnChangeRenderingRuleListener(@NonNull String key) {
|
||||
onChangeRenderingRuleListeners.remove(key);
|
||||
}
|
||||
|
||||
public interface OnChangeRenderingRuleListener {
|
||||
void onRenderingRuleChanged(RenderingRulesStorage currentSelectedRender);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue