add online source from url

This commit is contained in:
veliymolfar 2020-06-11 18:06:48 +03:00
parent 26c4bd276b
commit b6c8ab7362
2 changed files with 25 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.map.TileSourceManager;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandApplication;
@ -109,8 +110,8 @@ public class IntentHelper {
if (!attrs.isEmpty()) {
try {
TileSourceManager.TileSourceTemplate r = TileSourceManager.createTileSourceTemplate(attrs);
if (r != null && settings.installTileSource(r)) {
app.showShortToastMessage(app.getString(R.string.edit_tilesource_successfully, r.getName()));
if (r != null) {
EditMapSourceDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), r);
}
} catch (Exception e) {
LOG.error("parseAddTileSourceIntent error", e);

View file

@ -77,6 +77,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
private static final String EXPIRE_TIME_KEY = "expire_time_key";
private static final String ELLIPTIC_KEY = "elliptic_key";
private static final String SQLITE_DB_KEY = "sqlite_db_key";
private static final String FROM_TEMPLATE_KEY = "from_template_key";
private OsmandApplication app;
private TextInputEditText nameEditText;
private TextInputEditText urlEditText;
@ -93,6 +94,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
private boolean elliptic = false;
private boolean sqliteDB = false;
private boolean nightMode;
private boolean fromTemplate = false;
public static void showInstance(@NonNull FragmentManager fm,
@Nullable Fragment targetFragment,
@ -103,6 +105,14 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
fragment.show(fm, TAG);
}
public static void showInstance(@NonNull FragmentManager fm,
@NonNull TileSourceTemplate template) {
EditMapSourceDialogFragment fragment = new EditMapSourceDialogFragment();
fragment.setTemplate(template);
fragment.fromTemplate = true;
fragment.show(fm, TAG);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -119,6 +129,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
expireTimeMinutes = savedInstanceState.getInt(EXPIRE_TIME_KEY);
elliptic = savedInstanceState.getBoolean(ELLIPTIC_KEY);
sqliteDB = savedInstanceState.getBoolean(SQLITE_DB_KEY);
fromTemplate = savedInstanceState.getBoolean(FROM_TEMPLATE_KEY);
}
View root = UiUtilities.getMaterialInflater(requireContext(), nightMode).inflate(R.layout.fragment_edit_map_source, container, false);
Toolbar toolbar = root.findViewById(R.id.toolbar);
@ -172,8 +183,10 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
dismiss();
}
});
template = new TileSourceTemplate("", "", PNG_EXT, MAX_ZOOM, MIN_ZOOM, TILE_SIZE, BIT_DENSITY, AVG_SIZE);
if (editedLayerName != null) {
if (template == null) {
template = new TileSourceTemplate("", "", PNG_EXT, MAX_ZOOM, MIN_ZOOM, TILE_SIZE, BIT_DENSITY, AVG_SIZE);
}
if (editedLayerName != null && !fromTemplate) {
if (!editedLayerName.endsWith(IndexConstants.SQLITE_EXT)) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + editedLayerName);
template = TileSourceManager.createTileSourceTemplate(f);
@ -194,6 +207,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
}
}
if (savedInstanceState == null) {
editedLayerName = template.getName();
urlToLoad = template.getUrlTemplate();
expireTimeMinutes = template.getExpirationTimeMinutes();
minZoom = template.getMinimumZoomSupported();
@ -212,6 +226,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
outState.putInt(EXPIRE_TIME_KEY, expireTimeMinutes);
outState.putBoolean(ELLIPTIC_KEY, elliptic);
outState.putBoolean(SQLITE_DB_KEY, sqliteDB);
outState.putBoolean(FROM_TEMPLATE_KEY, fromTemplate);
super.onSaveInstanceState(outState);
}
@ -408,7 +423,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
InputZoomLevelsBottomSheet.showInstance(
fm, EditMapSourceDialogFragment.this,
R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr,
minZoom, maxZoom, editedLayerName == null
minZoom, maxZoom, editedLayerName == null && !fromTemplate
);
break;
case EXPIRE_TIME:
@ -464,6 +479,10 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
this.editedLayerName = editedLayerName;
}
public void setTemplate(TileSourceTemplate template) {
this.template = template;
}
public interface OnMapSourceUpdateListener {
void onMapSourceUpdated();
}