refactor / constructors for duplicate PoiUiFilter, SQLiteTileSource
This commit is contained in:
parent
1af5cb9eaf
commit
e3c940502f
3 changed files with 40 additions and 28 deletions
|
@ -107,6 +107,21 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
this.inversiveZoom = inversiveZoom;
|
this.inversiveZoom = inversiveZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SQLiteTileSource(SQLiteTileSource tileSource, int suffixNum, OsmandApplication ctx) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.name = tileSource.getName() + "_" + suffixNum;
|
||||||
|
this.urlTemplate = tileSource.getUrlTemplate();
|
||||||
|
this.maxZoom = tileSource.getMaximumZoomSupported();
|
||||||
|
this.minZoom = tileSource.getMinimumZoomSupported();
|
||||||
|
this.isEllipsoid = tileSource.isEllipticYTile();
|
||||||
|
this.expirationTimeMillis = tileSource.getExpirationTimeMillis();
|
||||||
|
this.randoms = tileSource.getRandoms();
|
||||||
|
this.referer = tileSource.getReferer();
|
||||||
|
this.invertedY = tileSource.isInvertedYTile();
|
||||||
|
this.timeSupported = tileSource.isTimeSupported();
|
||||||
|
this.inversiveZoom = tileSource.getInversiveZoom();
|
||||||
|
}
|
||||||
|
|
||||||
public void createDataBase() {
|
public void createDataBase() {
|
||||||
db = ctx.getSQLiteAPI().getOrCreateDatabase(
|
db = ctx.getSQLiteAPI().getOrCreateDatabase(
|
||||||
ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true);
|
ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
|
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -831,39 +832,41 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static class QuickActionSettingsItem extends CollectionSettingsItem<QuickAction> {
|
public static class QuickActionSettingsItem extends CollectionSettingsItem<QuickAction> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
private QuickActionRegistry actionRegistry;
|
||||||
|
|
||||||
public QuickActionSettingsItem(@NonNull OsmandApplication app,
|
public QuickActionSettingsItem(@NonNull OsmandApplication app,
|
||||||
@NonNull List<QuickAction> items) {
|
@NonNull List<QuickAction> items) {
|
||||||
super(SettingsItemType.QUICK_ACTION, items);
|
super(SettingsItemType.QUICK_ACTION, items);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
existingItems = app.getQuickActionRegistry().getQuickActions();
|
actionRegistry = app.getQuickActionRegistry();
|
||||||
|
existingItems = actionRegistry.getQuickActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickActionSettingsItem(@NonNull OsmandApplication app,
|
QuickActionSettingsItem(@NonNull OsmandApplication app,
|
||||||
@NonNull JSONObject json) throws JSONException {
|
@NonNull JSONObject json) throws JSONException {
|
||||||
super(SettingsItemType.QUICK_ACTION, json);
|
super(SettingsItemType.QUICK_ACTION, json);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
existingItems = app.getQuickActionRegistry().getQuickActions();
|
actionRegistry = app.getQuickActionRegistry();
|
||||||
|
existingItems = actionRegistry.getQuickActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDuplicate(QuickAction item) {
|
public boolean isDuplicate(QuickAction item) {
|
||||||
return !app.getQuickActionRegistry().isNameUnique(item, app);
|
return !actionRegistry.isNameUnique(item, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public QuickAction renameItem(QuickAction item) {
|
public QuickAction renameItem(QuickAction item) {
|
||||||
return app.getQuickActionRegistry().generateUniqueName(item, app);
|
return actionRegistry.generateUniqueName(item, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List excludeDuplicateItems() {
|
public List<QuickAction> excludeDuplicateItems() {
|
||||||
duplicateItems = new ArrayList<>();
|
duplicateItems = new ArrayList<>();
|
||||||
for (QuickAction item : items) {
|
for (QuickAction item : items) {
|
||||||
if (isDuplicate(item)) {
|
if (isDuplicate(item)) {
|
||||||
|
@ -1008,12 +1011,11 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static class PoiUiFilterSettingsItem extends CollectionSettingsItem<PoiUIFilter> {
|
public static class PoiUiFilterSettingsItem extends CollectionSettingsItem<PoiUIFilter> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
public PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull List items) {
|
public PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull List<PoiUIFilter> items) {
|
||||||
super(SettingsItemType.POI_UI_FILTERS, items);
|
super(SettingsItemType.POI_UI_FILTERS, items);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||||
|
@ -1051,7 +1053,7 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List excludeDuplicateItems() {
|
public List<PoiUIFilter> excludeDuplicateItems() {
|
||||||
duplicateItems = new ArrayList<>();
|
duplicateItems = new ArrayList<>();
|
||||||
if (!items.isEmpty()) {
|
if (!items.isEmpty()) {
|
||||||
for (PoiUIFilter item : items) {
|
for (PoiUIFilter item : items) {
|
||||||
|
@ -1071,10 +1073,7 @@ public class SettingsHelper {
|
||||||
int number = 0;
|
int number = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
number++;
|
number++;
|
||||||
PoiUIFilter renamedItem = new PoiUIFilter(
|
PoiUIFilter renamedItem = new PoiUIFilter(item, number, app);
|
||||||
item.getName() + "_" + number,
|
|
||||||
item.getFilterId() + "_" + number,
|
|
||||||
item.getAcceptedTypes(), app);
|
|
||||||
if (!isDuplicate(renamedItem)) {
|
if (!isDuplicate(renamedItem)) {
|
||||||
return renamedItem;
|
return renamedItem;
|
||||||
}
|
}
|
||||||
|
@ -1194,13 +1193,12 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static class MapSourcesSettingsItem extends CollectionSettingsItem<ITileSource> {
|
public static class MapSourcesSettingsItem extends CollectionSettingsItem<ITileSource> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private List<String> existingItemsNames;
|
private List<String> existingItemsNames;
|
||||||
|
|
||||||
public MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull List 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();
|
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
|
||||||
|
@ -1253,7 +1251,7 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List excludeDuplicateItems() {
|
public List<ITileSource> excludeDuplicateItems() {
|
||||||
duplicateItems = new ArrayList<>();
|
duplicateItems = new ArrayList<>();
|
||||||
for (String name : existingItemsNames) {
|
for (String name : existingItemsNames) {
|
||||||
for (ITileSource tileSource : items) {
|
for (ITileSource tileSource : items) {
|
||||||
|
@ -1274,17 +1272,7 @@ public class SettingsHelper {
|
||||||
number++;
|
number++;
|
||||||
if (item instanceof SQLiteTileSource) {
|
if (item instanceof SQLiteTileSource) {
|
||||||
SQLiteTileSource oldItem = (SQLiteTileSource) item;
|
SQLiteTileSource oldItem = (SQLiteTileSource) item;
|
||||||
SQLiteTileSource renamedItem = new SQLiteTileSource(app,
|
SQLiteTileSource renamedItem = new SQLiteTileSource(oldItem, number, app);
|
||||||
oldItem.getName() + "_" + number,
|
|
||||||
oldItem.getMinimumZoomSupported(),
|
|
||||||
oldItem.getMaximumZoomSupported(),
|
|
||||||
oldItem.getUrlTemplate(),
|
|
||||||
oldItem.getRandoms(),
|
|
||||||
oldItem.isEllipticYTile(),
|
|
||||||
oldItem.isInvertedYTile(),
|
|
||||||
oldItem.getReferer(), oldItem.isTimeSupported(),
|
|
||||||
oldItem.getExpirationTimeMillis(),
|
|
||||||
oldItem.getInversiveZoom());
|
|
||||||
if (!isDuplicate(renamedItem)) {
|
if (!isDuplicate(renamedItem)) {
|
||||||
return renamedItem;
|
return renamedItem;
|
||||||
}
|
}
|
||||||
|
@ -1298,7 +1286,6 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDuplicate(ITileSource item) {
|
public boolean isDuplicate(ITileSource item) {
|
||||||
for (String name : existingItemsNames) {
|
for (String name : existingItemsNames) {
|
||||||
|
|
|
@ -125,6 +125,16 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
name = app.getPoiFilters().getFiltersName(filtersToMerge);
|
name = app.getPoiFilters().getFiltersName(filtersToMerge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PoiUIFilter(PoiUIFilter filter, int suffixNum, OsmandApplication app) {
|
||||||
|
this.app = app;
|
||||||
|
name = filter.getName() + "_" + suffixNum;
|
||||||
|
filterId = filter.getFilterId() + "_" + suffixNum;
|
||||||
|
isStandardFilter = false;
|
||||||
|
poiTypes = app.getPoiTypes();
|
||||||
|
acceptedTypes = filter.getAcceptedTypes();
|
||||||
|
poiAdditionals = filter.getPoiAdditionals();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue