Merge pull request #8436 from osmandapp/Fix_7752
Fix 7752 Add edit online sources.
This commit is contained in:
commit
4b403a00b8
3 changed files with 81 additions and 25 deletions
|
@ -25,9 +25,13 @@ import java.util.List;
|
|||
|
||||
public class SQLiteTileSource implements ITileSource {
|
||||
|
||||
|
||||
public static final String EXT = IndexConstants.SQLITE_EXT;
|
||||
private static final Log LOG = PlatformUtil.getLog(SQLiteTileSource.class);
|
||||
private static final String MAXZOOM_FIELD = "maxzoom";
|
||||
private static final String MINZOOM_FIELD = "minzoom";
|
||||
private static final String ELLIPSOID_FIELD = "ellipsoid";
|
||||
private static final String URL_FIELD = "url";
|
||||
private static final String EXPIREMINUTES_FIELD = "expireminutes";
|
||||
|
||||
private ITileSource base;
|
||||
private String urlTemplate = null;
|
||||
|
@ -163,7 +167,7 @@ public class SQLiteTileSource implements ITileSource {
|
|||
if(cursor.moveToFirst()) {
|
||||
String[] columnNames = cursor.getColumnNames();
|
||||
List<String> list = Arrays.asList(columnNames);
|
||||
int url = list.indexOf("url");
|
||||
int url = list.indexOf(URL_FIELD);
|
||||
if(url != -1) {
|
||||
String template = cursor.getString(url);
|
||||
if(!Algorithms.isEmpty(template)){
|
||||
|
@ -192,7 +196,7 @@ public class SQLiteTileSource implements ITileSource {
|
|||
timeSupported = hasTimeColumn();
|
||||
addInfoColumn("timecolumn", timeSupported? "yes" : "no");
|
||||
}
|
||||
int expireminutes = list.indexOf("expireminutes");
|
||||
int expireminutes = list.indexOf(EXPIREMINUTES_FIELD);
|
||||
this.expirationTimeMillis = -1;
|
||||
if(expireminutes != -1) {
|
||||
int minutes = (int) cursor.getInt(expireminutes);
|
||||
|
@ -200,14 +204,14 @@ public class SQLiteTileSource implements ITileSource {
|
|||
this.expirationTimeMillis = minutes * 60 * 1000l;
|
||||
}
|
||||
} else {
|
||||
addInfoColumn("expireminutes", "0");
|
||||
addInfoColumn(EXPIREMINUTES_FIELD, "0");
|
||||
}
|
||||
int tsColumn = list.indexOf("tilesize");
|
||||
this.tileSizeSpecified = tsColumn != -1;
|
||||
if(tileSizeSpecified) {
|
||||
this.tileSize = (int) cursor.getInt(tsColumn);
|
||||
}
|
||||
int ellipsoid = list.indexOf("ellipsoid");
|
||||
int ellipsoid = list.indexOf(ELLIPSOID_FIELD);
|
||||
if(ellipsoid != -1) {
|
||||
int set = (int) cursor.getInt(ellipsoid);
|
||||
if(set == 1){
|
||||
|
@ -225,15 +229,14 @@ public class SQLiteTileSource implements ITileSource {
|
|||
if(randomsId != -1) {
|
||||
this.randoms = cursor.getString(randomsId);
|
||||
this.randomsArray = TileSourceTemplate.buildRandomsArray(this.randoms);
|
||||
|
||||
}
|
||||
//boolean inversiveInfoZoom = tnumbering != -1 && "BigPlanet".equals(cursor.getString(tnumbering));
|
||||
boolean inversiveInfoZoom = inversiveZoom;
|
||||
int mnz = list.indexOf("minzoom");
|
||||
int mnz = list.indexOf(MINZOOM_FIELD);
|
||||
if(mnz != -1) {
|
||||
minZoom = (int) cursor.getInt(mnz);
|
||||
}
|
||||
int mxz = list.indexOf("maxzoom");
|
||||
int mxz = list.indexOf(MAXZOOM_FIELD);
|
||||
if(mxz != -1) {
|
||||
maxZoom = (int) cursor.getInt(mxz);
|
||||
}
|
||||
|
@ -251,6 +254,33 @@ public class SQLiteTileSource implements ITileSource {
|
|||
return db;
|
||||
}
|
||||
|
||||
public void updateFromTileSourceTemplate(TileSourceTemplate r) {
|
||||
if (!onlyReadonlyAvailable) {
|
||||
int maxZoom = r.getMaximumZoomSupported();
|
||||
int minZoom = r.getMinimumZoomSupported();
|
||||
if (inversiveZoom) {
|
||||
int mnz = minZoom;
|
||||
minZoom = 17 - maxZoom;
|
||||
maxZoom = 17 - mnz;
|
||||
}
|
||||
if (getUrlTemplate() != null && !getUrlTemplate().equals(r.getUrlTemplate())) {
|
||||
db.execSQL("update info set " + URL_FIELD + " = '" + r.getUrlTemplate() + "'");
|
||||
}
|
||||
if (r.getMinimumZoomSupported() != minZoom) {
|
||||
db.execSQL("update info set " + MINZOOM_FIELD + " = '" + minZoom + "'");
|
||||
}
|
||||
if (r.getMaximumZoomSupported() != maxZoom) {
|
||||
db.execSQL("update info set " + MAXZOOM_FIELD + " = '" + maxZoom + "'");
|
||||
}
|
||||
if (r.isEllipticYTile() != isEllipticYTile()) {
|
||||
db.execSQL("update info set " + ELLIPSOID_FIELD + " = '" + (r.isEllipticYTile() ? 1 : 0) + "'");
|
||||
}
|
||||
if (r.getExpirationTimeMinutes() != getExpirationTimeMinutes()) {
|
||||
db.execSQL("update info set " + EXPIREMINUTES_FIELD + " = '" + r.getExpirationTimeMinutes() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addInfoColumn(String columnName, String value) {
|
||||
if (!onlyReadonlyAvailable) {
|
||||
db.execSQL("alter table info add column " + columnName + " TEXT");
|
||||
|
@ -517,7 +547,9 @@ public class SQLiteTileSource implements ITileSource {
|
|||
return referer;
|
||||
}
|
||||
|
||||
|
||||
public String getUrlTemplate() {
|
||||
return urlTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.map.TileSourceManager;
|
|||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -252,7 +253,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
getDownloadActivity().reloadLocalIndexes();
|
||||
return true;
|
||||
}
|
||||
}, info.getName());
|
||||
}, info.getFileName());
|
||||
} else if (resId == R.string.local_index_mi_restore) {
|
||||
new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.RESTORE_OPERATION).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info);
|
||||
} else if (resId == R.string.shared_string_delete) {
|
||||
|
@ -1237,7 +1238,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
});
|
||||
if (info.getType() == LocalIndexType.TILES_DATA
|
||||
&& (info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate)) {
|
||||
&& ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate)
|
||||
|| ((info.getAttachedObject() instanceof SQLiteTileSource)
|
||||
&& ((SQLiteTileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()))) {
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_edit)
|
||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
|
|
|
@ -36,6 +36,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.DownloadTilesDialog;
|
||||
|
@ -478,10 +479,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public static void defineNewEditLayer(final Activity activity, final ResultMatcher<TileSourceTemplate> resultMatcher, String editedLayerName) {
|
||||
public static void defineNewEditLayer(final Activity activity, final ResultMatcher<TileSourceTemplate> resultMatcher, final String editedLayerName) {
|
||||
final OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
final OsmandSettings settings = app.getSettings();
|
||||
final Map<String, String> entriesMap = settings.getTileSourceEntries(false);
|
||||
final Map<String, String> entriesMap = settings.getTileSourceEntries(true);
|
||||
final SQLiteTileSource[] sqLiteTileSource = new SQLiteTileSource[1];
|
||||
boolean nightMode = isNightMode(activity, app);
|
||||
final int dp8 = AndroidUtils.dpToPx(app, 8f);
|
||||
int textColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light);
|
||||
|
@ -512,10 +514,25 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
existing.setAdapter(adapter);
|
||||
TileSourceTemplate template;
|
||||
if (editedLayerName != null) {
|
||||
if (!editedLayerName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
File f = ((OsmandApplication) activity.getApplication()).getAppPath(
|
||||
IndexConstants.TILES_INDEX_DIR + editedLayerName);
|
||||
TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f);
|
||||
template = TileSourceManager.createTileSourceTemplate(f);
|
||||
} else {
|
||||
List<TileSourceTemplate> knownTemplates = TileSourceManager.getKnownSourceTemplates();
|
||||
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
File dir = new File(tPath, editedLayerName);
|
||||
sqLiteTileSource[0] = new SQLiteTileSource(app, dir, knownTemplates);
|
||||
sqLiteTileSource[0].couldBeDownloadedFromInternet();
|
||||
template = new TileSourceManager.TileSourceTemplate(sqLiteTileSource[0].getName(),
|
||||
sqLiteTileSource[0].getUrlTemplate(), "png", sqLiteTileSource[0].getMaximumZoomSupported(),
|
||||
sqLiteTileSource[0].getMinimumZoomSupported(), sqLiteTileSource[0].getTileSize(),
|
||||
sqLiteTileSource[0].getBitDensity(), 32000);
|
||||
template.setExpirationTimeMinutes(sqLiteTileSource[0].getExpirationTimeMinutes());
|
||||
template.setEllipticYTile(sqLiteTileSource[0].isEllipticYTile());
|
||||
}
|
||||
if (template != null) {
|
||||
result[0] = template.copy();
|
||||
updateTileSourceEditView(result[0], name, urlToLoad, minZoom, maxZoom, expire, elliptic);
|
||||
|
@ -558,6 +575,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
r.setEllipticYTile(elliptic.isChecked());
|
||||
r.setUrlToLoad(urlToLoad.getText().toString().equals("") ? null : urlToLoad.getText().toString().replace("{$x}", "{1}")
|
||||
.replace("{$y}", "{2}").replace("{$z}", "{0}"));
|
||||
if (sqLiteTileSource[0] != null) {
|
||||
sqLiteTileSource[0].updateFromTileSourceTemplate(r);
|
||||
} else {
|
||||
if (r.getName().length() > 0) {
|
||||
if (settings.installTileSource(r)) {
|
||||
Toast.makeText(activity, activity.getString(R.string.edit_tilesource_successfully, r.getName()),
|
||||
|
@ -565,6 +585,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
resultMatcher.publish(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue