Rename osm preferences

This commit is contained in:
Vitaliy 2021-02-03 13:07:34 +02:00
parent 2ef2ba43d6
commit 3fa52bf005
15 changed files with 57 additions and 62 deletions

View file

@ -12,6 +12,10 @@
-->
<string name="login_open_place_reviews">Login to OpenPlaceReviews</string>
<string name="opr_use_dev_url">Use test.openplacereviews.org</string>
<string name="open_place_reviews">OpenPlaceReviews</string>
<string name="open_place_reviews_plugin_description">OpenPlaceReviews is a community-driven project about public places such as restaurants, hotels, museums, waypoints. It collects all public information about them such as photos, reviews, links to other systems link OpenStreetMap, Wikipedia.\n\nAll OpenPlaceReview data is open and available to everyone: http://openplacereviews.org/data.\n\nYou can read more at: http://openplacereviews.org</string>
<string name="hillshade_slope_contour_lines">Hillshade / Slope / Contour lines</string>
<string name="toast_select_edits_for_upload">Select edits for upload</string>
<string name="uploaded_count">Uploaded %1$d of %2$d</string>

View file

@ -143,8 +143,8 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
@Override
public void disable(OsmandApplication app) {
if (app.getSettings().USE_DEV_URL.get()) {
app.getSettings().USE_DEV_URL.set(false);
if (app.getSettings().OSM_USE_DEV_URL.get()) {
app.getSettings().OSM_USE_DEV_URL.set(false);
app.getOsmOAuthHelper().resetAuthorization();
}
super.disable(app);

View file

@ -51,8 +51,8 @@ public class EditPOIMenuController extends MenuController {
OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
boolean isLogged = client.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|| !Algorithms.isEmpty(settings.OSM_USER_NAME.get())
&& !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
if (point instanceof OpenstreetmapPoint) {
if (isLogged) {

View file

@ -84,7 +84,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
additionalData.put("tags", tagstring);
additionalData.put("visibility", visibility);
return NetworkUtils.uploadFile(url, f,
settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(),
settings.OSM_USER_NAME.get() + ":" + settings.OSM_USER_PASSWORD.get(),
adapter.getClient(),
"file",
true, additionalData);
@ -138,7 +138,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
StringBuilder responseBody = new StringBuilder();
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
String token = settings.OSM_USER_NAME.get() + ":" + settings.OSM_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$
connection.setDoInput(true);
if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -322,9 +322,9 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
if (n instanceof Node) {
writeNode((Node) n, info, ser, changeSetId, settings.USER_NAME.get());
writeNode((Node) n, info, ser, changeSetId, settings.OSM_USER_NAME.get());
} else if (n instanceof Way) {
writeWay((Way) n, info, ser, changeSetId, settings.USER_NAME.get());
writeWay((Way) n, info, ser, changeSetId, settings.OSM_USER_NAME.get());
}
ser.endTag(null, OsmPoint.stringAction.get(action));
ser.endTag(null, "osmChange"); //$NON-NLS-1$

View file

@ -141,7 +141,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(app));
if (!anonymous) {
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get();
String token = settings.OSM_USER_NAME.get() + ":" + settings.OSM_USER_PASSWORD.get();
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes(StandardCharsets.UTF_8)));
}
connection.setDoInput(true);

View file

@ -112,7 +112,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
boolean validToken = isValidToken();
Preference nameAndPasswordPref = findPreference(OSM_LOGOUT);
if (validToken || isLoginExists()) {
String userName = validToken ? settings.USER_DISPLAY_NAME.get() : settings.USER_NAME.get();
String userName = validToken ? settings.OSM_USER_DISPLAY_NAME.get() : settings.OSM_USER_NAME.get();
nameAndPasswordPref.setVisible(true);
nameAndPasswordPref.setSummary(userName);
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
@ -126,7 +126,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
}
private boolean isLoginExists() {
return !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
return !Algorithms.isEmpty(settings.OSM_USER_NAME.get()) && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
}
private void setupOfflineEditingPref() {
@ -140,7 +140,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
}
private void setupUseDevUrlPref() {
SwitchPreferenceEx useDevUrlPref = findPreference(settings.USE_DEV_URL.getId());
SwitchPreferenceEx useDevUrlPref = findPreference(settings.OSM_USE_DEV_URL.getId());
if (OsmandPlugin.isDevelopment()) {
Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_laptop);
useDevUrlPref.setDescription(getString(R.string.use_dev_url_descr));
@ -176,8 +176,8 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@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);
if (settings.OSM_USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) {
settings.OSM_USE_DEV_URL.set((Boolean) newValue);
osmLogout();
return true;
}
@ -220,7 +220,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override
public void onPreferenceChanged(String prefId) {
if (settings.USE_DEV_URL.getId().equals(prefId)) {
if (settings.OSM_USE_DEV_URL.getId().equals(prefId)) {
osmLogout();
}
updateAllSettings();

View file

@ -457,9 +457,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
public boolean sendGPXFiles(final FragmentActivity activity, Fragment fragment, final GpxInfo... info) {
String name = settings.USER_NAME.get();
String pwd = settings.USER_PASSWORD.get();
String authToken = settings.USER_ACCESS_TOKEN.get();
String name = settings.OSM_USER_NAME.get();
String pwd = settings.OSM_USER_PASSWORD.get();
String authToken = settings.OSM_USER_ACCESS_TOKEN.get();
if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment);
return false;

View file

@ -30,8 +30,8 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask<Void, Void, OsmBugRes
@Override
protected void onPostExecute(OsmBugResult osmBugResult) {
if (osmBugResult.warning != null) {
app.getSettings().USER_NAME.resetToDefault();
app.getSettings().USER_PASSWORD.resetToDefault();
app.getSettings().OSM_USER_NAME.resetToDefault();
app.getSettings().OSM_USER_PASSWORD.resetToDefault();
app.showToastMessage(osmBugResult.warning);
} else {
app.showToastMessage(R.string.osm_authorization_success);

View file

@ -69,10 +69,10 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
messageField = sendGpxView.findViewById(R.id.message_field);
TextView accountName = sendGpxView.findViewById(R.id.user_name);
if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) {
accountName.setText(settings.USER_DISPLAY_NAME.get());
if (!Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get())) {
accountName.setText(settings.OSM_USER_DISPLAY_NAME.get());
} else {
accountName.setText(settings.USER_NAME.get());
accountName.setText(settings.OSM_USER_NAME.get());
}
String fileName = gpxInfos[0].getFileName();

View file

@ -61,7 +61,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
private EditText noteText;
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
return !Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get());
}
@Override
@ -150,8 +150,8 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
}
private void updateAccountName() {
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userNameOAuth = settings.OSM_USER_DISPLAY_NAME.get();
String userNameOpenID = settings.OSM_USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
accountName.setText(userName);
updateSignIn(uploadAnonymously.isChecked());
@ -230,7 +230,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
private boolean isLogged() {
OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
return adapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|| !Algorithms.isEmpty(settings.OSM_USER_NAME.get())
&& !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
}
}

View file

@ -47,7 +47,7 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
private boolean isLoginOAuth(OsmandSettings settings) {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
return !Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get());
}
@Override
@ -68,8 +68,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
messageEditText.setSelection(messageEditText.getText().length());
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
OsmandSettings settings = app.getSettings();
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userNameOAuth = settings.OSM_USER_DISPLAY_NAME.get();
String userNameOpenID = settings.OSM_USER_NAME.get();
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
accountName.setText(userName);
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);

View file

@ -1,19 +1,12 @@
package net.osmand.plus.osmedit.oauth;
import android.content.Context;
import android.content.Intent;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import com.github.scribejava.core.builder.api.DefaultApi10a;
import com.github.scribejava.core.model.OAuth1AccessToken;
@ -24,7 +17,6 @@ import com.github.scribejava.core.model.Verb;
import net.osmand.PlatformUtil;
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
@ -52,7 +44,7 @@ public class OsmOAuthAuthorizationAdapter {
DefaultApi10a api10a;
String key;
String secret;
if (app.getSettings().USE_DEV_URL.get()) {
if (app.getSettings().OSM_USE_DEV_URL.get()) {
api10a = new OsmOAuthAuthorizationClient.OsmDevApi();
key = app.getString(R.string.osm_oauth_developer_key);
secret = app.getString(R.string.osm_oauth_developer_secret);
@ -78,8 +70,8 @@ public class OsmOAuthAuthorizationAdapter {
}
public void restoreToken() {
String token = app.getSettings().USER_ACCESS_TOKEN.get();
String tokenSecret = app.getSettings().USER_ACCESS_TOKEN_SECRET.get();
String token = app.getSettings().OSM_USER_ACCESS_TOKEN.get();
String tokenSecret = app.getSettings().OSM_USER_ACCESS_TOKEN_SECRET.get();
if (!(token.isEmpty() || tokenSecret.isEmpty())) {
client.setAccessToken(new OAuth1AccessToken(token, tokenSecret));
} else {
@ -93,8 +85,8 @@ public class OsmOAuthAuthorizationAdapter {
private void saveToken() {
OAuth1AccessToken accessToken = client.getAccessToken();
app.getSettings().USER_ACCESS_TOKEN.set(accessToken.getToken());
app.getSettings().USER_ACCESS_TOKEN_SECRET.set(accessToken.getTokenSecret());
app.getSettings().OSM_USER_ACCESS_TOKEN.set(accessToken.getToken());
app.getSettings().OSM_USER_ACCESS_TOKEN_SECRET.set(accessToken.getTokenSecret());
}
private void loadWebView(ViewGroup root, boolean nightMode, String url) {
@ -180,7 +172,7 @@ public class OsmOAuthAuthorizationAdapter {
} catch (XmlPullParserException e) {
log.error(e);
}
app.getSettings().USER_DISPLAY_NAME.set(userName);
app.getSettings().OSM_USER_DISPLAY_NAME.set(userName);
}
public String getUserName() throws InterruptedException, ExecutionException, IOException, XmlPullParserException {

View file

@ -54,18 +54,18 @@ public class OsmOAuthHelper {
public void resetAuthorization() {
if (isValidToken()) {
settings.USER_ACCESS_TOKEN.resetToDefault();
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
settings.OSM_USER_ACCESS_TOKEN.resetToDefault();
settings.OSM_USER_ACCESS_TOKEN_SECRET.resetToDefault();
authorizationAdapter.resetToken();
} else if (isLoginExists()) {
settings.USER_NAME.resetToDefault();
settings.USER_PASSWORD.resetToDefault();
settings.OSM_USER_NAME.resetToDefault();
settings.OSM_USER_PASSWORD.resetToDefault();
}
updateAdapter();
}
private boolean isLoginExists() {
return !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
return !Algorithms.isEmpty(settings.OSM_USER_NAME.get()) && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
}
public void notifyAndRemoveListeners() {

View file

@ -1121,8 +1121,8 @@ public class OsmandSettings {
}
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared();
public final OsmandPreference<String> USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared();
public final OsmandPreference<String> OSM_USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared();
public final OsmandPreference<String> OSM_USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared();
public static final String BILLING_USER_DONATION_WORLD_PARAMETER = "";
public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none";
@ -1156,13 +1156,13 @@ public class OsmandSettings {
new StringPreference(this, "user_osm_bug_name", "NoName/OsmAnd").makeGlobal().makeShared();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> USER_PASSWORD =
public final OsmandPreference<String> OSM_USER_PASSWORD =
new StringPreference(this, "user_password", "").makeGlobal().makeShared();
public final OsmandPreference<String> USER_ACCESS_TOKEN =
public final OsmandPreference<String> OSM_USER_ACCESS_TOKEN =
new StringPreference(this, "user_access_token", "").makeGlobal();
public final OsmandPreference<String> USER_ACCESS_TOKEN_SECRET =
public final OsmandPreference<String> OSM_USER_ACCESS_TOKEN_SECRET =
new StringPreference(this, "user_access_token_secret", "").makeGlobal();
public final OsmandPreference<String> OPR_ACCESS_TOKEN =
@ -1176,11 +1176,11 @@ 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 final OsmandPreference<Boolean> OSM_USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
public String getOsmUrl() {
String osmUrl;
if (USE_DEV_URL.get()) {
if (OSM_USE_DEV_URL.get()) {
osmUrl = "https://master.apis.dev.openstreetmap.org/";
} else {
osmUrl = "https://api.openstreetmap.org/";

View file

@ -6,7 +6,6 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ScrollView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -49,8 +48,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
userNameEditText = view.findViewById(R.id.name_edit_text);
passwordEditText = view.findViewById(R.id.password_edit_text);
String name = app.getSettings().USER_NAME.get();
String password = app.getSettings().USER_PASSWORD.get();
String name = app.getSettings().OSM_USER_NAME.get();
String password = app.getSettings().OSM_USER_PASSWORD.get();
if (savedInstanceState != null) {
name = savedInstanceState.getString(USER_NAME_KEY, null);
@ -96,8 +95,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
protected void onRightBottomButtonClick() {
OsmandApplication app = requiredMyApplication();
app.getSettings().USER_NAME.set(userNameEditText.getText().toString());
app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString());
app.getSettings().OSM_USER_NAME.set(userNameEditText.getText().toString());
app.getSettings().OSM_USER_PASSWORD.set(passwordEditText.getText().toString());
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof ValidateOsmLoginListener) {