diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml index b8877dc710..e941075f54 100644 --- a/OsmAnd/res/layout/fragment_opr_login.xml +++ b/OsmAnd/res/layout/fragment_opr_login.xml @@ -1,114 +1,105 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + android:layout_height="@dimen/dialog_button_height" + android:layout_marginBottom="@dimen/content_padding_small" /> + android:layout_height="@dimen/dialog_button_height" /> - \ No newline at end of file + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index aaa8241710..72fb10e393 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,19 @@ Thx - Hardy --> + OsmAnd shows photos from several sources:\nOpenPlaceReviews - POI photos;\nMapillary - street-level imagery;\nWeb / Wikimedia - POI photos specified in OpenStreetMap data. + Use dev.openstreetmap.org + Switch to use "dev.openstreetmap.org" instead of "openstreetmap.org" to testing uploading OSM Note / POI / GPX. + Add to OpenPlaceReviews + Add to Mapillary + Select items that will be imported. + Select groups that will be imported. + There is not enough space + Your device only has %1$s free. Please free up some space or unselect some items to export. + Needed for import + Select the data to be exported to the file. + Approximate file size + Resources Select picture Cannot upload image, please, try again later Motorboat @@ -18,10 +31,10 @@ Search history I already have an account Create new account - Log in on the open data project website OpenPlaceReviews.org to upload even more photos. + Photos are provided by open data project OpenPlaceReviews.org. In order to upload your photos you need to sign up on website. Register on\nOpenPlaceReviews.org Add photo - Log in using the safe OAuth method or use your username and password. + You can log in using the safe OAuth method or use your login and password. Comment OSM Note Close OSM Note \"Trackable\" means the trace does not show up in any public listings, but processed trackpoints with timestamps from it (that can\'t be associated with you directly) do through downloads from the public GPS API. @@ -36,15 +49,15 @@ OsmAnd Live subscription has been expired There is a problem with your subscription. Click the button to go to the Google Play subscription settings to fix your payment method. Manage subscription - Username + Login Password Account - Log in with username and password - Log in to upload new or modified changes,\n\neither with OAuth or using your username and password. + Use login and password + You need to login to upload new or modified changes. \n\nYou can log in using the safe OAuth method or use your login and password. You can view all your not yet uploaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd. - Log in with OpenStreetMap - Login for OpenStreetMap.org - Login for OpenStreetMap + Sign in with OpenStreetMap + Login to OpenStreetMap.org + Login to OpenStreetMap These plugin setting are global, and apply to all profiles You need to add at least two points Travel diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 4d8ff2d548..8a82f4d96b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -51,6 +51,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; 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.OprStartFragment; import net.osmand.plus.osmedit.opr.OpenDBAPI; @@ -78,6 +79,8 @@ import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCa public class MenuBuilder { + private static final int PICK_IMAGE = 1231; + private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class); public static final float SHADOW_HEIGHT_TOP_DP = 17f; public static final int TITLE_LIMIT = 60; protected static final String[] arrowChars = new String[] {"=>", " - "}; @@ -107,10 +110,7 @@ public class MenuBuilder { private String preferredMapAppLang; private boolean transliterateNames; - private static final int PICK_IMAGE = 1231; - private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class); - private View view; - private OpenDBAPI openDBAPI = new OpenDBAPI(); + private final OpenDBAPI openDBAPI = new OpenDBAPI(); private String[] placeId = new String[0]; private GetImageCardsListener imageCardListener = new GetImageCardsListener() { @Override @@ -126,8 +126,7 @@ public class MenuBuilder { @Override public void onFinish(List cardList) { if (!isHidden()) { - List cards = new ArrayList<>(); - cards.addAll(cardList); + List cards = new ArrayList(cardList); if (cardList.size() == 0) { cards.add(new NoImagesCard(mapActivity)); } @@ -386,19 +385,7 @@ public class MenuBuilder { b.setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { - mapActivity.registerActivityResultListener(new ActivityResultListener(PICK_IMAGE, - new ActivityResultListener.OnActivityResultListener() { - @Override - public void onResult(int resultCode, Intent resultData) { - InputStream inputStream = null; - try { - inputStream = mapActivity.getContentResolver().openInputStream(resultData.getData()); - } catch (Exception e) { - LOG.error(e); - } - handleSelectedImage(view, inputStream); - } - })); + registerResultListener(view); final String privateKey = OPRWebviewActivity.getPrivateKeyFromCookie(); final String name = OPRWebviewActivity.getUsernameFromCookie(); if (privateKey == null || privateKey.isEmpty()) { @@ -408,7 +395,7 @@ public class MenuBuilder { new Thread(new Runnable() { @Override public void run() { - if (openDBAPI.checkPrivateKeyValid(name,privateKey)){ + if (openDBAPI.checkPrivateKeyValid(name, privateKey)) { app.runInUIThread(new Runnable() { @Override public void run() { @@ -419,64 +406,12 @@ public class MenuBuilder { mapActivity.getString(R.string.select_picture)), PICK_IMAGE); } }); - } - else { + } else { OprStartFragment.showInstance(mapActivity.getSupportFragmentManager()); } } }).start(); } - - private void handleSelectedImage(final View view, final InputStream image) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - uploadImageToPlace(view, image); - } catch (Exception e) { - LOG.error(e); - } - } - }); - t.start(); - } - - private void uploadImageToPlace(View view, InputStream image) { - //compress image - BufferedInputStream bufferedInputStream = new BufferedInputStream(image); - Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - bmp.compress(Bitmap.CompressFormat.PNG, 70, os); - byte[] buff = os.toByteArray(); - InputStream serverData = new ByteArrayInputStream(buff); - String url = BuildConfig.OPR_BASE_URL + "api/ipfs/image"; - String response = NetworkUtils.sendPostDataRequest(url, serverData); - if (response != null) { - int res = 0; - try { - res = openDBAPI.uploadImage( - placeId, - OPRWebviewActivity.getPrivateKeyFromCookie() -, OPRWebviewActivity.getUsernameFromCookie(), - response); - } catch (FailedVerificationException e) { - LOG.error(e); - app.showToastMessage(view.getResources().getString(R.string.cannot_upload_image)); - } - if (res != 200) { - //image was uploaded but not added to blockchain - app.showToastMessage(view.getResources().getString(R.string.cannot_upload_image)); - } else { - String str = MessageFormat.format(view.getResources() - .getString(R.string.successfully_uploaded_pattern), 1, 1); - app.showToastMessage(str); - //refresh the image - execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), imageCardListener)); - } - } else { - app.showToastMessage(view.getResources().getString(R.string.cannot_upload_image)); - } - } }); //TODO feature under development //b.setVisibility(View.GONE); @@ -493,6 +428,73 @@ public class MenuBuilder { false, null, false); } + private void registerResultListener(final View view) { + mapActivity.registerActivityResultListener(new ActivityResultListener(PICK_IMAGE, new ActivityResultListener. + OnActivityResultListener() { + @Override + public void onResult(int resultCode, Intent resultData) { + handleSelectedImage(view, resultData.getData()); + } + })); + } + + private void handleSelectedImage(final View view, final Uri uri) { + Thread t = new Thread(new Runnable() { + @Override + public void run() { + InputStream inputStream = null; + try { + inputStream = app.getContentResolver().openInputStream(uri); + if (inputStream != null) { + uploadImageToPlace(view, inputStream); + } + } catch (Exception e) { + LOG.error(e); + } finally { + Algorithms.closeStream(inputStream); + } + } + }); + t.start(); + } + + private void uploadImageToPlace(View view, InputStream image) { + InputStream serverData = new ByteArrayInputStream(compressImage(image)); + String url = BuildConfig.OPR_BASE_URL + "api/ipfs/image"; + String response = NetworkUtils.sendPostDataRequest(url, serverData); + if (response != null) { + int res = 0; + try { + res = openDBAPI.uploadImage( + placeId, + OPRWebviewActivity.getPrivateKeyFromCookie(), + OPRWebviewActivity.getUsernameFromCookie(), + response); + } catch (FailedVerificationException e) { + LOG.error(e); + app.showToastMessage(R.string.cannot_upload_image); + } + if (res != 200) { + //image was uploaded but not added to blockchain + app.showToastMessage(R.string.cannot_upload_image); + } else { + app.showToastMessage(R.string.successfully_uploaded_pattern, 1, 1); + //refresh the image + execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), imageCardListener)); + } + } else { + app.showToastMessage(R.string.cannot_upload_image); + } + } + + private byte[] compressImage(InputStream image) { + BufferedInputStream bufferedInputStream = new BufferedInputStream(image); + Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + bmp.compress(Bitmap.CompressFormat.PNG, 70, os); + return os.toByteArray(); + } + private void startLoadingImages() { if (onlinePhotoCardsRow == null) { return; @@ -500,7 +502,7 @@ public class MenuBuilder { startLoadingImagesTask(); } - private void startLoadingImagesTask(){ + private void startLoadingImagesTask() { onlinePhotoCards = new ArrayList<>(); onlinePhotoCardsRow.setProgressCard(); execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), imageCardListener)); diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java index 19a4ba57be..2f936cf21e 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java @@ -12,17 +12,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; - import net.osmand.PlatformUtil; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; - import org.apache.commons.logging.Log; public class OprStartFragment extends BaseOsmAndFragment {