commit
62629478b6
12 changed files with 203 additions and 121 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;
|
||||
}
|
||||
|
|
|
@ -198,14 +198,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\""
|
||||
signingConfig signingConfigs.publishing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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="select_items_for_import">Select items that will be imported.</string>
|
||||
<string name="select_groups_for_import">Select groups that will be imported.</string>
|
||||
<string name="export_not_enough_space">There is not enough space</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" />
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
public interface OsmAndConstants {
|
||||
|
||||
|
||||
|
||||
|
||||
public int UI_HANDLER_MAP_VIEW = 3000;
|
||||
|
||||
|
||||
public int UI_HANDLER_MAP_CONTROLS = 4000;
|
||||
|
||||
|
||||
public int UI_HANDLER_LOCATION_SERVICE = 5000;
|
||||
|
||||
public int UI_HANDLER_PROGRESS = 6000;
|
||||
|
||||
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();
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
|
||||
import com.github.scribejava.core.model.Response;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.osm.io.Base64;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
|
@ -19,6 +22,8 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
||||
|
||||
|
@ -26,26 +31,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;
|
||||
|
@ -107,57 +98,82 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
return editingPOI(getUserDetailsApi(), GET, "validate_login", false);
|
||||
}
|
||||
|
||||
private OsmBugResult editingPOI(String url, String requestMethod, String userOperation,
|
||||
boolean anonymous) {
|
||||
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
|
||||
OsmBugResult r = new OsmBugResult();
|
||||
try {
|
||||
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
log.info("Editing poi " + url);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setRequestMethod(requestMethod);
|
||||
connection.setRequestProperty("User-Agent", Version.getFullVersion(app)); //$NON-NLS-1$
|
||||
|
||||
if (!anonymous) {
|
||||
if (client.isValidToken()) {
|
||||
connection.addRequestProperty("Authorization", "OAuth " + client.getClient().getAccessToken().getToken());
|
||||
} else {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
private OsmBugResult editingPOI(String url, String requestMethod, String userOperation, boolean anonymous) {
|
||||
OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
OsmBugResult result = new OsmBugResult();
|
||||
if (authorizationAdapter.isValidToken() && !anonymous) {
|
||||
try {
|
||||
result = performOAuthRequest(url, requestMethod, userOperation, authorizationAdapter);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
result.warning = e.getMessage();
|
||||
} catch (ExecutionException e) {
|
||||
log.error(e);
|
||||
result.warning = e.getMessage();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
result.warning = e.getMessage();
|
||||
}
|
||||
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
String msg = connection.getResponseMessage();
|
||||
boolean ok = connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||
log.info(msg); //$NON-NLS-1$
|
||||
// populate return fields.
|
||||
|
||||
StringBuilder responseBody;
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
|
||||
responseBody = Algorithms.readFromInputStream(connection.getErrorStream());
|
||||
} else {
|
||||
responseBody = Algorithms.readFromInputStream(connection.getInputStream());
|
||||
} else {
|
||||
try {
|
||||
result = performBasicRequest(url, requestMethod, anonymous);
|
||||
} catch (FileNotFoundException | NullPointerException e) {
|
||||
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
|
||||
String msg = app.getString(R.string.auth_failed);
|
||||
log.error(msg, e);
|
||||
result.warning = app.getString(R.string.auth_failed) + "";
|
||||
} catch (MalformedURLException e) {
|
||||
log.error(userOperation + " " + app.getString(R.string.failed_op), e);
|
||||
result.warning = e.getMessage() + "";
|
||||
} catch (IOException e) {
|
||||
log.error(userOperation + " " + app.getString(R.string.failed_op), e);
|
||||
result.warning = e.getMessage() + " link unavailable";
|
||||
}
|
||||
log.info("Response : " + responseBody); //$NON-NLS-1$
|
||||
connection.disconnect();
|
||||
if (!ok) {
|
||||
r.warning = msg + "\n" + responseBody;
|
||||
}
|
||||
} catch (FileNotFoundException | NullPointerException e) {
|
||||
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
|
||||
String msg = app.getString(R.string.auth_failed);
|
||||
log.error(msg, e);
|
||||
r.warning = app.getString(R.string.auth_failed) + "";
|
||||
} catch (MalformedURLException e) {
|
||||
log.error(userOperation + " " + app.getString(R.string.failed_op), e); //$NON-NLS-1$
|
||||
r.warning = e.getMessage() + "";
|
||||
} catch (IOException e) {
|
||||
log.error(userOperation + " " + app.getString(R.string.failed_op), e); //$NON-NLS-1$
|
||||
r.warning = e.getMessage() + " link unavailable";
|
||||
}
|
||||
return r;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
private OsmBugResult performBasicRequest(String url, String requestMethod, boolean anonymous) throws IOException {
|
||||
OsmBugResult result = new OsmBugResult();
|
||||
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
log.info("Editing poi " + url);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setRequestMethod(requestMethod);
|
||||
connection.setRequestProperty("User-Agent", Version.getFullVersion(app));
|
||||
if (!anonymous) {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get();
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
String msg = connection.getResponseMessage();
|
||||
boolean ok = connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||
log.info(msg);
|
||||
// populate return fields.
|
||||
|
||||
StringBuilder responseBody;
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
|
||||
responseBody = Algorithms.readFromInputStream(connection.getErrorStream());
|
||||
} else {
|
||||
responseBody = Algorithms.readFromInputStream(connection.getInputStream());
|
||||
}
|
||||
log.info("Response : " + responseBody);
|
||||
connection.disconnect();
|
||||
if (!ok) {
|
||||
result.warning = msg + "\n" + responseBody;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private OsmBugResult performOAuthRequest(String url, String requestMethod, String userOperation,
|
||||
OsmOAuthAuthorizationAdapter authorizationAdapter)
|
||||
throws InterruptedException, ExecutionException, IOException {
|
||||
OsmBugResult result = new OsmBugResult();
|
||||
OsmOAuthAuthorizationClient client = authorizationAdapter.getClient();
|
||||
Response response = client.performRequest(url, requestMethod, userOperation);
|
||||
if (response.getCode() != HttpURLConnection.HTTP_OK) {
|
||||
result.warning = response.getMessage() + "\n" + response.getBody();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ import androidx.fragment.app.FragmentManager;
|
|||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
@ -31,16 +30,12 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
|||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||
import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB;
|
||||
|
||||
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener,
|
||||
OsmAuthorizationListener {
|
||||
|
||||
private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class);
|
||||
|
||||
private static final String OSM_LOGOUT = "osm_logout";
|
||||
private static final String OPEN_OSM_EDITS = "open_osm_edits";
|
||||
public static final String OSM_LOGIN_DATA = "osm_login_data";
|
||||
|
@ -74,6 +69,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
setupLogoutPref();
|
||||
|
||||
setupOfflineEditingPref();
|
||||
setupUseDevUrlPref();
|
||||
setupOsmEditsDescrPref();
|
||||
setupOsmEditsPref();
|
||||
}
|
||||
|
@ -142,6 +138,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);
|
||||
|
@ -165,6 +168,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 (settings.USE_DEV_URL.getId().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();
|
||||
|
@ -185,10 +200,18 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
return true;
|
||||
}
|
||||
} else if (OSM_LOGOUT.equals(prefId)) {
|
||||
if (isValidToken()) {
|
||||
osmLogout();
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
private void osmLogout() {
|
||||
boolean validToken = isValidToken();
|
||||
if (validToken || isLoginExists()) {
|
||||
if (validToken) {
|
||||
settings.USER_ACCESS_TOKEN.resetToDefault();
|
||||
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
|
||||
|
||||
authorizationAdapter.resetToken();
|
||||
} else {
|
||||
settings.USER_NAME.resetToDefault();
|
||||
|
@ -196,13 +219,15 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
}
|
||||
app.showShortToastMessage(R.string.osm_edit_logout_success);
|
||||
updateAllSettings();
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreferenceChanged(String prefId) {
|
||||
if (settings.USE_DEV_URL.getId().equals(prefId)) {
|
||||
osmLogout();
|
||||
authorizationAdapter = app.getOsmOAuthHelper().updateAdapter();
|
||||
}
|
||||
updateAllSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.webkit.WebView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
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;
|
||||
|
@ -16,7 +17,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.apache.commons.logging.Log;
|
||||
|
@ -31,16 +32,27 @@ 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";
|
||||
public final static Log log = PlatformUtil.getLog(OsmOAuthAuthorizationAdapter.class);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -162,9 +174,10 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
return parseUserName(response);
|
||||
}
|
||||
|
||||
public Response getOsmUserDetails() throws InterruptedException, ExecutionException, IOException {
|
||||
return performRequest(OSM_USER_DETAILS_URL, Verb.GET.name(), null);
|
||||
}
|
||||
public Response getOsmUserDetails() throws InterruptedException, ExecutionException, IOException {
|
||||
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 {
|
||||
String userName = null;
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Set;
|
|||
public class OsmOAuthHelper {
|
||||
|
||||
private final OsmandApplication app;
|
||||
private final OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
private OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
private final Set<OsmAuthorizationListener> listeners = new HashSet<>();
|
||||
|
||||
public OsmOAuthHelper(@NonNull OsmandApplication app) {
|
||||
|
@ -24,6 +24,11 @@ public class OsmOAuthHelper {
|
|||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public OsmOAuthAuthorizationAdapter updateAdapter(){
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
return authorizationAdapter;
|
||||
}
|
||||
|
||||
public void removeListener(OsmAuthorizationListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
|
|
@ -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