commit
6586411754
4 changed files with 67 additions and 24 deletions
|
@ -6,7 +6,11 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
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.Drawable;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -24,12 +28,14 @@ import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.view.ContextThemeWrapper;
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
@ -37,7 +43,11 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.osm.io.NetworkUtils;
|
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.ActivityResultListener;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.FontCache;
|
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.plus.widgets.tools.ClickableSpanTouchListener;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.openplacereviews.opendb.util.exception.FailedVerificationException;
|
import org.openplacereviews.opendb.util.exception.FailedVerificationException;
|
||||||
|
|
||||||
|
@ -67,7 +78,13 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
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;
|
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
|
||||||
|
|
||||||
|
@ -383,8 +400,9 @@ public class MenuBuilder {
|
||||||
AddPhotosBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
|
AddPhotosBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||||
} else {
|
} else {
|
||||||
registerResultListener(view);
|
registerResultListener(view);
|
||||||
final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie();
|
final String baseUrl = OPRWebviewActivity.getBaseUrl(app);
|
||||||
final String name = OPRWebviewActivity.getUsernameFromCookie();
|
final String name = OPRWebviewActivity.getUsernameFromCookie(app);
|
||||||
|
final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(app);
|
||||||
if (privateKey == null || privateKey.isEmpty()) {
|
if (privateKey == null || privateKey.isEmpty()) {
|
||||||
OprStartFragment.showInstance(mapActivity.getSupportFragmentManager());
|
OprStartFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||||
return;
|
return;
|
||||||
|
@ -392,7 +410,7 @@ public class MenuBuilder {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (openDBAPI.checkPrivateKeyValid(name, privateKey)) {
|
if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) {
|
||||||
app.runInUIThread(new Runnable() {
|
app.runInUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -458,15 +476,17 @@ public class MenuBuilder {
|
||||||
|
|
||||||
private void uploadImageToPlace(View view, InputStream image) {
|
private void uploadImageToPlace(View view, InputStream image) {
|
||||||
InputStream serverData = new ByteArrayInputStream(compressImage(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);
|
String response = NetworkUtils.sendPostDataRequest(url, serverData);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
try {
|
try {
|
||||||
res = openDBAPI.uploadImage(
|
res = openDBAPI.uploadImage(
|
||||||
placeId,
|
placeId,
|
||||||
OPRWebviewActivity.getPrivateKeyFromCookie(),
|
baseUrl,
|
||||||
OPRWebviewActivity.getUsernameFromCookie(),
|
OPRWebviewActivity.getPrivateKeyFromCookie(app),
|
||||||
|
OPRWebviewActivity.getUsernameFromCookie(app),
|
||||||
response);
|
response);
|
||||||
} catch (FailedVerificationException e) {
|
} catch (FailedVerificationException e) {
|
||||||
LOG.error(e);
|
LOG.error(e);
|
||||||
|
|
|
@ -21,7 +21,6 @@ import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.BuildConfig;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
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.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapillary.MapillaryContributeCard;
|
import net.osmand.plus.mapillary.MapillaryContributeCard;
|
||||||
import net.osmand.plus.mapillary.MapillaryImageCard;
|
import net.osmand.plus.mapillary.MapillaryImageCard;
|
||||||
|
import net.osmand.plus.openplacereviews.OPRWebviewActivity;
|
||||||
import net.osmand.plus.wikimedia.WikiImageHelper;
|
import net.osmand.plus.wikimedia.WikiImageHelper;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
@ -40,7 +40,14 @@ import org.json.JSONObject;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
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 {
|
public abstract class ImageCard extends AbstractCard {
|
||||||
|
|
||||||
|
@ -460,7 +467,8 @@ public abstract class ImageCard extends AbstractCard {
|
||||||
if (o instanceof Amenity) {
|
if (o instanceof Amenity) {
|
||||||
Amenity am = (Amenity) o;
|
Amenity am = (Amenity) o;
|
||||||
long amenityId = am.getId() >> 1;
|
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.<String, String>emptyMap(),
|
String response = AndroidNetworkUtils.sendRequest(app, url, Collections.<String, String>emptyMap(),
|
||||||
"Requesting location images...", false, false);
|
"Requesting location images...", false, false);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
|
@ -23,16 +23,20 @@ public class OPRWebviewActivity extends OsmandActionBarActivity {
|
||||||
private WebView webView;
|
private WebView webView;
|
||||||
private boolean isLogin = false;
|
private boolean isLogin = false;
|
||||||
|
|
||||||
|
public static String getBaseUrl(Context ctx) {
|
||||||
|
return ctx.getString(R.string.opr_base_url);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCookieUrl(Context ctx) {
|
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) {
|
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) {
|
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) {
|
public static String getFinishUrl(Context ctx) {
|
||||||
|
|
|
@ -2,11 +2,12 @@ package net.osmand.plus.osmedit.opr;
|
||||||
|
|
||||||
import android.net.TrafficStats;
|
import android.net.TrafficStats;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import net.osmand.AndroidNetworkUtils;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.osm.io.NetworkUtils;
|
import net.osmand.osm.io.NetworkUtils;
|
||||||
import net.osmand.plus.BuildConfig;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.openplacereviews.opendb.SecUtils;
|
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.JsonFormatter;
|
||||||
import org.openplacereviews.opendb.util.exception.FailedVerificationException;
|
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.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.Security;
|
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 {
|
public class OpenDBAPI {
|
||||||
|
@ -39,10 +50,10 @@ public class OpenDBAPI {
|
||||||
* Need to encode key
|
* Need to encode key
|
||||||
* Do not call on mainThread
|
* Do not call on mainThread
|
||||||
*/
|
*/
|
||||||
public boolean checkPrivateKeyValid(String username, String privateKey) {
|
public boolean checkPrivateKeyValid(String baseUrl, String username, String privateKey) {
|
||||||
String url = null;
|
String url = null;
|
||||||
try {
|
try {
|
||||||
url = BuildConfig.OPR_BASE_URL + checkLoginEndpoint +
|
url = baseUrl + checkLoginEndpoint +
|
||||||
"name=" +
|
"name=" +
|
||||||
username +
|
username +
|
||||||
"&" +
|
"&" +
|
||||||
|
@ -57,7 +68,7 @@ public class OpenDBAPI {
|
||||||
response.toString().contains(LOGIN_SUCCESS_MESSAGE);
|
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) {
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
Security.removeProvider("BC");
|
Security.removeProvider("BC");
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
@ -100,7 +111,7 @@ public class OpenDBAPI {
|
||||||
opOperation.addOrSetStringValue("hash", hash);
|
opOperation.addOrSetStringValue("hash", hash);
|
||||||
opOperation.addOrSetStringValue("signature", signature);
|
opOperation.addOrSetStringValue("signature", signature);
|
||||||
TrafficStats.setThreadStatsTag(THREAD_ID);
|
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);
|
String json = formatter.opToJson(opOperation);
|
||||||
System.out.println("JSON: " + json);
|
System.out.println("JSON: " + json);
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
|
|
Loading…
Reference in a new issue