From 02dbacf4fe09d48d719c56ed42a0fd524d0044ff Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 7 Oct 2020 12:10:59 +0300 Subject: [PATCH 1/9] amenity id --- .../builders/cards/ImageCard.java | 137 ++++++++++++------ .../plus/views/layers/ContextMenuLayer.java | 6 +- .../osmand/plus/views/layers/POIMapLayer.java | 2 +- 3 files changed, 95 insertions(+), 50 deletions(-) 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 c7cf92df0f..84a63cb72a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.builders.cards; import android.content.res.ColorStateList; import android.graphics.Bitmap; +import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.view.View; @@ -16,9 +17,13 @@ import androidx.appcompat.widget.AppCompatButton; import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; import net.osmand.Location; import net.osmand.data.Amenity; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.RotatedTileBox; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -26,6 +31,8 @@ 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.osmedit.OsmBugsLayer; +import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.plus.wikimedia.WikiImageHelper; import net.osmand.util.Algorithms; @@ -43,6 +50,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; + public abstract class ImageCard extends AbstractCard { public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; @@ -411,7 +420,7 @@ public abstract class ImageCard extends AbstractCard { } public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, - @Nullable Map params, GetImageCardsListener listener) { + @Nullable Map params, GetImageCardsListener listener) { this.mapActivity = mapActivity; this.app = mapActivity.getMyApplication(); this.latLon = latLon; @@ -422,64 +431,100 @@ public abstract class ImageCard extends AbstractCard { @Override protected List doInBackground(Void... params) { List result = new ArrayList<>(); - try { + RotatedTileBox rtb = mapActivity.getMapView().getCurrentRotatedTileBox(); + Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); + if (this.params != null) { + String wikidataId = this.params.get(Amenity.WIKIDATA); + if (wikidataId != null) { + this.params.remove(Amenity.WIKIDATA); + WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); + } + String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); + if (wikimediaContent != null) { + this.params.remove(Amenity.WIKIMEDIA_COMMONS); + WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); + } + } + if (o instanceof Amenity) { + Amenity am = (Amenity) o; + System.out.println("POINT OSM ID: " + am.getId() + " " + am.getType().ordinal()); final Map pms = new LinkedHashMap<>(); - pms.put("lat", "" + (float) latLon.getLatitude()); - pms.put("lon", "" + (float) latLon.getLongitude()); - Location myLocation = app.getLocationProvider().getLastKnownLocation(); - if (myLocation != null) { - pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); - } - pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); - String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); - if (Algorithms.isEmpty(preferredLang)) { - preferredLang = app.getLanguage(); - } - if (!Algorithms.isEmpty(preferredLang)) { - pms.put("lang", preferredLang); - } - if (this.params != null) { - String wikidataId = this.params.get(Amenity.WIKIDATA); - if (wikidataId != null) { - this.params.remove(Amenity.WIKIDATA); - WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); - } - String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); - if (wikimediaContent != null) { - this.params.remove(Amenity.WIKIMEDIA_COMMONS); - WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); - } - pms.putAll(this.params); - } + pms.put("osmid", "" + am.getId()); String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, "Requesting location images...", false, false); if (!Algorithms.isEmpty(response)) { - JSONObject obj = new JSONObject(response); - JSONArray images = obj.getJSONArray("features"); - if (images.length() > 0) { - for (int i = 0; i < images.length(); i++) { - try { - JSONObject imageObject = (JSONObject) images.get(i); - if (imageObject != JSONObject.NULL) { - ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); - if (imageCard != null) { - result.add(imageCard); + JSONObject obj = null; + try { + obj = new JSONObject(response); + JSONArray images = null; + images = obj.getJSONArray("features"); + if (images.length() > 0) { + for (int i = 0; i < images.length(); i++) { + try { + JSONObject imageObject = (JSONObject) images.get(i); + if (imageObject != JSONObject.NULL) { + ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); + if (imageCard != null) { + result.add(imageCard); + } } + } catch (JSONException e) { + e.printStackTrace(); } - } catch (JSONException e) { - e.printStackTrace(); } } + } catch (JSONException e) { + e.printStackTrace(); } } - } catch (Exception e) { - e.printStackTrace(); - } - if (listener != null) { - listener.onPostProcess(result); } return result; +// try { +// final Map pms = new LinkedHashMap<>(); +// pms.put("lat", "" + (float) latLon.getLatitude()); +// pms.put("lon", "" + (float) latLon.getLongitude()); +// Location myLocation = app.getLocationProvider().getLastKnownLocation(); +// if (myLocation != null) { +// pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); +// } +// pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); +// String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); +// if (Algorithms.isEmpty(preferredLang)) { +// preferredLang = app.getLanguage(); +// } +// if (!Algorithms.isEmpty(preferredLang)) { +// pms.put("lang", preferredLang); +// } +// String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, +// "Requesting location images...", false, false); +// +// if (!Algorithms.isEmpty(response)) { +// JSONObject obj = new JSONObject(response); +// JSONArray images = obj.getJSONArray("features"); +// if (images.length() > 0) { +// for (int i = 0; i < images.length(); i++) { +// try { +// JSONObject imageObject = (JSONObject) images.get(i); +// if (imageObject != JSONObject.NULL) { +// ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); +// if (imageCard != null) { +// result.add(imageCard); +// } +// } +// } catch (JSONException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// if (listener != null) { +// listener.onPostProcess(result); +// } +// return result; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index 7a8690fe2d..2902794ee8 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -907,9 +907,9 @@ public class ContextMenuLayer extends OsmandMapLayer { } @NonNull - private Map selectObjectsForContextMenu(RotatedTileBox tileBox, - PointF point, boolean acquireObjLatLon, - boolean unknownLocation) { + public Map selectObjectsForContextMenu(RotatedTileBox tileBox, + PointF point, boolean acquireObjLatLon, + boolean unknownLocation) { Map pressedLatLonFull = new HashMap<>(); Map pressedLatLonSmall = new HashMap<>(); Map selectedObjects = new HashMap<>(); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index ed0f2cc45d..d01ec310a9 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -66,7 +66,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon /// cache for displayed POI // Work with cache (for map copied from AmenityIndexRepositoryOdb) - private MapLayerData> data; + public MapLayerData> data; private OsmandApplication app; From b201f147aca39dccdfdbaa9561f5afdd3c23fa16 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 7 Oct 2020 14:23:34 +0300 Subject: [PATCH 2/9] #9621 Add validation for the online tracking link --- .../main/java/net/osmand/util/Algorithms.java | 16 ++++++++++++++ .../plus/monitoring/LiveMonitoringHelper.java | 16 +++++++++----- .../SettingsMonitoringActivity.java | 21 ++++++++++++++++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index ea2869aaa3..a1e721ac21 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -942,4 +942,20 @@ public class Algorithms { } return res; } + + public static boolean isValidMessageFormat(CharSequence sequence) { + if (!isEmpty(sequence)) { + int counter = 0; + for (int i = 0; i < sequence.length(); i++) { + char ch = sequence.charAt(i); + if (ch == '{') { + counter++; + } else if (ch == '}') { + counter--; + } + } + return counter == 0; + } + return false; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index 169507b35a..9ec8a3081c 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -131,7 +131,14 @@ public class LiveMonitoringHelper { } public void sendData(LiveMonitoringData data) { - String urlStr = getLiveUrl(data); + String baseUrl = app.getSettings().LIVE_MONITORING_URL.get(); + String urlStr; + try { + urlStr = getLiveUrl(baseUrl, data); + } catch (IllegalArgumentException e) { + log.error("Could not construct live url from base url: " + baseUrl, e); + return; + } try { // Parse the URL and let the URI constructor handle proper encoding of special characters such as spaces URL url = new URL(urlStr); @@ -172,12 +179,11 @@ public class LiveMonitoringHelper { } } - private String getLiveUrl(LiveMonitoringData data) { - String st = app.getSettings().LIVE_MONITORING_URL.get(); + private String getLiveUrl(String baseUrl, LiveMonitoringData data) { List prm = new ArrayList(); int maxLen = 0; for (int i = 0; i < 7; i++) { - boolean b = st.contains("{"+i+"}"); + boolean b = baseUrl.contains("{"+i+"}"); if(b) { maxLen = i; } @@ -210,6 +216,6 @@ public class LiveMonitoringHelper { break; } } - return MessageFormat.format(st, prm.toArray()); + return MessageFormat.format(baseUrl, prm.toArray()); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java index d048bbedd5..7ace6377ad 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java @@ -8,6 +8,7 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; @@ -23,11 +24,11 @@ import android.view.Window; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable; import net.osmand.plus.OsmandApplication; @@ -35,6 +36,8 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsBaseActivity; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.util.Algorithms; import java.util.Map; @@ -172,8 +175,20 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity { cat.setTitle(R.string.live_monitoring_m); grp.addPreference(cat); - cat.addPreference(createEditTextPreference(settings.LIVE_MONITORING_URL, R.string.live_monitoring_url, - R.string.live_monitoring_url_descr)); + EditTextPreference urlPreference = createEditTextPreference(settings.LIVE_MONITORING_URL, R.string.live_monitoring_url, + R.string.live_monitoring_url_descr); + urlPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (Algorithms.isValidMessageFormat((String) newValue)) { + return SettingsMonitoringActivity.super.onPreferenceChange(preference, newValue); + } else { + Toast.makeText(SettingsMonitoringActivity.this, R.string.wrong_format, Toast.LENGTH_SHORT).show(); + return false; + } + } + }); + cat.addPreference(urlPreference); final CheckBoxPreference liveMonitoring = createCheckBoxPreference(settings.LIVE_MONITORING, R.string.live_monitoring_m, R.string.live_monitoring_m_descr); cat.addPreference(liveMonitoring); From 878129ce93c17b688fc516530ef3806d10d59cb9 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 7 Oct 2020 17:01:51 +0300 Subject: [PATCH 3/9] photos added --- .../builders/cards/IPFSImageCard.java | 47 +++++ .../builders/cards/ImageCard.java | 183 +++++++++--------- 2 files changed, 143 insertions(+), 87 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java new file mode 100644 index 0000000000..b029c7cdfc --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java @@ -0,0 +1,47 @@ +package net.osmand.plus.mapcontextmenu.builders.cards; + +import android.view.View; +import net.osmand.plus.activities.MapActivity; +import net.osmand.util.Algorithms; +import org.json.JSONException; +import org.json.JSONObject; + +public class IPFSImageCard extends ImageCard { + private static final String BASE_URL = "https://test.openplacereviews.org/api/ipfs/image-ipfs?cid="; + + public IPFSImageCard(MapActivity mapActivity, JSONObject imageObject) { + super(mapActivity, imageObject); + try { + this.url = BASE_URL + imageObject.get("cid"); + this.imageHiresUrl = BASE_URL + imageObject.get("cid"); + this.imageUrl = BASE_URL + imageObject.get("cid"); + } catch (JSONException e) { + e.printStackTrace(); + } + if (!Algorithms.isEmpty(getSuitableUrl())) { + View.OnClickListener onClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + openUrl(getMapActivity(), getMyApplication(), getTitle(), getSuitableUrl(), + isExternalLink() || Algorithms.isEmpty(getImageHiresUrl()), + !Algorithms.isEmpty(getImageHiresUrl())); + } + }; + if (!Algorithms.isEmpty(buttonText)) { + this.onButtonClickListener = onClickListener; + } else { + this.onClickListener = onClickListener; + } + } + } + + private String getSuitableUrl() { + final String url; + if (Algorithms.isEmpty(getImageHiresUrl())) { + url = getUrl(); + } else { + url = getImageHiresUrl(); + } + return url; + } +} \ No newline at end of file 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 84a63cb72a..667b234956 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -4,6 +4,7 @@ import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.PointF; import android.graphics.drawable.Drawable; +import android.net.TrafficStats; import android.os.AsyncTask; import android.view.View; import android.view.View.OnClickListener; @@ -15,10 +16,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; -import net.osmand.AndroidNetworkUtils; -import net.osmand.AndroidUtils; -import net.osmand.GPXUtilities; -import net.osmand.Location; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import net.osmand.*; import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -28,6 +28,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapillary.MapillaryContributeCard; import net.osmand.plus.mapillary.MapillaryImageCard; @@ -36,6 +37,7 @@ import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.plus.wikimedia.WikiImageHelper; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -43,12 +45,7 @@ import org.json.JSONObject; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; @@ -57,6 +54,7 @@ public abstract class ImageCard extends AbstractCard { public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute"; + private static final Log LOG = PlatformUtil.getLog(ImageCard.class); protected String type; // Image location protected LatLon location; @@ -200,6 +198,14 @@ public abstract class ImageCard extends AbstractCard { return imageCard; } + private static ImageCard createCardOpr(MapActivity mapActivity, JSONObject imageObject) { + ImageCard imageCard = null; + if (imageObject.has("cid")) { + imageCard = new IPFSImageCard(mapActivity, imageObject); + } + return imageCard; + } + public double getCa() { return ca; } @@ -430,101 +436,104 @@ public abstract class ImageCard extends AbstractCard { @Override protected List doInBackground(Void... params) { + final int THREAD_ID = 10104; + TrafficStats.setThreadStatsTag(THREAD_ID); List result = new ArrayList<>(); RotatedTileBox rtb = mapActivity.getMapView().getCurrentRotatedTileBox(); Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); - if (this.params != null) { - String wikidataId = this.params.get(Amenity.WIKIDATA); - if (wikidataId != null) { - this.params.remove(Amenity.WIKIDATA); - WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); - } - String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); - if (wikimediaContent != null) { - this.params.remove(Amenity.WIKIMEDIA_COMMONS); - WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); - } - } if (o instanceof Amenity) { Amenity am = (Amenity) o; - System.out.println("POINT OSM ID: " + am.getId() + " " + am.getType().ordinal()); + long amenityId = (am.getId() >> 1); + getPicturesForPlace(result, amenityId); + } + try { final Map pms = new LinkedHashMap<>(); - pms.put("osmid", "" + am.getId()); + pms.put("lat", "" + (float) latLon.getLatitude()); + pms.put("lon", "" + (float) latLon.getLongitude()); + Location myLocation = app.getLocationProvider().getLastKnownLocation(); + if (myLocation != null) { + pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); + } + pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); + String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); + if (Algorithms.isEmpty(preferredLang)) { + preferredLang = app.getLanguage(); + } + if (!Algorithms.isEmpty(preferredLang)) { + pms.put("lang", preferredLang); + } + if (this.params != null) { + String wikidataId = this.params.get(Amenity.WIKIDATA); + if (wikidataId != null) { + this.params.remove(Amenity.WIKIDATA); + WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); + } + String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); + if (wikimediaContent != null) { + this.params.remove(Amenity.WIKIMEDIA_COMMONS); + WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); + } + pms.putAll(this.params); + } String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, "Requesting location images...", false, false); if (!Algorithms.isEmpty(response)) { - JSONObject obj = null; - try { - obj = new JSONObject(response); - JSONArray images = null; - images = obj.getJSONArray("features"); - if (images.length() > 0) { - for (int i = 0; i < images.length(); i++) { - try { - JSONObject imageObject = (JSONObject) images.get(i); - if (imageObject != JSONObject.NULL) { - ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); - if (imageCard != null) { - result.add(imageCard); - } + JSONObject obj = new JSONObject(response); + JSONArray images = obj.getJSONArray("features"); + if (images.length() > 0) { + for (int i = 0; i < images.length(); i++) { + try { + JSONObject imageObject = (JSONObject) images.get(i); + if (imageObject != JSONObject.NULL) { + ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); + if (imageCard != null) { + result.add(imageCard); } - } catch (JSONException e) { - e.printStackTrace(); } + } catch (JSONException e) { + e.printStackTrace(); } } - } catch (JSONException e) { - e.printStackTrace(); } } + } catch (Exception e) { + e.printStackTrace(); + } + if (listener != null) { + listener.onPostProcess(result); } return result; -// try { -// final Map pms = new LinkedHashMap<>(); -// pms.put("lat", "" + (float) latLon.getLatitude()); -// pms.put("lon", "" + (float) latLon.getLongitude()); -// Location myLocation = app.getLocationProvider().getLastKnownLocation(); -// if (myLocation != null) { -// pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); -// } -// pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); -// String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); -// if (Algorithms.isEmpty(preferredLang)) { -// preferredLang = app.getLanguage(); -// } -// if (!Algorithms.isEmpty(preferredLang)) { -// pms.put("lang", preferredLang); -// } -// String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, -// "Requesting location images...", false, false); -// -// if (!Algorithms.isEmpty(response)) { -// JSONObject obj = new JSONObject(response); -// JSONArray images = obj.getJSONArray("features"); -// if (images.length() > 0) { -// for (int i = 0; i < images.length(); i++) { -// try { -// JSONObject imageObject = (JSONObject) images.get(i); -// if (imageObject != JSONObject.NULL) { -// ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); -// if (imageCard != null) { -// result.add(imageCard); -// } -// } -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// } -// } -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// if (listener != null) { -// listener.onPostProcess(result); -// } -// return result; + } + + private void getPicturesForPlace(List result, long l) { + String url = "https://test.openplacereviews.org/api/objects-by-index?type=opr.place&index=osmid&limit=1&key=" + l; + String response = AndroidNetworkUtils.sendRequest(app, url, Collections.emptyMap(), + "Requesting location images...", false, false); + + try { + if (!Algorithms.isEmpty(response)) { + JSONArray obj = new JSONObject(response).getJSONArray("objects"); + JSONArray images = ((JSONObject) ((JSONObject) obj.get(0)).get("images")).getJSONArray("outdoor"); + if (images.length() > 0) { + for (int i = 0; i < images.length(); i++) { + try { + JSONObject imageObject = (JSONObject) images.get(i); + if (imageObject != JSONObject.NULL) { + ImageCard imageCard = ImageCard.createCardOpr(mapActivity, imageObject); + if (imageCard != null) { + result.add(imageCard); + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } + } catch (Exception e) { + LOG.error(e); + } } @Override From 4e3526e742fb0f02e1e8bf426f6608c808928821 Mon Sep 17 00:00:00 2001 From: sergosm Date: Wed, 7 Oct 2020 23:15:45 +0300 Subject: [PATCH 4/9] We have a few issues with text and icon colors. --- .../plus/wikivoyage/search/SearchRecyclerViewAdapter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java index 902b883e3d..e4c310c866 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java @@ -135,6 +135,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter Date: Thu, 8 Oct 2020 09:58:44 +0300 Subject: [PATCH 5/9] cleanup --- .../builders/cards/IPFSImageCard.java | 30 ++++++++----------- .../builders/cards/ImageCard.java | 8 ++--- .../osmand/plus/views/layers/POIMapLayer.java | 2 +- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java index b029c7cdfc..682cfe8abd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java @@ -1,28 +1,34 @@ package net.osmand.plus.mapcontextmenu.builders.cards; import android.view.View; +import net.osmand.AndroidNetworkUtils; +import net.osmand.PlatformUtil; import net.osmand.plus.activities.MapActivity; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; import org.json.JSONException; import org.json.JSONObject; public class IPFSImageCard extends ImageCard { private static final String BASE_URL = "https://test.openplacereviews.org/api/ipfs/image-ipfs?cid="; + private static final Log LOG = PlatformUtil.getLog(IPFSImageCard.class); public IPFSImageCard(MapActivity mapActivity, JSONObject imageObject) { super(mapActivity, imageObject); + String cid = ""; try { - this.url = BASE_URL + imageObject.get("cid"); - this.imageHiresUrl = BASE_URL + imageObject.get("cid"); - this.imageUrl = BASE_URL + imageObject.get("cid"); + cid = (String) imageObject.get("cid"); } catch (JSONException e) { - e.printStackTrace(); + LOG.error(e); } - if (!Algorithms.isEmpty(getSuitableUrl())) { + this.url = BASE_URL + cid; + this.imageHiresUrl = BASE_URL + cid; + this.imageUrl = BASE_URL + cid; + if (!Algorithms.isEmpty(getUrl())) { View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - openUrl(getMapActivity(), getMyApplication(), getTitle(), getSuitableUrl(), + openUrl(getMapActivity(), getMyApplication(), getTitle(), getUrl(), isExternalLink() || Algorithms.isEmpty(getImageHiresUrl()), !Algorithms.isEmpty(getImageHiresUrl())); } @@ -34,14 +40,4 @@ public class IPFSImageCard extends ImageCard { } } } - - private String getSuitableUrl() { - final String url; - if (Algorithms.isEmpty(getImageHiresUrl())) { - url = getUrl(); - } else { - url = getImageHiresUrl(); - } - return url; - } -} \ No newline at end of file +} 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 667b234956..9a4486b8a5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -418,6 +418,7 @@ public abstract class ImageCard extends AbstractCard { private Map params; private GetImageCardsListener listener; private List result; + private static final int GET_IMAGE_CARD_THREAD_ID = 10104; public interface GetImageCardsListener { void onPostProcess(List cardList); @@ -436,10 +437,8 @@ public abstract class ImageCard extends AbstractCard { @Override protected List doInBackground(Void... params) { - final int THREAD_ID = 10104; - TrafficStats.setThreadStatsTag(THREAD_ID); + TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID); List result = new ArrayList<>(); - RotatedTileBox rtb = mapActivity.getMapView().getCurrentRotatedTileBox(); Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); if (o instanceof Amenity) { Amenity am = (Amenity) o; @@ -510,7 +509,6 @@ public abstract class ImageCard extends AbstractCard { String url = "https://test.openplacereviews.org/api/objects-by-index?type=opr.place&index=osmid&limit=1&key=" + l; String response = AndroidNetworkUtils.sendRequest(app, url, Collections.emptyMap(), "Requesting location images...", false, false); - try { if (!Algorithms.isEmpty(response)) { JSONArray obj = new JSONObject(response).getJSONArray("objects"); @@ -526,7 +524,7 @@ public abstract class ImageCard extends AbstractCard { } } } catch (JSONException e) { - e.printStackTrace(); + LOG.error(e); } } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index d01ec310a9..ed0f2cc45d 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -66,7 +66,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon /// cache for displayed POI // Work with cache (for map copied from AmenityIndexRepositoryOdb) - public MapLayerData> data; + private MapLayerData> data; private OsmandApplication app; From 4eae0ee60a2494693e9523f49085ac9a3e241b3c Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 8 Oct 2020 10:03:58 +0300 Subject: [PATCH 6/9] cleanup --- .../plus/mapcontextmenu/builders/cards/IPFSImageCard.java | 8 ++++---- .../plus/mapcontextmenu/builders/cards/ImageCard.java | 2 +- .../net/osmand/plus/views/layers/ContextMenuLayer.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java index 682cfe8abd..45495ca8d0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java @@ -21,9 +21,9 @@ public class IPFSImageCard extends ImageCard { } catch (JSONException e) { LOG.error(e); } - this.url = BASE_URL + cid; - this.imageHiresUrl = BASE_URL + cid; - this.imageUrl = BASE_URL + cid; + url = BASE_URL + cid; + imageHiresUrl = BASE_URL + cid; + imageUrl = BASE_URL + cid; if (!Algorithms.isEmpty(getUrl())) { View.OnClickListener onClickListener = new View.OnClickListener() { @Override @@ -34,7 +34,7 @@ public class IPFSImageCard extends ImageCard { } }; if (!Algorithms.isEmpty(buttonText)) { - this.onButtonClickListener = onClickListener; + onButtonClickListener = onClickListener; } else { this.onClickListener = onClickListener; } 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 9a4486b8a5..1afb883231 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -442,7 +442,7 @@ public abstract class ImageCard extends AbstractCard { Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); if (o instanceof Amenity) { Amenity am = (Amenity) o; - long amenityId = (am.getId() >> 1); + long amenityId = am.getId() >> 1; getPicturesForPlace(result, amenityId); } try { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index 2902794ee8..7a8690fe2d 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -907,9 +907,9 @@ public class ContextMenuLayer extends OsmandMapLayer { } @NonNull - public Map selectObjectsForContextMenu(RotatedTileBox tileBox, - PointF point, boolean acquireObjLatLon, - boolean unknownLocation) { + private Map selectObjectsForContextMenu(RotatedTileBox tileBox, + PointF point, boolean acquireObjLatLon, + boolean unknownLocation) { Map pressedLatLonFull = new HashMap<>(); Map pressedLatLonSmall = new HashMap<>(); Map selectedObjects = new HashMap<>(); From 0cd8cd049f67f80853d3bc05d6837a0c2b673316 Mon Sep 17 00:00:00 2001 From: sergosm Date: Thu, 8 Oct 2020 11:53:45 +0300 Subject: [PATCH 7/9] update --- .../plus/wikivoyage/search/SearchRecyclerViewAdapter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java index e4c310c866..de9793d267 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java @@ -135,7 +135,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter Date: Thu, 8 Oct 2020 12:08:31 +0300 Subject: [PATCH 8/9] #9621 Add validation for the online tracking link to the new settings screen --- .../fragments/LiveMonitoringFragment.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/LiveMonitoringFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/LiveMonitoringFragment.java index e664953662..6a426e654c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/LiveMonitoringFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/LiveMonitoringFragment.java @@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import android.widget.Toast; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; @@ -12,11 +13,12 @@ import androidx.preference.Preference; import net.osmand.AndroidUtils; import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.preferences.EditTextPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx; +import net.osmand.util.Algorithms; import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MAX_INTERVAL_TO_SEND_MINUTES; @@ -60,6 +62,19 @@ public class LiveMonitoringFragment extends BaseSettingsFragment { updateToolbarSwitch(); } + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference.getKey().equals(settings.LIVE_MONITORING_URL.getId())) { + if (Algorithms.isValidMessageFormat((String) newValue)) { + return super.onPreferenceChange(preference, newValue); + } else { + Toast.makeText(app, R.string.wrong_format, Toast.LENGTH_SHORT).show(); + return false; + } + } + return super.onPreferenceChange(preference, newValue); + } + private void updateToolbarSwitch() { View view = getView(); if (view == null) { From e083c3958df2762f0f3601dd0d24298983533cd3 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 8 Oct 2020 12:50:33 +0300 Subject: [PATCH 9/9] Fix wrong place of configure profile --- OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java | 12 ++++++++++++ .../fragments/ConfigureMenuItemsFragment.java | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 7263f119bd..26e173d568 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -53,6 +53,9 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_PROFILE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SWITCH_PROFILE_ID; + public class ContextMenuAdapter { private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class); @@ -134,6 +137,15 @@ public class ContextMenuAdapter { Collections.sort(items, new Comparator() { @Override public int compare(ContextMenuItem item1, ContextMenuItem item2) { + if (DRAWER_SWITCH_PROFILE_ID.equals(item1.getId())) { + return -1; + } + if (DRAWER_CONFIGURE_PROFILE_ID.equals(item1.getId()) && DRAWER_SWITCH_PROFILE_ID.equals(item2.getId())) { + return 1; + } + if (DRAWER_CONFIGURE_PROFILE_ID.equals(item1.getId())) { + return -1; + } int order1 = item1.getOrder(); int order2 = item2.getOrder(); if (order1 < order2) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ConfigureMenuItemsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ConfigureMenuItemsFragment.java index 44fb4bf7f6..4d2309af82 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ConfigureMenuItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ConfigureMenuItemsFragment.java @@ -51,6 +51,8 @@ import java.util.HashMap; import java.util.List; import static net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_PROFILE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SWITCH_PROFILE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.plus.settings.fragments.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON; import static net.osmand.plus.settings.fragments.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION; @@ -183,7 +185,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment public static List getCustomizableDefaultItems(List defItems) { List items = new ArrayList<>(); for (ContextMenuItem item : defItems) { - if (!APP_PROFILES_ID.equals(item.getId())) { + if (!APP_PROFILES_ID.equals(item.getId()) + && !DRAWER_CONFIGURE_PROFILE_ID.equals(item.getId()) + && !DRAWER_SWITCH_PROFILE_ID.equals(item.getId())) { items.add(item); } }