From 923278a04628bf00a73ce610e4f47488b63ced9b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 23 Nov 2020 21:33:15 +0200 Subject: [PATCH] Fix compilation --- .../plus/mapcontextmenu/MenuBuilder.java | 38 ++++++++++++++----- .../builders/cards/ImageCard.java | 14 +++++-- .../openplacereviews/OPRWebviewActivity.java | 10 +++-- .../osmand/plus/osmedit/opr/OpenDBAPI.java | 29 +++++++++----- 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 0a6fa296d0..bfd21f5abb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -6,7 +6,11 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.ColorStateList; -import android.graphics.*; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.net.Uri; @@ -24,12 +28,14 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; + import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -37,7 +43,11 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.*; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.ActivityResultListener; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; @@ -60,6 +70,7 @@ import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.tools.ClickableSpanTouchListener; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; + import org.apache.commons.logging.Log; import org.openplacereviews.opendb.util.exception.FailedVerificationException; @@ -67,7 +78,13 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; @@ -383,8 +400,9 @@ public class MenuBuilder { AddPhotosBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); } else { registerResultListener(view); - final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(); - final String name = OPRWebviewActivity.getUsernameFromCookie(); + final String baseUrl = OPRWebviewActivity.getBaseUrl(app); + final String name = OPRWebviewActivity.getUsernameFromCookie(app); + final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app); if (privateKey == null || privateKey.isEmpty()) { OprStartFragment.showInstance(mapActivity.getSupportFragmentManager()); return; @@ -392,7 +410,7 @@ public class MenuBuilder { new Thread(new Runnable() { @Override public void run() { - if (openDBAPI.checkPrivateKeyValid(name, privateKey)) { + if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) { app.runInUIThread(new Runnable() { @Override public void run() { @@ -458,15 +476,17 @@ public class MenuBuilder { private void uploadImageToPlace(View view, InputStream image) { InputStream serverData = new ByteArrayInputStream(compressImage(image)); - String url = BuildConfig.OPR_BASE_URL + "api/ipfs/image"; + final String baseUrl = OPRWebviewActivity.getBaseUrl(app); + String url = baseUrl + "api/ipfs/image"; String response = NetworkUtils.sendPostDataRequest(url, serverData); if (response != null) { int res = 0; try { res = openDBAPI.uploadImage( placeId, - OPRWebviewActivity.getPrivateKeyFromCookie(), - OPRWebviewActivity.getUsernameFromCookie(), + baseUrl, + OPRWebviewActivity.getPrivateKeyFromCookie(app), + OPRWebviewActivity.getUsernameFromCookie(app), response); } catch (FailedVerificationException e) { LOG.error(e); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index 33feb6c5a3..49c23e9501 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -21,7 +21,6 @@ import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; import net.osmand.data.LatLon; -import net.osmand.plus.BuildConfig; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -29,6 +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.wikimedia.WikiImageHelper; import net.osmand.util.Algorithms; @@ -40,7 +40,14 @@ import org.json.JSONObject; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; public abstract class ImageCard extends AbstractCard { @@ -460,7 +467,8 @@ public abstract class ImageCard extends AbstractCard { if (o instanceof Amenity) { Amenity am = (Amenity) o; long amenityId = am.getId() >> 1; - String url = BuildConfig.OPR_BASE_URL + "api/objects-by-index?type=opr.place&index=osmid&key=" + amenityId; + String baseUrl = OPRWebviewActivity.getBaseUrl(app); + String url = baseUrl + "api/objects-by-index?type=opr.place&index=osmid&key=" + amenityId; String response = AndroidNetworkUtils.sendRequest(app, url, Collections.emptyMap(), "Requesting location images...", false, false); if (response != null) { diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java index 7cd6f5bc38..72aa9873d3 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java @@ -23,16 +23,20 @@ public class OPRWebviewActivity extends OsmandActionBarActivity { 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 ctx.getString(R.string.opr_base_url) + "profile"; + return getBaseUrl(ctx) + "profile"; } public static String getLoginUrl(Context ctx) { - return ctx.getString(R.string.opr_base_url) + "login"; + return getBaseUrl(ctx) + "login"; } public static String getRegisterUrl(Context ctx) { - return ctx.getString(R.string.opr_base_url) + "signup"; + return getBaseUrl(ctx) + "signup"; } public static String getFinishUrl(Context ctx) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java index ad19add249..7c891c25c9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java @@ -2,11 +2,12 @@ package net.osmand.plus.osmedit.opr; import android.net.TrafficStats; import android.os.Build; + import com.google.gson.GsonBuilder; -import net.osmand.AndroidNetworkUtils; + import net.osmand.PlatformUtil; import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.BuildConfig; + import org.apache.commons.logging.Log; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.openplacereviews.opendb.SecUtils; @@ -14,15 +15,25 @@ import org.openplacereviews.opendb.ops.OpOperation; import org.openplacereviews.opendb.util.JsonFormatter; import org.openplacereviews.opendb.util.exception.FailedVerificationException; -import java.io.*; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.security.KeyPair; import java.security.Security; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; -import static org.openplacereviews.opendb.SecUtils.*; +import static org.openplacereviews.opendb.SecUtils.ALGO_EC; +import static org.openplacereviews.opendb.SecUtils.JSON_MSG_TYPE; +import static org.openplacereviews.opendb.SecUtils.signMessageWithKeyBase64; public class OpenDBAPI { @@ -39,10 +50,10 @@ public class OpenDBAPI { * Need to encode key * Do not call on mainThread */ - public boolean checkPrivateKeyValid(String username, String privateKey) { + public boolean checkPrivateKeyValid(String baseUrl, String username, String privateKey) { String url = null; try { - url = BuildConfig.OPR_BASE_URL + checkLoginEndpoint + + url = baseUrl + checkLoginEndpoint + "name=" + username + "&" + @@ -57,7 +68,7 @@ public class OpenDBAPI { response.toString().contains(LOGIN_SUCCESS_MESSAGE); } - public int uploadImage(String[] placeId, String privateKey, String username, String image) throws FailedVerificationException { + public int uploadImage(String[] placeId, String baseUrl, String privateKey, String username, String image) throws FailedVerificationException { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { Security.removeProvider("BC"); Security.addProvider(new BouncyCastleProvider()); @@ -100,7 +111,7 @@ public class OpenDBAPI { opOperation.addOrSetStringValue("hash", hash); opOperation.addOrSetStringValue("signature", signature); TrafficStats.setThreadStatsTag(THREAD_ID); - String url = BuildConfig.OPR_BASE_URL + "api/auth/process-operation?addToQueue=true&dontSignByServer=false"; + String url = baseUrl + "api/auth/process-operation?addToQueue=true&dontSignByServer=false"; String json = formatter.opToJson(opOperation); System.out.println("JSON: " + json); HttpURLConnection connection;