Move oauth consts to no_translate

This commit is contained in:
max-klaus 2020-11-23 15:25:12 +03:00
parent a661ce677f
commit 74aace6fa9
5 changed files with 39 additions and 27 deletions

View file

@ -197,11 +197,9 @@ android {
buildTypes {
debug {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
signingConfig signingConfigs.development
}
release {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
signingConfig signingConfigs.publishing
}
}

View file

@ -41,4 +41,9 @@
<string name="items_modified">items modified</string>
<string name="osmand_unlimited">OsmAnd Unlimited</string>
<string name="markers">Markers</string>
<string name="opr_base_url">https://test.openplacereviews.org/</string>
<string name="osm_oauth_developer_key">v8G8r9NLJZGMV4he5lwbQlz620FNVARKjI9Bm5UJ</string>
<string name="osm_oauth_developer_secret">jDvM95Ne1Bq2BDTmIfB6b3ZMxvdK87WGfp6DC07J</string>
<string name="osm_oauth_consumer_key">Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y</string>
<string name="osm_oauth_consumer_secret">lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM</string>
</resources>

View file

@ -13,9 +13,4 @@ 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";
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.openplacereviews;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -8,24 +9,36 @@ import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.BuildConfig;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class OPRWebviewActivity extends OsmandActionBarActivity {
public static final String KEY_LOGIN = "LOGIN_KEY";
private static final String url = BuildConfig.OPR_BASE_URL;
private static final String cookieUrl = BuildConfig.OPR_BASE_URL + "profile";
private static final String loginUrl = BuildConfig.OPR_BASE_URL + "login";
private static final String registerUrl = BuildConfig.OPR_BASE_URL + "signup";
private static final String finishUrl = cookieUrl;
public static String KEY_TITLE = "TITLE_KEY";
private WebView webView;
private boolean isLogin = false;
public static String getCookieUrl(Context ctx) {
return ctx.getString(R.string.opr_base_url) + "profile";
}
public static String getLoginUrl(Context ctx) {
return ctx.getString(R.string.opr_base_url) + "login";
}
public static String getRegisterUrl(Context ctx) {
return ctx.getString(R.string.opr_base_url) + "signup";
}
public static String getFinishUrl(Context ctx) {
return getCookieUrl(ctx);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opr_webview);
@ -46,9 +59,9 @@ public class OPRWebviewActivity extends OsmandActionBarActivity {
if (b != null) {
isLogin = b.getBoolean(KEY_LOGIN);
if (isLogin) {
webView.loadUrl(loginUrl);
webView.loadUrl(getLoginUrl(this));
} else {
webView.loadUrl(registerUrl);
webView.loadUrl(getRegisterUrl(this));
}
}
}
@ -59,18 +72,18 @@ public class OPRWebviewActivity extends OsmandActionBarActivity {
return true;
}
public static String getPrivateKeyFromCookie() {
return returnCookieByKey("opr-token");
public static String getPrivateKeyFromCookie(Context ctx) {
return returnCookieByKey(ctx, "opr-token");
}
public static String getUsernameFromCookie() {
return returnCookieByKey("opr-nickname");
public static String getUsernameFromCookie(Context ctx) {
return returnCookieByKey(ctx, "opr-nickname");
}
private static String returnCookieByKey(String key) {
private static String returnCookieByKey(Context ctx, String key) {
String CookieValue = null;
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(cookieUrl);
String cookies = cookieManager.getCookie(getCookieUrl(ctx));
if (cookies == null || cookies.isEmpty()) {
return "";
}
@ -88,7 +101,7 @@ public class OPRWebviewActivity extends OsmandActionBarActivity {
public class CloseOnSuccessWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
if (url.contains(finishUrl) && isLogin) {
if (url.contains(getFinishUrl(OPRWebviewActivity.this)) && isLogin) {
finish();
}
super.onPageFinished(view, url);

View file

@ -19,6 +19,7 @@ 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 org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
@ -45,12 +46,12 @@ public class OsmOAuthAuthorizationAdapter {
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;
key = app.getString(R.string.osm_oauth_developer_key);
secret = app.getString(R.string.osm_oauth_developer_secret);
} else {
api10a = new OsmOAuthAuthorizationClient.OsmApi();
key = OsmAndConstants.OSM_OAUTH_CONSUMER_KEY;
secret = OsmAndConstants.OSM_OAUTH_CONSUMER_SECRET;
key = app.getString(R.string.osm_oauth_consumer_key);
secret = app.getString(R.string.osm_oauth_consumer_secret);
}
client = new OsmOAuthAuthorizationClient(key, secret, api10a);
restoreToken();