Add ability to switch to dev server

This commit is contained in:
Vitaliy 2021-02-03 13:24:20 +02:00
parent 43f326e320
commit fd8afa15b3
3 changed files with 23 additions and 14 deletions

View file

@ -2,11 +2,15 @@ package net.osmand.plus.mapcontextmenu.builders.cards;
import android.view.View;
import androidx.core.content.ContextCompat;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
@ -22,7 +26,7 @@ public class IPFSImageCard extends ImageCard {
} catch (JSONException e) {
LOG.error(e);
}
String BASE_URL = mapActivity.getString(R.string.opr_base_url) + "api/ipfs/image-ipfs?cid=";
String BASE_URL = OPRConstants.getBaseUrl(mapActivity.getMyApplication()) + "api/ipfs/image-ipfs?cid=";
url = BASE_URL + cid;
imageHiresUrl = BASE_URL + cid;
imageUrl = BASE_URL + cid;

View file

@ -1,9 +1,9 @@
package net.osmand.plus.openplacereviews;
import android.content.Context;
import androidx.annotation.NonNull;
import net.osmand.plus.R;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.osmedit.opr.OpenDBAPI;
public class OPRConstants {
@ -11,28 +11,27 @@ public class OPRConstants {
private static final String PURPOSE = OpenDBAPI.PURPOSE;
private static final String CALLBACK_URL = OPR_OAUTH_PREFIX + "://osmand_opr_auth";
public static String getBaseUrl(Context ctx) {
return ctx.getString(R.string.opr_base_url);
public static String getBaseUrl(@NonNull OsmandApplication app) {
return app.getSettings().getOprUrl();
}
public static String getLoginUrl(Context ctx) {
return getBaseUrl(ctx) + "login" + getQueryString(ctx);
public static String getLoginUrl(@NonNull OsmandApplication app) {
return getBaseUrl(app) + "login" + getQueryString();
}
public static String getRegisterUrl(Context ctx) {
return getBaseUrl(ctx) + "signup" + getQueryString(ctx);
public static String getRegisterUrl(@NonNull OsmandApplication app) {
return getBaseUrl(app) + "signup" + getQueryString();
}
public static String getQueryString(Context ctx) {
return "?" + getPurposeParam(ctx) + "&" + getCallbackParam(ctx);
public static String getQueryString() {
return "?" + getPurposeParam() + "&" + getCallbackParam();
}
public static String getPurposeParam(Context ctx) {
public static String getPurposeParam() {
return "purpose=" + PURPOSE;
}
public static String getCallbackParam(Context ctx) {
public static String getCallbackParam() {
return "callback=" + CALLBACK_URL;
}
}

View file

@ -1174,6 +1174,8 @@ public class OsmandSettings {
public final OsmandPreference<String> OPR_BLOCKCHAIN_NAME =
new StringPreference(this, "opr_blockchain_name", "").makeGlobal();
public final OsmandPreference<Boolean> OPR_USE_DEV_URL = new BooleanPreference(this, "opr_use_dev_url", false).makeGlobal().makeShared();
// this value boolean is synchronized with settings_pref.xml preference offline POI/Bugs edition
public final OsmandPreference<Boolean> OFFLINE_EDITION = new BooleanPreference(this, "offline_osm_editing", true).makeGlobal().makeShared();
public final OsmandPreference<Boolean> OSM_USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
@ -1188,6 +1190,10 @@ public class OsmandSettings {
return osmUrl;
}
public String getOprUrl() {
return ctx.getString(OPR_USE_DEV_URL.get() ? R.string.dev_opr_base_url : R.string.opr_base_url);
}
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<DayNightMode> DAYNIGHT_MODE =
new EnumStringPreference<DayNightMode>(this, "daynight_mode", DayNightMode.DAY, DayNightMode.values());