refactor / change to ITileSource
This commit is contained in:
parent
ab77ea143c
commit
af5efd12b7
4 changed files with 77 additions and 47 deletions
|
@ -12,6 +12,8 @@ public interface ITileSource {
|
||||||
|
|
||||||
public String getUrlToLoad(int x, int y, int zoom);
|
public String getUrlToLoad(int x, int y, int zoom);
|
||||||
|
|
||||||
|
public String getUrlTemplate();
|
||||||
|
|
||||||
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException;
|
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException;
|
||||||
|
|
||||||
public int getMinimumZoomSupported();
|
public int getMinimumZoomSupported();
|
||||||
|
|
|
@ -117,6 +117,11 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
return TileSourceTemplate.buildUrlToLoad(urlTemplate, randomsArray, x, y, zoom);
|
return TileSourceTemplate.buildUrlToLoad(urlTemplate, randomsArray, x, y, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrlTemplate() {
|
||||||
|
return this.urlTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
import net.osmand.osm.MapPoiTypes;
|
import net.osmand.osm.MapPoiTypes;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
|
@ -101,10 +102,6 @@ public class SettingsHelper {
|
||||||
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SettingsPreImportListener {
|
|
||||||
void onSettingsPreImported(boolean isSuccessful, List<SettingsItem> items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SettingsHelper(OsmandApplication app) {
|
public SettingsHelper(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +169,7 @@ public class SettingsHelper {
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract String getFileName();
|
public abstract String getFileName();
|
||||||
|
|
||||||
public Boolean shouldReadInCollecting() {
|
public Boolean shouldReadOnCollecting() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,9 +737,10 @@ public class SettingsHelper {
|
||||||
this.quickActions = quickActions;
|
this.quickActions = quickActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuickActionSettingsItem(@NonNull OsmandSettings settings,
|
public QuickActionSettingsItem(@NonNull OsmandApplication app,
|
||||||
@NonNull JSONObject jsonObject) throws JSONException {
|
@NonNull JSONObject jsonObject) throws JSONException {
|
||||||
super(SettingsItemType.QUICK_ACTION, settings, jsonObject);
|
super(SettingsItemType.QUICK_ACTION, app.getSettings(), jsonObject);
|
||||||
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<QuickAction> getQuickActions() {
|
public List<QuickAction> getQuickActions() {
|
||||||
|
@ -768,7 +766,7 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean shouldReadInCollecting() {
|
public Boolean shouldReadOnCollecting() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +880,6 @@ public class SettingsHelper {
|
||||||
public PoiUiFilterSettingsItem(OsmandApplication app, JSONObject jsonObject) throws JSONException {
|
public PoiUiFilterSettingsItem(OsmandApplication app, JSONObject jsonObject) throws JSONException {
|
||||||
super(SettingsItemType.POI_UI_FILTERS, app.getSettings(), jsonObject);
|
super(SettingsItemType.POI_UI_FILTERS, app.getSettings(), jsonObject);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
readFromJson(jsonObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PoiUIFilter> getPoiUIFilters() {
|
public List<PoiUIFilter> getPoiUIFilters() {
|
||||||
|
@ -912,7 +909,7 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean shouldReadInCollecting() {
|
public Boolean shouldReadOnCollecting() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1004,28 +1001,32 @@ public class SettingsHelper {
|
||||||
|
|
||||||
public static class MapSourcesSettingsItem extends OsmandSettingsItem {
|
public static class MapSourcesSettingsItem extends OsmandSettingsItem {
|
||||||
|
|
||||||
private List<TileSourceManager.TileSourceTemplate> mapSources;
|
private OsmandApplication app;
|
||||||
|
|
||||||
public MapSourcesSettingsItem(OsmandSettings settings, List<TileSourceManager.TileSourceTemplate> mapSources) {
|
private List<ITileSource> mapSources;
|
||||||
super(SettingsItemType.MAP_SOURCES, settings);
|
|
||||||
|
public MapSourcesSettingsItem(OsmandApplication app, List<ITileSource> mapSources) {
|
||||||
|
super(SettingsItemType.MAP_SOURCES, app.getSettings());
|
||||||
|
this.app = app;
|
||||||
this.mapSources = mapSources;
|
this.mapSources = mapSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapSourcesSettingsItem(OsmandSettings settings, JSONObject jsonObject) throws JSONException {
|
public MapSourcesSettingsItem(OsmandApplication app, JSONObject jsonObject) throws JSONException {
|
||||||
super(SettingsItemType.MAP_SOURCES, settings, jsonObject);
|
super(SettingsItemType.MAP_SOURCES, app.getSettings(), jsonObject);
|
||||||
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TileSourceManager.TileSourceTemplate> getMapSources() {
|
public List<ITileSource> getMapSources() {
|
||||||
return this.mapSources;
|
return this.mapSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
if (!mapSources.isEmpty()) {
|
if (!mapSources.isEmpty()) {
|
||||||
for (TileSourceManager.TileSourceTemplate template : mapSources) {
|
for (ITileSource template : mapSources) {
|
||||||
boolean writed = getSettings().installTileSource(template);
|
// getSettings().installTileSource(template);
|
||||||
LOG.info("Temaplate _" + writed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,7 +1043,7 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean shouldReadInCollecting() {
|
public Boolean shouldReadOnCollecting() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,10 +1082,16 @@ public class SettingsHelper {
|
||||||
try {
|
try {
|
||||||
mapSources = new ArrayList<>();
|
mapSources = new ArrayList<>();
|
||||||
json = new JSONObject(jsonStr);
|
json = new JSONObject(jsonStr);
|
||||||
String items = json.getString("items");
|
JSONArray items = json.getJSONArray("items");
|
||||||
TileSourceManager manager = new TileSourceManager();
|
for (int i = 0; i < items.length(); i++) {
|
||||||
List<TileSourceManager.TileSourceTemplate> templates = manager.parseTemplatesList(items);
|
JSONObject object = items.getJSONObject(i);
|
||||||
mapSources.addAll(templates);
|
String name = object.getString("name");
|
||||||
|
// String url = object.getString("url");
|
||||||
|
|
||||||
|
|
||||||
|
// ITileSource template
|
||||||
|
// mapSources.add();
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new IllegalArgumentException("Json parse error", e);
|
throw new IllegalArgumentException("Json parse error", e);
|
||||||
}
|
}
|
||||||
|
@ -1098,9 +1105,19 @@ public class SettingsHelper {
|
||||||
return new OsmandSettingsItemWriter(this, getSettings()) {
|
return new OsmandSettingsItemWriter(this, getSettings()) {
|
||||||
@Override
|
@Override
|
||||||
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||||
TileSourceManager manager = new TileSourceManager();
|
JSONArray items = new JSONArray();
|
||||||
if (!mapSources.isEmpty()) {
|
if (!mapSources.isEmpty()) {
|
||||||
json.put("items", manager.templatesListToString(mapSources));
|
for (ITileSource template : mapSources) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("name", template.getName());
|
||||||
|
jsonObject.put("url", template.getUrlTemplate());
|
||||||
|
jsonObject.put("ext", template.getUrlTemplate());
|
||||||
|
jsonObject.put("minZoom", template.getMinimumZoomSupported());
|
||||||
|
jsonObject.put("maxZoom", template.getMaximumZoomSupported());
|
||||||
|
jsonObject.put("expire", template.getExpirationTimeMillis());
|
||||||
|
items.put(jsonObject);
|
||||||
|
}
|
||||||
|
json.put("items", items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1164,13 +1181,13 @@ public class SettingsHelper {
|
||||||
item = new FileSettingsItem(app, json);
|
item = new FileSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
case QUICK_ACTION:
|
case QUICK_ACTION:
|
||||||
item = new QuickActionSettingsItem(settings, json);
|
item = new QuickActionSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
case POI_UI_FILTERS:
|
case POI_UI_FILTERS:
|
||||||
item = new PoiUiFilterSettingsItem(app, json);
|
item = new PoiUiFilterSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
case MAP_SOURCES:
|
case MAP_SOURCES:
|
||||||
item = new MapSourcesSettingsItem(settings, json);
|
item = new MapSourcesSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
@ -1286,8 +1303,8 @@ public class SettingsHelper {
|
||||||
while ((entry = zis.getNextEntry()) != null) {
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
String fileName = entry.getName();
|
String fileName = entry.getName();
|
||||||
SettingsItem item = itemsFactory.getItemByFileName(fileName);
|
SettingsItem item = itemsFactory.getItemByFileName(fileName);
|
||||||
if (item != null && collecting && item.shouldReadInCollecting()
|
if (item != null && collecting && item.shouldReadOnCollecting()
|
||||||
|| item != null && !collecting && !item.shouldReadInCollecting()) {
|
|| item != null && !collecting && !item.shouldReadOnCollecting()) {
|
||||||
try {
|
try {
|
||||||
item.getReader().readFromStream(ois);
|
item.getReader().readFromStream(ois);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -1318,7 +1335,7 @@ public class SettingsHelper {
|
||||||
private File file;
|
private File file;
|
||||||
private String latestChanges;
|
private String latestChanges;
|
||||||
private int version;
|
private int version;
|
||||||
private Boolean isCollecting;
|
private boolean collectOnly;
|
||||||
|
|
||||||
private SettingsImportListener listener;
|
private SettingsImportListener listener;
|
||||||
private SettingsImporter importer;
|
private SettingsImporter importer;
|
||||||
|
@ -1333,7 +1350,7 @@ public class SettingsHelper {
|
||||||
this.latestChanges = latestChanges;
|
this.latestChanges = latestChanges;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
importer = new SettingsImporter(app);
|
importer = new SettingsImporter(app);
|
||||||
isCollecting = true;
|
collectOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportAsyncTask(@NonNull File settingsFile, @NonNull List<SettingsItem> items, String latestChanges, int version, @Nullable SettingsImportListener listener) {
|
ImportAsyncTask(@NonNull File settingsFile, @NonNull List<SettingsItem> items, String latestChanges, int version, @Nullable SettingsImportListener listener) {
|
||||||
|
@ -1343,7 +1360,7 @@ public class SettingsHelper {
|
||||||
this.latestChanges = latestChanges;
|
this.latestChanges = latestChanges;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
importer = new SettingsImporter(app);
|
importer = new SettingsImporter(app);
|
||||||
isCollecting = false;
|
collectOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1358,7 +1375,7 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<SettingsItem> doInBackground(Void... voids) {
|
protected List<SettingsItem> doInBackground(Void... voids) {
|
||||||
if (isCollecting) {
|
if (collectOnly) {
|
||||||
try {
|
try {
|
||||||
return importer.collectItems(file);
|
return importer.collectItems(file);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -1374,7 +1391,7 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<SettingsItem> items) {
|
protected void onPostExecute(List<SettingsItem> items) {
|
||||||
if (isCollecting) {
|
if (collectOnly) {
|
||||||
listener.onSettingsImportFinished(true, false, items);
|
listener.onSettingsImportFinished(true, false, items);
|
||||||
} else {
|
} else {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
|
|
|
@ -13,7 +13,6 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.widget.CompoundButtonCompat;
|
import android.support.v4.widget.CompoundButtonCompat;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.ContextThemeWrapper;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -26,10 +25,12 @@ import android.widget.Toast;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
import net.osmand.plus.SettingsHelper;
|
import net.osmand.plus.SettingsHelper;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
|
@ -231,21 +232,26 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TileSourceManager.TileSourceTemplate> tileSourceTemplates = new ArrayList<>();
|
List<ITileSource> iTileSources = new ArrayList<>();
|
||||||
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(false));
|
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
|
||||||
for (Map.Entry<String, String> entry : tileSourceEntries.entrySet()) {
|
for (Map.Entry<String, String> entry : tileSourceEntries.entrySet()) {
|
||||||
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + entry.getKey());
|
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + entry.getKey());
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
TileSourceManager.TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f);
|
ITileSource template;
|
||||||
if (template != null) {
|
if (f.getName().endsWith(SQLiteTileSource.EXT)) {
|
||||||
tileSourceTemplates.add(template);
|
template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
|
||||||
|
} else {
|
||||||
|
template = TileSourceManager.createTileSourceTemplate(f);
|
||||||
|
}
|
||||||
|
if (template != null && template.getUrlTemplate() != null) {
|
||||||
|
iTileSources.add(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tileSourceTemplates.isEmpty()) {
|
if (!iTileSources.isEmpty()) {
|
||||||
dataList.add(new AdditionalDataWrapper(
|
dataList.add(new AdditionalDataWrapper(
|
||||||
AdditionalDataWrapper.Type.MAP_SOURCES,
|
AdditionalDataWrapper.Type.MAP_SOURCES,
|
||||||
tileSourceTemplates
|
iTileSources
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +290,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||||
List<QuickAction> quickActions = new ArrayList<>();
|
List<QuickAction> quickActions = new ArrayList<>();
|
||||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||||
List<TileSourceManager.TileSourceTemplate> tileSourceTemplates = new ArrayList<>();
|
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||||
for (Object object : dataToOperate) {
|
for (Object object : dataToOperate) {
|
||||||
if (object instanceof QuickAction) {
|
if (object instanceof QuickAction) {
|
||||||
quickActions.add((QuickAction) object);
|
quickActions.add((QuickAction) object);
|
||||||
|
@ -303,7 +309,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app, poiUIFilters));
|
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app, poiUIFilters));
|
||||||
}
|
}
|
||||||
if (!tileSourceTemplates.isEmpty()) {
|
if (!tileSourceTemplates.isEmpty()) {
|
||||||
settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(app.getSettings(), tileSourceTemplates));
|
settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(app, tileSourceTemplates));
|
||||||
}
|
}
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +332,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||||
List<QuickAction> quickActions = new ArrayList<>();
|
List<QuickAction> quickActions = new ArrayList<>();
|
||||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||||
List<TileSourceManager.TileSourceTemplate> tileSourceTemplates = new ArrayList<>();
|
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||||
List<File> routingFilesList = new ArrayList<>();
|
List<File> routingFilesList = new ArrayList<>();
|
||||||
List<File> renderFilesList = new ArrayList<>();
|
List<File> renderFilesList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -634,7 +640,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, profileColor));
|
icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, profileColor));
|
||||||
break;
|
break;
|
||||||
case MAP_SOURCES:
|
case MAP_SOURCES:
|
||||||
title.setText(((TileSourceManager.TileSourceTemplate) currentItem).getName());
|
title.setText(((ITileSource) currentItem).getName());
|
||||||
icon.setVisibility(View.INVISIBLE);
|
icon.setVisibility(View.INVISIBLE);
|
||||||
icon.setImageResource(R.drawable.ic_action_info_dark);
|
icon.setImageResource(R.drawable.ic_action_info_dark);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue