Merge pull request #8558 from osmandapp/avoid_roads_export_import

import fix
This commit is contained in:
max-klaus 2020-02-25 19:42:19 +03:00 committed by GitHub
commit c3cbbe799a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 29 deletions

View file

@ -245,7 +245,7 @@ public class SettingsHelper {
public abstract static class CollectionSettingsItem<T> extends SettingsItem {
protected List<T> items;
protected List<T> items = new ArrayList<>();
protected List<T> duplicateItems = new ArrayList<>();
protected List<T> existingItems;
@ -931,7 +931,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemReader getReader() {
return new SettingsItemReader(this) {
return new SettingsItemReader<QuickActionSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
StringBuilder buf = new StringBuilder();
@ -950,7 +950,6 @@ public class SettingsHelper {
}
final JSONObject json;
try {
items = new ArrayList<>();
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, String>>() {
}.getType();
@ -979,7 +978,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemWriter getWriter() {
return new SettingsItemWriter(this) {
return new SettingsItemWriter<QuickActionSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
JSONObject json = new JSONObject();
@ -1098,7 +1097,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemReader getReader() {
return new SettingsItemReader(this) {
return new SettingsItemReader<PoiUiFilterSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
StringBuilder buf = new StringBuilder();
@ -1117,7 +1116,6 @@ public class SettingsHelper {
}
final JSONObject json;
try {
items = new ArrayList<>();
json = new JSONObject(jsonStr);
JSONArray jsonArray = json.getJSONArray("items");
Gson gson = new Gson();
@ -1148,7 +1146,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemWriter getWriter() {
return new SettingsItemWriter(this) {
return new SettingsItemWriter<PoiUiFilterSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
JSONObject json = new JSONObject();
@ -1193,15 +1191,13 @@ public class SettingsHelper {
public MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull List<ITileSource> items) {
super(SettingsItemType.MAP_SOURCES, items);
this.app = app;
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
existingItemsNames = new ArrayList(values);
existingItemsNames = new ArrayList<>(app.getSettings().getTileSourceEntries().values());
}
MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.MAP_SOURCES, json);
this.app = app;
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
existingItemsNames = new ArrayList(values);
existingItemsNames = new ArrayList<>(app.getSettings().getTileSourceEntries().values());
}
@Override
@ -1301,7 +1297,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemReader getReader() {
return new SettingsItemReader(this) {
return new SettingsItemReader<MapSourcesSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
StringBuilder buf = new StringBuilder();
@ -1320,7 +1316,6 @@ public class SettingsHelper {
}
final JSONObject json;
try {
items = new ArrayList<>();
json = new JSONObject(jsonStr);
JSONArray jsonArray = json.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
@ -1361,7 +1356,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemWriter getWriter() {
return new SettingsItemWriter(this) {
return new SettingsItemWriter<MapSourcesSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
JSONObject json = new JSONObject();
@ -1503,7 +1498,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemReader getReader() {
return new SettingsItemReader(this) {
return new SettingsItemReader<AvoidRoadsSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
StringBuilder buf = new StringBuilder();
@ -1522,7 +1517,6 @@ public class SettingsHelper {
}
final JSONObject json;
try {
items = new ArrayList<>();
json = new JSONObject(jsonStr);
JSONArray jsonArray = json.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
@ -1553,7 +1547,7 @@ public class SettingsHelper {
@NonNull
@Override
SettingsItemWriter getWriter() {
return new SettingsItemWriter(this) {
return new SettingsItemWriter<AvoidRoadsSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
JSONObject json = new JSONObject();
@ -1599,9 +1593,14 @@ public class SettingsHelper {
JSONArray itemsJson = json.getJSONArray("items");
for (int i = 0; i < itemsJson.length(); i++) {
JSONObject itemJson = itemsJson.getJSONObject(i);
SettingsItem item = createItem(itemJson);
if (item != null) {
items.add(item);
SettingsItem item;
try {
item = createItem(itemJson);
if (item != null) {
items.add(item);
}
} catch (IllegalArgumentException e) {
LOG.error("Error creating item from json: " + itemJson, e);
}
}
if (items.size() == 0) {
@ -1811,7 +1810,7 @@ public class SettingsHelper {
private SettingsImportListener listener;
private SettingsImporter importer;
private List<SettingsItem> items;
private List<SettingsItem> items = new ArrayList<>();
private List<SettingsItem> processedItems = new ArrayList<>();
private SettingsItem currentItem;
private AlertDialog dialog;
@ -1864,10 +1863,12 @@ public class SettingsHelper {
}
@Override
protected void onPostExecute(List<SettingsItem> items) {
this.items = items;
protected void onPostExecute(@Nullable List<SettingsItem> items) {
if (items != null) {
this.items = items;
}
if (collectOnly) {
listener.onSettingsImportFinished(true, false, items);
listener.onSettingsImportFinished(true, false, this.items);
} else {
if (items != null && items.size() > 0) {
processNextItem();
@ -1972,7 +1973,7 @@ public class SettingsHelper {
}
}
private void finishImport(@Nullable SettingsImportListener listener, boolean success, boolean empty, List<SettingsItem> items) {
private void finishImport(@Nullable SettingsImportListener listener, boolean success, boolean empty, @NonNull List<SettingsItem> items) {
importing = false;
importSuspended = false;
importTask = null;

View file

@ -45,9 +45,9 @@ import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
@ -205,9 +205,9 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
}
List<ITileSource> iTileSources = new ArrayList<>();
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
for (Map.Entry<String, String> entry : tileSourceEntries.entrySet()) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + entry.getKey());
Set<String> tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet();
for (String name : tileSourceNames) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + name);
if (f != null) {
ITileSource template;
if (f.getName().endsWith(SQLiteTileSource.EXT)) {