update opr constants
This commit is contained in:
parent
01bf8f0ba3
commit
becc44a148
8 changed files with 58 additions and 179 deletions
|
@ -65,7 +65,6 @@
|
|||
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" />
|
||||
<activity android:name="net.osmand.plus.activities.HelpActivity" />
|
||||
<activity android:name="net.osmand.plus.activities.ExitActivity" />
|
||||
<activity android:name="net.osmand.plus.openplacereviews.OPRWebviewActivity" android:theme="@style/Theme.AppCompat.NoActionBar" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
|
|
@ -21,7 +21,7 @@ import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
|||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
|
||||
import net.osmand.plus.openplacereviews.OPRWebviewActivity;
|
||||
import net.osmand.plus.openplacereviews.OPRConstants;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
@ -314,7 +314,7 @@ public class IntentHelper {
|
|||
Intent intent = mapActivity.getIntent();
|
||||
if (intent != null && intent.getData() != null) {
|
||||
Uri uri = intent.getData();
|
||||
if (uri.toString().startsWith(OPRWebviewActivity.OPR_OAUTH_PREFIX)) {
|
||||
if (uri.toString().startsWith(OPRConstants.OPR_OAUTH_PREFIX)) {
|
||||
String token = uri.getQueryParameter("opr-token");
|
||||
String username = uri.getQueryParameter("opr-nickname");
|
||||
app.getSettings().OPR_ACCESS_TOKEN.set(token);
|
||||
|
|
|
@ -53,7 +53,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask
|
|||
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
||||
import net.osmand.plus.openplacereviews.AddPhotosBottomSheetDialogFragment;
|
||||
import net.osmand.plus.openplacereviews.OPRWebviewActivity;
|
||||
import net.osmand.plus.openplacereviews.OPRConstants;
|
||||
import net.osmand.plus.openplacereviews.OprStartFragment;
|
||||
import net.osmand.plus.osmedit.opr.OpenDBAPI;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
|
@ -382,7 +382,7 @@ public class MenuBuilder {
|
|||
AddPhotosBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||
} else {
|
||||
registerResultListener(view);
|
||||
final String baseUrl = OPRWebviewActivity.getBaseUrl(app);
|
||||
final String baseUrl = OPRConstants.getBaseUrl(app);
|
||||
final String name = app.getSettings().OPR_USERNAME.get();
|
||||
final String privateKey = app.getSettings().OPR_ACCESS_TOKEN.get();
|
||||
if (Algorithms.isBlank(privateKey) || Algorithms.isBlank(name)) {
|
||||
|
@ -464,18 +464,20 @@ public class MenuBuilder {
|
|||
|
||||
private void uploadImageToPlace(InputStream image) {
|
||||
InputStream serverData = new ByteArrayInputStream(compressImage(image));
|
||||
final String baseUrl = OPRWebviewActivity.getBaseUrl(app);
|
||||
final String baseUrl = OPRConstants.getBaseUrl(app);
|
||||
String url = baseUrl + "api/ipfs/image";
|
||||
String response = NetworkUtils.sendPostDataRequest(url, serverData);
|
||||
if (response != null) {
|
||||
int res = 0;
|
||||
try {
|
||||
StringBuilder error = new StringBuilder();
|
||||
String privateKey = app.getSettings().OPR_ACCESS_TOKEN.get();
|
||||
String username = app.getSettings().OPR_USERNAME.get();
|
||||
res = openDBAPI.uploadImage(
|
||||
placeId,
|
||||
baseUrl,
|
||||
OPRWebviewActivity.getPrivateKeyFromCookie(app),
|
||||
OPRWebviewActivity.getUsernameFromCookie(app),
|
||||
privateKey,
|
||||
username,
|
||||
response, error);
|
||||
if (res != 200) {
|
||||
showToastMessage(error.toString());
|
||||
|
@ -511,9 +513,9 @@ public class MenuBuilder {
|
|||
|
||||
//This method runs on non main thread
|
||||
private void checkTokenAndShowScreen() {
|
||||
final String baseUrl = OPRWebviewActivity.getBaseUrl(app);
|
||||
final String name = OPRWebviewActivity.getUsernameFromCookie(app);
|
||||
final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app);
|
||||
final String baseUrl = OPRConstants.getBaseUrl(app);
|
||||
final String name = app.getSettings().OPR_USERNAME.get();
|
||||
final String privateKey = app.getSettings().OPR_ACCESS_TOKEN.get();
|
||||
if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) {
|
||||
String str = app.getString(R.string.cannot_upload_image);
|
||||
showToastMessage(str);
|
||||
|
|
|
@ -28,7 +28,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapillary.MapillaryContributeCard;
|
||||
import net.osmand.plus.mapillary.MapillaryImageCard;
|
||||
import net.osmand.plus.openplacereviews.OPRWebviewActivity;
|
||||
import net.osmand.plus.openplacereviews.OPRConstants;
|
||||
import net.osmand.plus.wikimedia.WikiImageHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -467,7 +467,7 @@ public abstract class ImageCard extends AbstractCard {
|
|||
if (o instanceof Amenity) {
|
||||
Amenity am = (Amenity) o;
|
||||
long amenityId = am.getId() >> 1;
|
||||
String baseUrl = OPRWebviewActivity.getBaseUrl(app);
|
||||
String baseUrl = OPRConstants.getBaseUrl(app);
|
||||
String url = baseUrl + "api/objects-by-index?type=opr.place&index=osmid&key=" + amenityId;
|
||||
String response = AndroidNetworkUtils.sendRequest(app, url, Collections.<String, String>emptyMap(),
|
||||
"Requesting location images...", false, false);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package net.osmand.plus.openplacereviews;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.opr.OpenDBAPI;
|
||||
|
||||
public class OPRConstants {
|
||||
public static final String OPR_OAUTH_PREFIX = "opr-oauth";
|
||||
private static final String PURPOSE = OpenDBAPI.PURPOSE;
|
||||
private static final String CALLBACK_URL = OPR_OAUTH_PREFIX + "://osmand_opr_auth";
|
||||
|
||||
public static String getBaseUrl(Context ctx) {
|
||||
return ctx.getString(R.string.opr_base_url);
|
||||
}
|
||||
|
||||
|
||||
public static String getLoginUrl(Context ctx) {
|
||||
return getBaseUrl(ctx) + "login" + getQueryString(ctx);
|
||||
}
|
||||
|
||||
public static String getRegisterUrl(Context ctx) {
|
||||
return getBaseUrl(ctx) + "signup" + getQueryString(ctx);
|
||||
}
|
||||
|
||||
public static String getQueryString(Context ctx) {
|
||||
return "?" + getPurposeParam(ctx) + "&" + getCallbackParam(ctx);
|
||||
}
|
||||
|
||||
public static String getPurposeParam(Context ctx) {
|
||||
return "purpose=" + PURPOSE;
|
||||
}
|
||||
|
||||
public static String getCallbackParam(Context ctx) {
|
||||
return "callback=" + CALLBACK_URL;
|
||||
}
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
package net.osmand.plus.openplacereviews;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
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.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OPRWebviewActivity extends OsmandActionBarActivity {
|
||||
public static final String KEY_LOGIN = "LOGIN_KEY";
|
||||
public static final String KEY_TITLE = "TITLE_KEY";
|
||||
public static final String OPR_OAUTH_PREFIX = "opr-oauth";
|
||||
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)";
|
||||
private static final String PURPOSE = "opr-android";
|
||||
private static final String CALLBACK_URL = OPR_OAUTH_PREFIX + "://osmand_opr_auth";
|
||||
private WebView webView;
|
||||
private boolean isLogin = false;
|
||||
|
||||
public static String getBaseUrl(Context ctx) {
|
||||
return ctx.getString(R.string.opr_base_url);
|
||||
}
|
||||
|
||||
public static String getCookieUrl(Context ctx) {
|
||||
return getBaseUrl(ctx) + "profile";
|
||||
}
|
||||
|
||||
public static String getLoginUrl(Context ctx) {
|
||||
return getBaseUrl(ctx) + "login" + getQueryString(ctx);
|
||||
}
|
||||
|
||||
public static String getRegisterUrl(Context ctx) {
|
||||
return getBaseUrl(ctx) + "signup" + getQueryString(ctx);
|
||||
}
|
||||
|
||||
public static String getQueryString(Context ctx) {
|
||||
return "?" + getPurposeParam(ctx) + "&" + getCallbackParam(ctx);
|
||||
}
|
||||
|
||||
public static String getPurposeParam(Context ctx) {
|
||||
return "purpose=" + PURPOSE;
|
||||
}
|
||||
|
||||
public static String getCallbackParam(Context ctx) {
|
||||
return "callback=" + CALLBACK_URL;
|
||||
}
|
||||
|
||||
public static List<String> getFinishUrls(Context ctx) {
|
||||
String googleOAuthFinishUrl = getBaseUrl(ctx) + "auth?code=4";
|
||||
String profileUrl = getCookieUrl(ctx);
|
||||
List<String> urls = new ArrayList<>();
|
||||
urls.add(googleOAuthFinishUrl);
|
||||
urls.add(profileUrl);
|
||||
return urls;
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
boolean nightMode = !settings.isLightContent();
|
||||
int themeId = nightMode ? R.style.OsmandDarkTheme_NoActionbar : R.style.OsmandLightTheme_NoActionbar_LightStatusBar;
|
||||
setTheme(themeId);
|
||||
getWindow().setStatusBarColor(ContextCompat.getColor(this, nightMode
|
||||
? R.color.list_background_color_dark : R.color.list_background_color_light));
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_opr_webview);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
if (bundle != null) {
|
||||
TextView titleView = findViewById(R.id.toolbar_text);
|
||||
String title = bundle.getString(KEY_TITLE, "");
|
||||
titleView.setText(title);
|
||||
}
|
||||
toolbar.setBackgroundDrawable(new ColorDrawable(AndroidUtils.getColorFromAttr(this, R.attr.bg_color)));
|
||||
final Drawable upArrow = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(this));
|
||||
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP);
|
||||
toolbar.setNavigationIcon(upArrow);
|
||||
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
webView = findViewById(R.id.printDialogWebview);
|
||||
webView.getSettings().setUserAgentString(USER_AGENT);
|
||||
webView.setWebViewClient(new CloseOnSuccessWebViewClient());
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
WebView.setWebContentsDebuggingEnabled(true);
|
||||
if (bundle != null) {
|
||||
isLogin = bundle.getBoolean(KEY_LOGIN);
|
||||
if (isLogin) {
|
||||
webView.loadUrl(getLoginUrl(this));
|
||||
} else {
|
||||
webView.loadUrl(getRegisterUrl(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getPrivateKeyFromCookie(Context ctx) {
|
||||
return returnCookieByKey(ctx, "opr-token");
|
||||
}
|
||||
|
||||
public static String getUsernameFromCookie(Context ctx) {
|
||||
return returnCookieByKey(ctx, "opr-nickname");
|
||||
}
|
||||
|
||||
private static String returnCookieByKey(Context ctx, String key) {
|
||||
String CookieValue = null;
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
String cookies = cookieManager.getCookie(getCookieUrl(ctx));
|
||||
if (cookies == null || cookies.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
String[] temp = cookies.split(";");
|
||||
for (String ar1 : temp) {
|
||||
if (ar1.contains(key)) {
|
||||
String[] temp1 = ar1.split("=");
|
||||
CookieValue = temp1[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return CookieValue;
|
||||
}
|
||||
|
||||
public class CloseOnSuccessWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
for (String furl : getFinishUrls(OPRWebviewActivity.this)) {
|
||||
if (url.contains(furl) && isLogin) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,14 +70,14 @@ public class OprStartFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
private void handleHaveAccount() {
|
||||
String url = OPRWebviewActivity.getLoginUrl(requireContext());
|
||||
String url = OPRConstants.getLoginUrl(requireContext());
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(requireContext(), Uri.parse(url));
|
||||
}
|
||||
|
||||
private void handleCreateAccount() {
|
||||
String url = OPRWebviewActivity.getRegisterUrl(requireContext());
|
||||
String url = OPRConstants.getRegisterUrl(requireContext());
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(requireContext(), Uri.parse(url));
|
||||
|
|
|
@ -37,16 +37,16 @@ import static org.openplacereviews.opendb.SecUtils.signMessageWithKeyBase64;
|
|||
|
||||
|
||||
public class OpenDBAPI {
|
||||
public static final String PURPOSE = "opr-android";
|
||||
private static final Log log = PlatformUtil.getLog(SecUtils.class);
|
||||
private static final String checkLoginEndpoint = "api/auth/user-check-loginkey?";
|
||||
private static final String LOGIN_SUCCESS_MESSAGE = "{\"result\":\"OK\"}";
|
||||
private static final String PURPOSE = "opr-android";
|
||||
private static final int THREAD_ID = 11200;
|
||||
|
||||
/*
|
||||
* method for check if user is loggined in blockchain
|
||||
* params
|
||||
* - username: blockchain username in format "openplacereviews:test_1"
|
||||
* - username: blockchain username in format "openplacereviews"
|
||||
* - privatekey: "base64:PKCS#8:actualKey"
|
||||
* Need to encode key
|
||||
* Do not call on mainThread
|
||||
|
@ -54,8 +54,8 @@ public class OpenDBAPI {
|
|||
public boolean checkPrivateKeyValid(String baseUrl, String username, String privateKey) {
|
||||
String url = null;
|
||||
try {
|
||||
url = baseUrl + checkLoginEndpoint +
|
||||
"purpose=" + PURPOSE + "&" +
|
||||
String purposeParam = "purpose=" + PURPOSE;
|
||||
url = baseUrl + checkLoginEndpoint + purposeParam + "&" +
|
||||
"name=" +
|
||||
username +
|
||||
"&" +
|
||||
|
|
Loading…
Reference in a new issue