import fix

This commit is contained in:
veliymolfar 2020-02-25 16:56:16 +02:00
parent ae7fd7710a
commit 1d98082fac
2 changed files with 26 additions and 26 deletions

View file

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

View file

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