Use dev url
This commit is contained in:
parent
f8012eb8d2
commit
89d43ece79
12 changed files with 123 additions and 73 deletions
|
@ -25,16 +25,16 @@ public class OsmOAuthAuthorizationClient {
|
|||
private final OsmAndJDKHttpClient httpClient;
|
||||
public final static Log log = PlatformUtil.getLog(OsmOAuthAuthorizationClient.class);
|
||||
|
||||
public OsmOAuthAuthorizationClient(String key, String secret) {
|
||||
public OsmOAuthAuthorizationClient(String key, String secret, DefaultApi10a api) {
|
||||
httpClient = new OsmAndJDKHttpClient(JDKHttpClientConfig.defaultConfig());
|
||||
service = new ServiceBuilder(key)
|
||||
.apiSecret(secret)
|
||||
.httpClient(httpClient)
|
||||
.callback("osmand-oauth://example.com/oauth")
|
||||
.build(new OsmApi());
|
||||
.build(api);
|
||||
}
|
||||
|
||||
static class OsmApi extends DefaultApi10a {
|
||||
public static class OsmApi extends DefaultApi10a {
|
||||
@Override
|
||||
public OAuth1SignatureType getSignatureType() {
|
||||
return OAuth1SignatureType.QUERY_STRING;
|
||||
|
@ -56,6 +56,28 @@ public class OsmOAuthAuthorizationClient {
|
|||
}
|
||||
}
|
||||
|
||||
public static class OsmDevApi extends DefaultApi10a {
|
||||
@Override
|
||||
public OAuth1SignatureType getSignatureType() {
|
||||
return OAuth1SignatureType.QUERY_STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestTokenEndpoint() {
|
||||
return "https://master.apis.dev.openstreetmap.org/oauth/request_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint() {
|
||||
return "https://master.apis.dev.openstreetmap.org/oauth/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAuthorizationBaseUrl() {
|
||||
return "https://master.apis.dev.openstreetmap.org/oauth/authorize";
|
||||
}
|
||||
}
|
||||
|
||||
public OsmAndJDKHttpClient getHttpClient() {
|
||||
return httpClient;
|
||||
}
|
||||
|
|
|
@ -207,14 +207,10 @@ android {
|
|||
buildTypes {
|
||||
debug {
|
||||
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
|
||||
buildConfigField "String", "OSM_OAUTH_CONSUMER_KEY", "\"Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y\""
|
||||
buildConfigField "String", "OSM_OAUTH_CONSUMER_SECRET", "\"lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM\""
|
||||
signingConfig signingConfigs.development
|
||||
}
|
||||
release {
|
||||
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
|
||||
buildConfigField "String", "OSM_OAUTH_CONSUMER_KEY", "\"Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y\""
|
||||
buildConfigField "String", "OSM_OAUTH_CONSUMER_SECRET", "\"lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM\""
|
||||
if (gradle.startParameter.taskNames.toString().contains("huawei")) {
|
||||
signingConfig signingConfigs.publishingHuawei
|
||||
} else {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="use_dev_url">Use dev.openstreetmap.org</string>
|
||||
<string name="use_dev_url_descr">Switch to use "dev.openstreetmap.org" instead of "openstreetmap.org" to testing uploading OSM Note / POI / GPX.</string>
|
||||
<string name="app_mode_motorboat">Motorboat</string>
|
||||
<string name="app_mode_kayak">Kayak</string>
|
||||
<string name="shared_string_search_history">Search history</string>
|
||||
|
|
|
@ -32,6 +32,14 @@
|
|||
android:title="@string/offline_edition"
|
||||
tools:icon="@drawable/ic_action_offline" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||
android:key="use_dev_url"
|
||||
android:layout="@layout/preference_with_descr_dialog_and_switch"
|
||||
android:summaryOff="@string/shared_string_disabled"
|
||||
android:summaryOn="@string/shared_string_enabled"
|
||||
android:title="@string/use_dev_url"
|
||||
tools:icon="@drawable/ic_action_laptop" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
|
|
@ -13,4 +13,9 @@ public interface OsmAndConstants {
|
|||
|
||||
public int UI_HANDLER_SEARCH = 7000;
|
||||
|
||||
String OSM_OAUTH_DEVELOPER_KEY = "v8G8r9NLJZGMV4he5lwbQlz620FNVARKjI9Bm5UJ";
|
||||
String OSM_OAUTH_DEVELOPER_SECRET = "jDvM95Ne1Bq2BDTmIfB6b3ZMxvdK87WGfp6DC07J";
|
||||
String OSM_OAUTH_CONSUMER_KEY = "Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y";
|
||||
String OSM_OAUTH_CONSUMER_SECRET = "lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM";
|
||||
|
||||
}
|
||||
|
|
|
@ -66,33 +66,19 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
|||
|
||||
@Override
|
||||
public EntityInfo getEntityInfo(long id) {
|
||||
if(entityInfoId != null && entityInfoId.getId().longValue() == id) {
|
||||
if (entityInfoId != null && entityInfoId.getId().longValue() == id) {
|
||||
return entityInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getSiteApi() {
|
||||
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
String RETURN_API;
|
||||
|
||||
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
|
||||
RETURN_API = "https://api.openstreetmap.org/";
|
||||
} else {
|
||||
RETURN_API = "http://api.openstreetmap.org/";
|
||||
}
|
||||
|
||||
// RETURN_API = "http://api06.dev.openstreetmap.org/";
|
||||
|
||||
return RETURN_API;
|
||||
private String getSiteApi() {
|
||||
return settings.getOsmUrl();
|
||||
}
|
||||
|
||||
private final static String URL_TO_UPLOAD_GPX = getSiteApi() + "api/0.6/gpx/create";
|
||||
|
||||
public String uploadGPXFile(String tagstring, String description, String visibility, File f) {
|
||||
OsmOAuthAuthorizationAdapter adapter = new OsmOAuthAuthorizationAdapter(ctx);
|
||||
String url = URL_TO_UPLOAD_GPX;
|
||||
String url = getSiteApi() + "api/0.6/gpx/create";
|
||||
Map<String, String> additionalData = new LinkedHashMap<String, String>();
|
||||
additionalData.put("description", description);
|
||||
additionalData.put("tags", tagstring);
|
||||
|
|
|
@ -248,15 +248,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
}
|
||||
|
||||
protected List<OpenStreetNote> loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
|
||||
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
String SITE_API;
|
||||
|
||||
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
|
||||
SITE_API = "https://api.openstreetmap.org/";
|
||||
} else {
|
||||
SITE_API = "http://api.openstreetmap.org/";
|
||||
}
|
||||
String SITE_API = activity.getMyApplication().getSettings().getOsmUrl();
|
||||
|
||||
List<OpenStreetNote> bugs = new ArrayList<>();
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
|
|
@ -26,26 +26,12 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
private static final String GET = "GET";
|
||||
private static final String POST = "POST";
|
||||
|
||||
static String getNotesApi() {
|
||||
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
|
||||
String RETURN_API;
|
||||
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
|
||||
RETURN_API = "https://api.openstreetmap.org/api/0.6/notes";
|
||||
} else {
|
||||
RETURN_API = "http://api.openstreetmap.org/api/0.6/notes";
|
||||
}
|
||||
return RETURN_API;
|
||||
String getNotesApi() {
|
||||
return settings.getOsmUrl() + "api/0.6/notes";
|
||||
}
|
||||
|
||||
static String getUserDetailsApi() {
|
||||
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
|
||||
String RETURN_API;
|
||||
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
|
||||
RETURN_API = "https://api.openstreetmap.org/api/0.6/user/details";
|
||||
} else {
|
||||
RETURN_API = "http://api.openstreetmap.org/api/0.6/user/details";
|
||||
}
|
||||
return RETURN_API;
|
||||
String getUserDetailsApi() {
|
||||
return settings.getOsmUrl() + "api/0.6/user/details";
|
||||
}
|
||||
|
||||
private OsmandApplication app;
|
||||
|
|
|
@ -43,6 +43,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
private static final String OPEN_OSM_EDITS = "open_osm_edits";
|
||||
public static final String OSM_LOGIN_DATA = "osm_login_data";
|
||||
private static final String OSM_EDITING_INFO = "osm_editing_info";
|
||||
private static final String USE_DEV_URL = "use_dev_url";
|
||||
|
||||
private OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
|
||||
|
@ -61,6 +62,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
setupLogoutPref();
|
||||
|
||||
setupOfflineEditingPref();
|
||||
setupUseDevUrlPref();
|
||||
setupOsmEditsDescrPref();
|
||||
setupOsmEditsPref();
|
||||
}
|
||||
|
@ -129,6 +131,13 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
offlineEditingPref.setIcon(icon);
|
||||
}
|
||||
|
||||
private void setupUseDevUrlPref() {
|
||||
Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_laptop);
|
||||
SwitchPreferenceEx useDevUrlPref = findPreference(settings.USE_DEV_URL.getId());
|
||||
useDevUrlPref.setDescription(getString(R.string.use_dev_url_descr));
|
||||
useDevUrlPref.setIcon(icon);
|
||||
}
|
||||
|
||||
private void setupOsmEditsDescrPref() {
|
||||
String menu = getString(R.string.shared_string_menu);
|
||||
String myPlaces = getString(R.string.shared_string_my_places);
|
||||
|
@ -152,6 +161,18 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
createProfile.setIcon(getActiveIcon(R.drawable.ic_action_folder));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String prefId = preference.getKey();
|
||||
if (USE_DEV_URL.equals(prefId) && newValue instanceof Boolean) {
|
||||
settings.USE_DEV_URL.set((Boolean) newValue);
|
||||
osmLogout();
|
||||
authorizationAdapter = app.getOsmOAuthHelper().updateAdapter();
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String prefId = preference.getKey();
|
||||
|
@ -172,22 +193,25 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
return true;
|
||||
}
|
||||
} else if (OSM_LOGOUT.equals(prefId)) {
|
||||
if (isValidToken()) {
|
||||
settings.USER_ACCESS_TOKEN.resetToDefault();
|
||||
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
|
||||
|
||||
authorizationAdapter.resetToken();
|
||||
} else {
|
||||
settings.USER_NAME.resetToDefault();
|
||||
settings.USER_PASSWORD.resetToDefault();
|
||||
}
|
||||
app.showShortToastMessage(R.string.osm_edit_logout_success);
|
||||
updateAllSettings();
|
||||
osmLogout();
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
private void osmLogout() {
|
||||
if (isValidToken()) {
|
||||
settings.USER_ACCESS_TOKEN.resetToDefault();
|
||||
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
|
||||
authorizationAdapter.resetToken();
|
||||
} else {
|
||||
settings.USER_NAME.resetToDefault();
|
||||
settings.USER_PASSWORD.resetToDefault();
|
||||
}
|
||||
app.showShortToastMessage(R.string.osm_edit_logout_success);
|
||||
updateAllSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreferenceChanged(String prefId) {
|
||||
updateAllSettings();
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.github.scribejava.core.builder.api.DefaultApi10a;
|
||||
import com.github.scribejava.core.model.OAuth1AccessToken;
|
||||
import com.github.scribejava.core.model.OAuth1RequestToken;
|
||||
import com.github.scribejava.core.model.OAuthAsyncRequestCallback;
|
||||
|
@ -13,7 +14,7 @@ import com.github.scribejava.core.model.Verb;
|
|||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.BuildConfig;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -27,15 +28,25 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
private static final int THREAD_ID = 10101;
|
||||
private static final String OSM_USER = "user";
|
||||
private static final String DISPLAY_NAME = "display_name";
|
||||
private static final String OSM_USER_DETAILS_URL = "https://api.openstreetmap.org/api/0.6/user/details";
|
||||
|
||||
private OsmandApplication app;
|
||||
private OsmOAuthAuthorizationClient client =
|
||||
new OsmOAuthAuthorizationClient(BuildConfig.OSM_OAUTH_CONSUMER_KEY, BuildConfig.OSM_OAUTH_CONSUMER_SECRET);
|
||||
private final OsmOAuthAuthorizationClient client;
|
||||
|
||||
public OsmOAuthAuthorizationAdapter(OsmandApplication app) {
|
||||
TrafficStats.setThreadStatsTag(THREAD_ID);
|
||||
this.app = app;
|
||||
DefaultApi10a api10a;
|
||||
String key;
|
||||
String secret;
|
||||
if (app.getSettings().USE_DEV_URL.get()) {
|
||||
api10a = new OsmOAuthAuthorizationClient.OsmDevApi();
|
||||
key = OsmAndConstants.OSM_OAUTH_DEVELOPER_KEY;
|
||||
secret = OsmAndConstants.OSM_OAUTH_DEVELOPER_SECRET;
|
||||
} else {
|
||||
api10a = new OsmOAuthAuthorizationClient.OsmApi();
|
||||
key = OsmAndConstants.OSM_OAUTH_CONSUMER_KEY;
|
||||
secret = OsmAndConstants.OSM_OAUTH_CONSUMER_SECRET;
|
||||
}
|
||||
client = new OsmOAuthAuthorizationClient(key, secret, api10a);
|
||||
restoreToken();
|
||||
}
|
||||
|
||||
|
@ -104,7 +115,8 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
}
|
||||
|
||||
public Response getOsmUserDetails() throws InterruptedException, ExecutionException, IOException {
|
||||
return performRequest(OSM_USER_DETAILS_URL, Verb.GET.name(), null);
|
||||
String osmUserDetailsUrl = app.getSettings().getOsmUrl() + "api/0.6/user/details";
|
||||
return performRequest(osmUserDetailsUrl, Verb.GET.name(), null);
|
||||
}
|
||||
|
||||
public String parseUserName(Response response) throws XmlPullParserException, IOException {
|
||||
|
|
|
@ -19,13 +19,18 @@ public class OsmOAuthHelper {
|
|||
|
||||
private final OsmandApplication app;
|
||||
|
||||
private final OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
private OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
|
||||
public OsmOAuthHelper(@NonNull OsmandApplication app) {
|
||||
this.app = app;
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
}
|
||||
|
||||
public OsmOAuthAuthorizationAdapter updateAdapter(){
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
return authorizationAdapter;
|
||||
}
|
||||
|
||||
public void startOAuth(ViewGroup view) {
|
||||
authorizationAdapter.startOAuth(view);
|
||||
}
|
||||
|
|
|
@ -1133,6 +1133,17 @@ public class OsmandSettings {
|
|||
|
||||
// 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> USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
|
||||
|
||||
public String getOsmUrl() {
|
||||
String osmUrl;
|
||||
if (USE_DEV_URL.get()) {
|
||||
osmUrl = "https://master.apis.dev.openstreetmap.org/";
|
||||
} else {
|
||||
osmUrl = "https://api.openstreetmap.org/";
|
||||
}
|
||||
return osmUrl;
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<DayNightMode> DAYNIGHT_MODE =
|
||||
|
|
Loading…
Reference in a new issue