Fix duplicates export bug

This commit is contained in:
Vitaliy 2020-03-26 16:05:11 +02:00
parent b774ccc51d
commit 24964c7802
7 changed files with 44 additions and 57 deletions

View file

@ -286,7 +286,7 @@ public class CustomOsmandPlugin extends OsmandPlugin {
}
public void addRenderer(String fileName) {
String renderer = RendererRegistry.formatRenderFileName(fileName);
String renderer = RendererRegistry.formatRendererFileName(fileName);
rendererNames.add(renderer.replace('_', ' ').replace('-', ' '));
}
}

View file

@ -185,7 +185,7 @@ public abstract class OsmandPlugin {
* Plugin was installed
*/
public void onInstall(@NonNull OsmandApplication app, @Nullable Activity activity) {
for (ApplicationMode appMode: getAddedAppModes()) {
for (ApplicationMode appMode : getAddedAppModes()) {
ApplicationMode.changeProfileAvailability(appMode, true, app);
}
showInstallDialog(activity);
@ -194,23 +194,19 @@ public abstract class OsmandPlugin {
public void showInstallDialog(@Nullable Activity activity) {
if (activity instanceof FragmentActivity) {
FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
if (fragmentManager != null) {
PluginInstalledBottomSheetDialog.showInstance(fragmentManager, getId(), activity instanceof MapActivity);
}
PluginInstalledBottomSheetDialog.showInstance(fragmentManager, getId(), activity instanceof MapActivity);
}
}
public void showDisableDialog(@Nullable Activity activity) {
if (activity instanceof FragmentActivity) {
FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
if (fragmentManager != null) {
PluginDisabledBottomSheet.showInstance(fragmentManager, getId(), activity instanceof MapActivity);
}
PluginDisabledBottomSheet.showInstance(fragmentManager, getId(), activity instanceof MapActivity);
}
}
public void disable(OsmandApplication app) {
for (ApplicationMode appMode: getAddedAppModes()) {
for (ApplicationMode appMode : getAddedAppModes()) {
ApplicationMode.changeProfileAvailability(appMode, false, app);
}
}

View file

@ -447,7 +447,6 @@ public class SettingsHelper {
}
}
}
items.removeAll(duplicateItems);
return duplicateItems;
}
@ -1265,31 +1264,28 @@ public class SettingsHelper {
@Override
public void apply() {
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<QuickAction> newActions = getNewActions();
actionRegistry.updateQuickActions(newActions);
}
}
private List<QuickAction> getNewActions() {
List<QuickAction> newActions = new ArrayList<>(existingItems);
if (!duplicateItems.isEmpty()) {
if (shouldReplace) {
for (QuickAction duplicateItem : duplicateItems) {
for (QuickAction savedAction : existingItems) {
if (duplicateItem.getName(app).equals(savedAction.getName(app))) {
newActions.remove(savedAction);
List<QuickAction> actions = new ArrayList<>(items);
actions.removeAll(duplicateItems);
List<QuickAction> newActions = new ArrayList<>(existingItems);
if (!duplicateItems.isEmpty()) {
if (shouldReplace) {
for (QuickAction duplicateItem : duplicateItems) {
for (QuickAction savedAction : existingItems) {
if (duplicateItem.getName(app).equals(savedAction.getName(app))) {
newActions.remove(savedAction);
}
}
}
} else {
for (QuickAction duplicateItem : duplicateItems) {
renameItem(duplicateItem);
}
}
} else {
for (QuickAction duplicateItem : duplicateItems) {
renameItem(duplicateItem);
}
newActions.addAll(duplicateItems);
}
newActions.addAll(duplicateItems);
newActions.addAll(actions);
actionRegistry.updateQuickActions(newActions);
}
newActions.addAll(items);
return newActions;
}
@Override
@ -1354,10 +1350,9 @@ public class SettingsHelper {
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, String>>() {
}.getType();
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<QuickAction> newActions = getNewActions();
if (!items.isEmpty()) {
try {
for (QuickAction action : newActions) {
for (QuickAction action : items) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", action.hasCustomName(app)
? action.getName(app) : "");
@ -1406,10 +1401,13 @@ public class SettingsHelper {
@Override
public void apply() {
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<PoiUIFilter> poiUIFilters = new ArrayList<>(items);
poiUIFilters.removeAll(duplicateItems);
for (PoiUIFilter duplicate : duplicateItems) {
items.add(shouldReplace ? duplicate : renameItem(duplicate));
poiUIFilters.add(shouldReplace ? duplicate : renameItem(duplicate));
}
for (PoiUIFilter filter : items) {
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().createPoiFilter(filter, false);
}
app.getSearchUICore().refreshCustomPoiFilters();
@ -1553,30 +1551,32 @@ public class SettingsHelper {
@Override
public void apply() {
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<ITileSource> tileSources = new ArrayList<>(items);
tileSources.removeAll(duplicateItems);
if (shouldReplace) {
for (ITileSource tileSource : duplicateItems) {
if (tileSource instanceof SQLiteTileSource) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT);
if (f != null && f.exists()) {
if (f.delete()) {
items.add(tileSource);
tileSources.add(tileSource);
}
}
} else if (tileSource instanceof TileSourceManager.TileSourceTemplate) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
if (f != null && f.exists() && f.isDirectory()) {
if (f.delete()) {
items.add(tileSource);
tileSources.add(tileSource);
}
}
}
}
} else {
for (ITileSource tileSource : duplicateItems) {
items.add(renameItem(tileSource));
tileSources.add(renameItem(tileSource));
}
}
for (ITileSource tileSource : items) {
for (ITileSource tileSource : tileSources) {
if (tileSource instanceof TileSourceManager.TileSourceTemplate) {
app.getSettings().installTileSource((TileSourceManager.TileSourceTemplate) tileSource);
} else if (tileSource instanceof SQLiteTileSource) {
@ -1684,11 +1684,9 @@ public class SettingsHelper {
@Override
void writeItemsToJson(@NonNull JSONObject json) {
JSONArray jsonArray = new JSONArray();
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<ITileSource> templates = new ArrayList<>(items);
templates.addAll(duplicateItems);
if (!items.isEmpty()) {
try {
for (ITileSource template : templates) {
for (ITileSource template : items) {
JSONObject jsonObject = new JSONObject();
boolean sql = template instanceof SQLiteTileSource;
jsonObject.put("sql", sql);
@ -1780,6 +1778,8 @@ public class SettingsHelper {
@Override
public void apply() {
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
List<AvoidRoadInfo> avoidRoadInfos = new ArrayList<>(items);
avoidRoadInfos.removeAll(duplicateItems);
for (AvoidRoadInfo duplicate : duplicateItems) {
if (shouldReplace) {
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
@ -1790,7 +1790,7 @@ public class SettingsHelper {
settings.addImpassableRoad(renameItem(duplicate));
}
}
for (AvoidRoadInfo avoidRoad : items) {
for (AvoidRoadInfo avoidRoad : avoidRoadInfos) {
settings.addImpassableRoad(avoidRoad);
}
specificRoads.loadImpassableRoads();

View file

@ -82,7 +82,6 @@ import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.zip.ZipInputStream;
@ -848,13 +847,6 @@ public class ImportHelper {
if (activity != null) {
pluginItem.getPlugin().onInstall(app, activity);
}
// will be removed after obf_map subtype fix
for (Iterator<SettingsItem> iterator = items.iterator(); iterator.hasNext(); ) {
SettingsItem item = iterator.next();
if (item instanceof SettingsHelper.ResourcesSettingsItem) {
iterator.remove();
}
}
String pluginId = pluginItem.getPluginId();
File pluginDir = new File(app.getAppPath(null), IndexConstants.PLUGINS_DIR + pluginId);
app.getSettingsHelper().exportSettings(pluginDir, "items", null, items, false);

View file

@ -261,7 +261,7 @@ public class RendererRegistry {
for (File f : lf) {
if (f != null && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT)) {
if (!internalRenderers.containsValue(f.getName())) {
String name = formatRenderFileName(f.getName());
String name = formatRendererFileName(f.getName());
externalRenderers.put(name, f);
}
}
@ -271,7 +271,7 @@ public class RendererRegistry {
this.externalRenderers = externalRenderers;
}
public static String formatRenderFileName(String fileName) {
public static String formatRendererFileName(String fileName) {
String name = fileName.substring(0, fileName.length() - IndexConstants.ROUTING_AND_RENDERING_FILE_EXT.length());
return name.replace('_', ' ').replace('-', ' ');
}

View file

@ -27,12 +27,12 @@ public class SkiMapsPlugin extends OsmandPlugin {
public String getName() {
return app.getString(net.osmand.plus.R.string.plugin_ski_name);
}
@Override
public int getLogoResourceId() {
return R.drawable.ic_action_skiing;
}
@Override
public int getAssetResourceName() {
return R.drawable.ski_map;

View file

@ -62,7 +62,6 @@ public class SRTMPlugin extends OsmandPlugin {
public static final int TERRAIN_MIN_ZOOM = 3;
public static final int TERRAIN_MAX_ZOOM = 19;
private OsmandApplication app;
private OsmandSettings settings;
private TerrainLayer terrainLayer;