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 { buildTypes {
debug { debug {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
signingConfig signingConfigs.development signingConfig signingConfigs.development
} }
release { release {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
signingConfig signingConfigs.publishing signingConfig signingConfigs.publishing
} }
} }

View file

@ -41,4 +41,9 @@
<string name="items_modified">items modified</string> <string name="items_modified">items modified</string>
<string name="osmand_unlimited">OsmAnd Unlimited</string> <string name="osmand_unlimited">OsmAnd Unlimited</string>
<string name="markers">Markers</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> </resources>

View file

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

View file

@ -19,6 +19,7 @@ import net.osmand.PlatformUtil;
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient; import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -45,12 +46,12 @@ public class OsmOAuthAuthorizationAdapter {
String secret; String secret;
if (app.getSettings().USE_DEV_URL.get()) { if (app.getSettings().USE_DEV_URL.get()) {
api10a = new OsmOAuthAuthorizationClient.OsmDevApi(); api10a = new OsmOAuthAuthorizationClient.OsmDevApi();
key = OsmAndConstants.OSM_OAUTH_DEVELOPER_KEY; key = app.getString(R.string.osm_oauth_developer_key);
secret = OsmAndConstants.OSM_OAUTH_DEVELOPER_SECRET; secret = app.getString(R.string.osm_oauth_developer_secret);
} else { } else {
api10a = new OsmOAuthAuthorizationClient.OsmApi(); api10a = new OsmOAuthAuthorizationClient.OsmApi();
key = OsmAndConstants.OSM_OAUTH_CONSUMER_KEY; key = app.getString(R.string.osm_oauth_consumer_key);
secret = OsmAndConstants.OSM_OAUTH_CONSUMER_SECRET; secret = app.getString(R.string.osm_oauth_consumer_secret);
} }
client = new OsmOAuthAuthorizationClient(key, secret, api10a); client = new OsmOAuthAuthorizationClient(key, secret, api10a);
restoreToken(); restoreToken();