diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml
index e941075f54..ee969b1a74 100644
--- a/OsmAnd/res/layout/fragment_opr_login.xml
+++ b/OsmAnd/res/layout/fragment_opr_login.xml
@@ -1,36 +1,22 @@
-
+
-
+ android:gravity="center_vertical"
+ android:padding="0dp" />
-
-
-
-
-
+ android:layout_height="0dp"
+ android:layout_weight="1">
+ app:typeface="@string/font_roboto_regular" />
+
-
+
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/subscription_fragment.xml b/OsmAnd/res/layout/subscription_fragment.xml
index 59b6f9b1b8..ad308e6be1 100644
--- a/OsmAnd/res/layout/subscription_fragment.xml
+++ b/OsmAnd/res/layout/subscription_fragment.xml
@@ -1,5 +1,4 @@
-
@@ -19,19 +19,19 @@
android:layout_width="52dp"
android:layout_height="52dp"
android:contentDescription="@string/shared_string_close"
- app:srcCompat="@drawable/ic_action_remove_dark"/>
+ app:srcCompat="@drawable/ic_action_remove_dark" />
+ app:typeface="@string/font_roboto_regular" />
@@ -39,7 +39,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
@@ -76,54 +76,81 @@
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
- app:srcCompat="@drawable/ic_action_osm_live"
- android:tint="@color/osmand_orange"/>
+ android:tint="@color/osmand_orange"
+ app:srcCompat="@drawable/ic_action_osm_live" />
+ android:textColor="?android:attr/textColorPrimary" />
+ android:orientation="horizontal">
+ android:layout_marginTop="@dimen/context_menu_second_line_top_margin"
+ android:layout_marginStart="@dimen/list_content_padding"
+ android:layout_marginLeft="@dimen/list_content_padding"
+ android:paddingStart="@dimen/local_size_height"
+ android:paddingLeft="@dimen/local_size_height"
+ android:paddingEnd="@dimen/local_size_height"
+ android:paddingRight="@dimen/local_size_height"
+ android:text="@string/donation_to_osm" />
-
+ android:minHeight="56dp"
+ android:orientation="vertical">
+
+
+
+
+
+
@@ -140,13 +167,13 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
- android:background="?attr/dashboard_divider"/>
+ android:background="?attr/dashboard_divider" />
@@ -155,47 +182,48 @@
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
- app:srcCompat="@drawable/ic_world_globe_dark"/>
+ app:srcCompat="@drawable/ic_world_globe_dark" />
+ android:layout_marginEnd="16dp"
+ android:layout_marginRight="16dp"
+ android:orientation="vertical">
+ android:textColor="?android:attr/textColorSecondary" />
+ app:drawableEndCompat="@drawable/ic_action_arrow_drop_down"
+ app:drawableRightCompat="@drawable/ic_action_arrow_drop_down" />
+ android:textColor="?android:attr/textColorSecondary" />
@@ -213,21 +241,21 @@
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
- app:srcCompat="@drawable/ic_action_message"/>
+ app:srcCompat="@drawable/ic_action_message" />
+ android:paddingStart="2dp"
+ android:paddingLeft="2dp" />
@@ -235,14 +263,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
+ android:layout_marginStart="72dp"
android:layout_marginLeft="72dp"
+ android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
+ android:paddingStart="2dp"
android:paddingLeft="2dp"
android:text="@string/osm_live_email_desc"
- android:textColor="?android:attr/textColorSecondary"
- android:paddingStart="2dp"
- android:layout_marginStart="72dp"
- android:layout_marginEnd="16dp" />
+ android:textColor="?android:attr/textColorSecondary" />
+ app:srcCompat="@drawable/ic_action_user" />
+ android:paddingStart="2dp"
+ android:paddingLeft="2dp" />
@@ -284,16 +312,16 @@
android:id="@+id/hideUserNameCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginStart="72dp"
android:layout_marginLeft="72dp"
- android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginRight="16dp"
+ android:layout_marginBottom="12dp"
+ android:paddingStart="4dp"
android:paddingLeft="4dp"
android:text="@string/osm_live_hide_user_name"
- android:textColor="?android:attr/textColorPrimary"
- android:layout_marginEnd="16dp"
- android:paddingStart="4dp"
- android:layout_marginStart="72dp" />
+ android:textColor="?android:attr/textColorPrimary" />
@@ -303,35 +331,35 @@
android:id="@+id/editModeBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
+ android:layout_marginBottom="16dp"
android:visibility="visible">
+ android:textColor="@color/color_white" />
-
+
+ android:layout_height="16dp" />
diff --git a/OsmAnd/res/layout/two_line_with_images_list_item.xml b/OsmAnd/res/layout/two_line_with_images_list_item.xml
index 66b2777765..4ef2c29631 100644
--- a/OsmAnd/res/layout/two_line_with_images_list_item.xml
+++ b/OsmAnd/res/layout/two_line_with_images_list_item.xml
@@ -24,7 +24,7 @@
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:src="@drawable/ic_map"
- android:layout_marginEnd="@dimen/favorites_icon_right_margin" />
+ android:layout_marginEnd="@dimen/favorites_icon_right_margin" />
+ android:layout_marginStart="@dimen/dashFavIconMargin" />
+ android:textColor="@color/text_color_tab_active_light"
+ android:visibility="gone" />
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 1d23e9db07..a15fb40cbd 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -12,6 +12,10 @@
-->
+ Login to OpenPlaceReviews
+ Use test.openplacereviews.org
+ OpenPlaceReviews
+ OpenPlaceReviews is a community-driven project about public places such as restaurants, hotels, museums, waypoints. It collects all public information about them such as photos, reviews, links to other systems link OpenStreetMap, Wikipedia.\n\nAll OpenPlaceReview data is open and available to everyone: http://openplacereviews.org/data.\n\nYou can read more at: http://openplacereviews.org
Hillshade / Slope / Contour lines
Select edits for upload
Uploaded %1$d of %2$d
diff --git a/OsmAnd/res/xml/open_place_reviews.xml b/OsmAnd/res/xml/open_place_reviews.xml
new file mode 100644
index 0000000000..f58c2be074
--- /dev/null
+++ b/OsmAnd/res/xml/open_place_reviews.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java
index 424855f2a0..065c7aba2e 100644
--- a/OsmAnd/src/net/osmand/plus/AppInitializer.java
+++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java
@@ -28,7 +28,6 @@ import net.osmand.map.OsmandRegions.RegionTranslation;
import net.osmand.map.WorldRegion;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
-import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.SavingTrackHelper;
@@ -36,6 +35,7 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.helpers.AvoidSpecificRoads;
+import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppPurchaseHelperImpl;
@@ -45,6 +45,7 @@ import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
+import net.osmand.plus.openplacereviews.OprAuthHelper;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry;
@@ -468,6 +469,7 @@ public class AppInitializer implements IProgress {
app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class);
app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
+ app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
initOpeningHoursParser();
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index b794a5bc0a..9d2524d30c 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -70,6 +70,7 @@ import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
+import net.osmand.plus.openplacereviews.OprAuthHelper;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry;
@@ -161,6 +162,7 @@ public class OsmandApplication extends MultiDexApplication {
GpxDbHelper gpxDbHelper;
QuickActionRegistry quickActionRegistry;
OsmOAuthHelper osmOAuthHelper;
+ OprAuthHelper oprAuthHelper;
MeasurementEditingContext measurementEditingContext;
OnlineRoutingHelper onlineRoutingHelper;
@@ -396,6 +398,10 @@ public class OsmandApplication extends MultiDexApplication {
return osmOAuthHelper;
}
+ public OprAuthHelper getOprAuthHelper() {
+ return oprAuthHelper;
+ }
+
public synchronized DownloadIndexesThread getDownloadThread() {
if (downloadIndexesThread == null) {
downloadIndexesThread = new DownloadIndexesThread(this);
diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
index e04f055b35..d3bcfb205e 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
@@ -35,9 +35,12 @@ import net.osmand.plus.dialogs.PluginInstalledBottomSheetDialog;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.mapillary.MapillaryPlugin;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity;
+import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
@@ -66,6 +69,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
public abstract class OsmandPlugin {
@@ -133,7 +137,7 @@ public abstract class OsmandPlugin {
public boolean init(@NonNull OsmandApplication app, @Nullable Activity activity) {
if (activity != null) {
// called from UI
- for (ApplicationMode appMode: getAddedAppModes()) {
+ for (ApplicationMode appMode : getAddedAppModes()) {
ApplicationMode.changeProfileAvailability(appMode, true, app);
}
}
@@ -208,6 +212,16 @@ public abstract class OsmandPlugin {
return Collections.emptyList();
}
+ protected List getContextMenuImageCards(@NonNull Map params,
+ @Nullable Map additionalParams,
+ @Nullable GetImageCardsListener listener) {
+ return Collections.emptyList();
+ }
+
+ protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
+ return null;
+ }
+
/**
* Plugin was installed
*/
@@ -266,9 +280,9 @@ public abstract class OsmandPlugin {
allPlugins.clear();
- enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app));
enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
+ allPlugins.add(new MapillaryPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
@@ -282,6 +296,7 @@ public abstract class OsmandPlugin {
checkMarketPlugin(app, enabledPlugins, new ParkingPositionPlugin(app));
allPlugins.add(new AccessibilityPlugin(app));
allPlugins.add(new OsmEditingPlugin(app));
+ allPlugins.add(new OpenPlaceReviewsPlugin(app));
allPlugins.add(new OsmandDevelopmentPlugin(app));
loadCustomPlugins(app);
@@ -734,7 +749,6 @@ public abstract class OsmandPlugin {
return l;
}
-
public static void onMapActivityCreate(MapActivity activity) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.mapActivityCreate(activity);
@@ -868,6 +882,23 @@ public abstract class OsmandPlugin {
return collection;
}
+ public static void populateContextMenuImageCards(@NonNull List imageCards, @NonNull Map params,
+ @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) {
+ for (OsmandPlugin plugin : getEnabledPlugins()) {
+ imageCards.addAll(plugin.getContextMenuImageCards(params, additionalParams, listener));
+ }
+ }
+
+ public static ImageCard createImageCardForJson(@NonNull JSONObject imageObject) {
+ for (OsmandPlugin plugin : getEnabledPlugins()) {
+ ImageCard imageCard = plugin.createContextMenuImageCard(imageObject);
+ if (imageCard != null) {
+ return imageCard;
+ }
+ }
+ return null;
+ }
+
public static boolean isPackageInstalled(String packageInfo, Context ctx) {
if (packageInfo == null) {
return false;
diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java
index 10997d0f07..33d6fed3ac 100644
--- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java
@@ -143,8 +143,8 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
@Override
public void disable(OsmandApplication app) {
- if (app.getSettings().USE_DEV_URL.get()) {
- app.getSettings().USE_DEV_URL.set(false);
+ if (app.getSettings().OSM_USE_DEV_URL.get()) {
+ app.getSettings().OSM_USE_DEV_URL.set(false);
app.getOsmOAuthHelper().resetAuthorization();
}
super.disable(app);
diff --git a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java
index 05e4bcc468..cd06804f5e 100644
--- a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java
@@ -19,9 +19,9 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
-import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosListener;
+import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosProgressListener;
-public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragment implements UploadPhotosListener {
+public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragment implements UploadPhotosProgressListener {
public static final String TAG = UploadPhotoProgressBottomSheet.class.getSimpleName();
@@ -103,7 +103,7 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
return uploadingFinished ? R.string.shared_string_close : R.string.shared_string_cancel;
}
- public static UploadPhotosListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
+ public static UploadPhotosProgressListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
fragment.setRetainInstance(true);
fragment.setMaxProgress(maxProgress);
diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java
index 0d569ba880..1649e1ea1a 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java
@@ -22,6 +22,7 @@ import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants;
+import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -326,8 +327,8 @@ public class IntentHelper {
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);
- app.getSettings().OPR_USERNAME.set(username);
+ app.getOprAuthHelper().addListener(getOprAuthorizationListener());
+ app.getOprAuthHelper().authorize(token, username);
mapActivity.setIntent(null);
return true;
}
@@ -348,6 +349,19 @@ public class IntentHelper {
};
}
+ private OprAuthorizationListener getOprAuthorizationListener() {
+ return new OprAuthorizationListener() {
+ @Override
+ public void authorizationCompleted() {
+ for (Fragment fragment : mapActivity.getSupportFragmentManager().getFragments()) {
+ if (fragment instanceof OprAuthorizationListener) {
+ ((OprAuthorizationListener) fragment).authorizationCompleted();
+ }
+ }
+ }
+ };
+ }
+
private boolean handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (!Algorithms.isEmpty(sharedText)) {
diff --git a/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java
index 9ae0e9b59b..7286c7ee19 100644
--- a/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java
+++ b/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java
@@ -63,7 +63,7 @@ class GpxOrFavouritesImportTask extends BaseLoadAsyncTask {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(ImportHelper.KML_SUFFIX)) {
- InputStream gpxStream = convertKmlToGpxStream(is);
+ InputStream gpxStream = convertKmlToGpxStream(zis);
if (gpxStream != null) {
fileSize = gpxStream.available();
return GPXUtilities.loadGPXFile(gpxStream);
diff --git a/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java
index 6a145a04f7..2ed67cc0e4 100644
--- a/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java
+++ b/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java
@@ -49,7 +49,7 @@ class KmzImportTask extends BaseLoadAsyncTask {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(KML_SUFFIX)) {
- InputStream gpxStream = convertKmlToGpxStream(is);
+ InputStream gpxStream = convertKmlToGpxStream(zis);
if (gpxStream != null) {
fileSize = gpxStream.available();
return GPXUtilities.loadGPXFile(gpxStream);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
index 93f2bdf6b5..2ad2bb6ee4 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
@@ -36,6 +36,7 @@ import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import net.osmand.AndroidUtils;
+import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@@ -47,11 +48,12 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
-import net.osmand.plus.Version;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
+import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosListener;
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
@@ -75,6 +77,10 @@ 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.json.JSONException;
+import org.json.JSONObject;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -87,6 +93,7 @@ import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCa
public class MenuBuilder {
+ private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class);
private static final int PICK_IMAGE = 1231;
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
@@ -131,16 +138,14 @@ public class MenuBuilder {
}
@Override
- public void onPlaceIdAcquired(String[] placeId) {
+ public void onPlaceIdAcquired(final String[] placeId) {
MenuBuilder.this.placeId = placeId;
- if (placeId.length < 2) {
- app.runInUIThread(new Runnable() {
- @Override
- public void run() {
- photoButton.setVisibility(View.GONE);
- }
- });
- }
+ app.runInUIThread(new Runnable() {
+ @Override
+ public void run() {
+ AndroidUiHelper.updateVisibility(photoButton, placeId.length >= 2);
+ }
+ });
}
@Override
@@ -158,6 +163,16 @@ public class MenuBuilder {
}
};
+ public void addImageCard(ImageCard card) {
+ if (onlinePhotoCards.size() == 1 && onlinePhotoCards.get(0) instanceof NoImagesCard) {
+ onlinePhotoCards.clear();
+ }
+ onlinePhotoCards.add(0, card);
+ if (onlinePhotoCardsRow != null) {
+ onlinePhotoCardsRow.setCards(onlinePhotoCards);
+ }
+ }
+
public interface CollapseExpandListener {
void onCollapseExpand(boolean collapsed);
}
@@ -443,10 +458,7 @@ public class MenuBuilder {
}
}
});
- //TODO This feature is under development
- if (!Version.isDeveloperVersion(app)) {
- view.setVisibility(View.GONE);
- }
+ AndroidUiHelper.updateVisibility(view, false);
photoButton = view;
return view;
}
@@ -481,7 +493,27 @@ public class MenuBuilder {
}
}
}
- execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, getLatLon(), placeId, getAdditionalCardParams(), imageCardListener));
+ UploadPhotosListener listener = new UploadPhotosListener() {
+ @Override
+ public void uploadPhotosSuccess(final String response) {
+ app.runInUIThread(new Runnable() {
+ @Override
+ public void run() {
+ if (AndroidUtils.isActivityNotDestroyed(mapActivity)) {
+ try {
+ ImageCard imageCard = OsmandPlugin.createImageCardForJson(new JSONObject(response));
+ if (imageCard != null) {
+ addImageCard(imageCard);
+ }
+ } catch (JSONException e) {
+ LOG.error(e);
+ }
+ }
+ }
+ });
+ }
+ };
+ execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, placeId, listener));
}
}
}));
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java
index afe492af6f..cf0587e06f 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java
@@ -13,14 +13,11 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
-import net.osmand.data.LatLon;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.UploadPhotoProgressBottomSheet;
-import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
-import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.openplacereviews.OprStartFragment;
import net.osmand.plus.osmedit.opr.OpenDBAPI;
@@ -36,7 +33,6 @@ import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
public class UploadPhotosAsyncTask extends AsyncTask {
@@ -47,22 +43,17 @@ public class UploadPhotosAsyncTask extends AsyncTask {
private final OsmandApplication app;
private final WeakReference activityRef;
private final OpenDBAPI openDBAPI = new OpenDBAPI();
- private final LatLon latLon;
private final List data;
private final String[] placeId;
- private final Map params;
- private final GetImageCardsListener imageCardListener;
- private UploadPhotosListener listener;
+ private final UploadPhotosListener listener;
+ private UploadPhotosProgressListener progressListener;
- public UploadPhotosAsyncTask(MapActivity activity, List data, LatLon latLon, String[] placeId,
- Map params, GetImageCardsListener imageCardListener) {
+ public UploadPhotosAsyncTask(MapActivity activity, List data, String[] placeId, UploadPhotosListener listener) {
app = (OsmandApplication) activity.getApplicationContext();
activityRef = new WeakReference<>(activity);
this.data = data;
- this.latLon = latLon;
- this.params = params;
this.placeId = placeId;
- this.imageCardListener = imageCardListener;
+ this.listener = listener;
}
@Override
@@ -70,7 +61,7 @@ public class UploadPhotosAsyncTask extends AsyncTask {
FragmentActivity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
FragmentManager manager = activity.getSupportFragmentManager();
- listener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() {
+ progressListener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
cancel(false);
@@ -81,8 +72,8 @@ public class UploadPhotosAsyncTask extends AsyncTask {
@Override
protected void onProgressUpdate(Integer... values) {
- if (listener != null) {
- listener.uploadPhotosProgressUpdate(values[0]);
+ if (progressListener != null) {
+ progressListener.uploadPhotosProgressUpdate(values[0]);
}
}
@@ -103,8 +94,8 @@ public class UploadPhotosAsyncTask extends AsyncTask {
@Override
protected void onPostExecute(Void aVoid) {
- if (listener != null) {
- listener.uploadPhotosFinished();
+ if (progressListener != null) {
+ progressListener.uploadPhotosFinished();
}
}
@@ -156,13 +147,9 @@ public class UploadPhotosAsyncTask extends AsyncTask {
checkTokenAndShowScreen();
} else {
success = true;
- String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
- app.showToastMessage(str);
//refresh the image
-
- MapActivity activity = activityRef.get();
- if (activity != null) {
- MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
+ if (listener != null) {
+ listener.uploadPhotosSuccess(response);
}
}
} else {
@@ -215,12 +202,17 @@ public class UploadPhotosAsyncTask extends AsyncTask {
return os.toByteArray();
}
-
- public interface UploadPhotosListener {
+ public interface UploadPhotosProgressListener {
void uploadPhotosProgressUpdate(int progress);
void uploadPhotosFinished();
}
+
+ public interface UploadPhotosListener {
+
+ void uploadPhotosSuccess(String response);
+
+ }
}
\ 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 86fd8c2d81..a7e538b211 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java
@@ -19,17 +19,13 @@ import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.PlatformUtil;
-import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
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.OPRConstants;
-import net.osmand.plus.wikimedia.WikiImageHelper;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@@ -41,18 +37,17 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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;
+import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_CONTRIBUTE;
+import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_PHOTO;
+
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;
@@ -184,11 +179,7 @@ public abstract class ImageCard extends AbstractCard {
try {
if (imageObject.has("type")) {
String type = imageObject.getString("type");
- if (TYPE_MAPILLARY_PHOTO.equals(type)) {
- imageCard = new MapillaryImageCard(mapActivity, imageObject);
- } else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) {
- imageCard = new MapillaryContributeCard(mapActivity, imageObject);
- } else {
+ if (!TYPE_MAPILLARY_CONTRIBUTE.equals(type) && !TYPE_MAPILLARY_PHOTO.equals(type)) {
imageCard = new UrlImageCard(mapActivity, imageObject);
}
}
@@ -198,14 +189,6 @@ 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;
}
@@ -410,28 +393,6 @@ public abstract class ImageCard extends AbstractCard {
}
}
- private static String[] getIdFromResponse(String response) {
- try {
- JSONArray obj = new JSONObject(response).getJSONArray("objects");
- JSONArray images = (JSONArray) ((JSONObject) obj.get(0)).get("id");
- return toStringArray(images);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return new String[0];
- }
-
- private static String[] toStringArray(JSONArray array) {
- if (array == null)
- return null;
-
- String[] arr = new String[array.length()];
- for (int i = 0; i < arr.length; i++) {
- arr[i] = array.optString(i);
- }
- return arr;
- }
-
public static class GetImageCardsTask extends AsyncTask> {
private MapActivity mapActivity;
@@ -451,7 +412,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;
@@ -460,23 +421,9 @@ public abstract class ImageCard extends AbstractCard {
}
@Override
- protected List doInBackground(Void... params) {
+ protected List doInBackground(Void... voids) {
TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID);
List result = new ArrayList<>();
- Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject();
- if (o instanceof Amenity) {
- Amenity am = (Amenity) o;
- long amenityId = am.getId() >> 1;
- 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.emptyMap(),
- "Requesting location images...", false, false);
- if (response != null) {
- getPicturesForPlace(result, response);
- String[] id = getIdFromResponse(response);
- listener.onPlaceIdAcquired(id);
- }
- }
try {
final Map pms = new LinkedHashMap<>();
pms.put("lat", "" + (float) latLon.getLatitude());
@@ -493,19 +440,8 @@ public abstract class ImageCard extends AbstractCard {
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);
- }
+ OsmandPlugin.populateContextMenuImageCards(result, pms, params, listener);
+
String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
"Requesting location images...", false, false);
@@ -517,7 +453,10 @@ public abstract class ImageCard extends AbstractCard {
try {
JSONObject imageObject = (JSONObject) images.get(i);
if (imageObject != JSONObject.NULL) {
- ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject);
+ ImageCard imageCard = OsmandPlugin.createImageCardForJson(imageObject);
+ if (imageCard == null) {
+ imageCard = ImageCard.createCard(mapActivity, imageObject);
+ }
if (imageCard != null) {
result.add(imageCard);
}
@@ -537,36 +476,6 @@ public abstract class ImageCard extends AbstractCard {
return result;
}
- private void getPicturesForPlace(List result, String response) {
- try {
- if (!Algorithms.isEmpty(response)) {
- JSONArray obj = new JSONObject(response).getJSONArray("objects");
- JSONObject imagesWrapper = ((JSONObject) ((JSONObject) obj.get(0)).get("images"));
- Iterator it = imagesWrapper.keys();
- while (it.hasNext()) {
- JSONArray images = imagesWrapper.getJSONArray(it.next());
- 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) {
- LOG.error(e);
- }
- }
- }
- }
- }
- } catch (Exception e) {
- LOG.error(e);
- }
- }
-
@Override
protected void onPostExecute(List cardList) {
result = cardList;
diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java
index 770f973592..1996d8bed5 100644
--- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java
@@ -17,27 +17,34 @@ import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
+import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
-import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
-import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
-import net.osmand.plus.views.layers.MapInfoLayer;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
+import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
+import net.osmand.plus.settings.backend.ApplicationMode;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
+import net.osmand.plus.views.layers.MapInfoLayer;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms;
+import org.apache.commons.logging.Log;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.text.MessageFormat;
import java.util.List;
@@ -47,11 +54,18 @@ import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction;
public class MapillaryPlugin extends OsmandPlugin {
+ public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo";
+ public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute";
+
public static final String ID = "osmand.mapillary";
private static final String MAPILLARY_PACKAGE_ID = "app.mapillary";
+ private static final Log LOG = PlatformUtil.getLog(OpenPlaceReviewsPlugin.class);
+
private OsmandSettings settings;
+ private MapActivity mapActivity;
+
private MapillaryRasterLayer rasterLayer;
private MapillaryVectorLayer vectorLayer;
private TextInfoWidget mapillaryControl;
@@ -62,11 +76,6 @@ public class MapillaryPlugin extends OsmandPlugin {
settings = app.getSettings();
}
- @Override
- public boolean isVisible() {
- return false;
- }
-
@Override
public int getLogoResourceId() {
return R.drawable.ic_action_mapillary;
@@ -228,6 +237,41 @@ public class MapillaryPlugin extends OsmandPlugin {
}
}
+ @Override
+ protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
+ ImageCard imageCard = null;
+ if (mapActivity != null) {
+ try {
+ if (imageObject.has("type")) {
+ String type = imageObject.getString("type");
+ if (TYPE_MAPILLARY_PHOTO.equals(type)) {
+ imageCard = new MapillaryImageCard(mapActivity, imageObject);
+ } else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) {
+ imageCard = new MapillaryContributeCard(mapActivity, imageObject);
+ }
+ }
+ } catch (JSONException e) {
+ LOG.error(e);
+ }
+ }
+ return imageCard;
+ }
+
+ @Override
+ public void mapActivityResume(MapActivity activity) {
+ this.mapActivity = activity;
+ }
+
+ @Override
+ public void mapActivityResumeOnTop(MapActivity activity) {
+ this.mapActivity = activity;
+ }
+
+ @Override
+ public void mapActivityPause(MapActivity activity) {
+ this.mapActivity = null;
+ }
+
public static boolean openMapillary(FragmentActivity activity, String imageKey) {
boolean success = false;
OsmandApplication app = (OsmandApplication) activity.getApplication();
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java b/OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java
similarity index 86%
rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java
rename to OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java
index 63f02d10fe..ccf52f7de9 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java
@@ -1,12 +1,16 @@
-package net.osmand.plus.mapcontextmenu.builders.cards;
+package net.osmand.plus.openplacereviews;
import android.view.View;
+
import androidx.core.content.ContextCompat;
+
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.util.Algorithms;
+
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
@@ -22,7 +26,7 @@ public class IPFSImageCard extends ImageCard {
} catch (JSONException e) {
LOG.error(e);
}
- String BASE_URL = mapActivity.getString(R.string.opr_base_url) + "api/ipfs/image-ipfs?cid=";
+ String BASE_URL = OPRConstants.getBaseUrl(mapActivity.getMyApplication()) + "api/ipfs/image-ipfs?cid=";
url = BASE_URL + cid;
imageHiresUrl = BASE_URL + cid;
imageUrl = BASE_URL + cid;
diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRConstants.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRConstants.java
index a329e48235..a8901e2b0b 100644
--- a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRConstants.java
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRConstants.java
@@ -1,9 +1,9 @@
package net.osmand.plus.openplacereviews;
-import android.content.Context;
+import androidx.annotation.NonNull;
-import net.osmand.plus.R;
+import net.osmand.plus.OsmandApplication;
import net.osmand.plus.osmedit.opr.OpenDBAPI;
public class OPRConstants {
@@ -11,28 +11,27 @@ public class OPRConstants {
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 getBaseUrl(@NonNull OsmandApplication app) {
+ return app.getSettings().getOprUrl();
}
-
- public static String getLoginUrl(Context ctx) {
- return getBaseUrl(ctx) + "login" + getQueryString(ctx);
+ public static String getLoginUrl(@NonNull OsmandApplication app) {
+ return getBaseUrl(app) + "login" + getQueryString();
}
- public static String getRegisterUrl(Context ctx) {
- return getBaseUrl(ctx) + "signup" + getQueryString(ctx);
+ public static String getRegisterUrl(@NonNull OsmandApplication app) {
+ return getBaseUrl(app) + "signup" + getQueryString();
}
- public static String getQueryString(Context ctx) {
- return "?" + getPurposeParam(ctx) + "&" + getCallbackParam(ctx);
+ public static String getQueryString() {
+ return "?" + getPurposeParam() + "&" + getCallbackParam();
}
- public static String getPurposeParam(Context ctx) {
+ public static String getPurposeParam() {
return "purpose=" + PURPOSE;
}
- public static String getCallbackParam(Context ctx) {
+ public static String getCallbackParam() {
return "callback=" + CALLBACK_URL;
}
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java
new file mode 100644
index 0000000000..3df34da0fd
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java
@@ -0,0 +1,182 @@
+package net.osmand.plus.openplacereviews;
+
+import android.graphics.drawable.Drawable;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import net.osmand.AndroidNetworkUtils;
+import net.osmand.PlatformUtil;
+import net.osmand.data.Amenity;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
+import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
+import net.osmand.util.Algorithms;
+
+import org.apache.commons.logging.Log;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class OpenPlaceReviewsPlugin extends OsmandPlugin {
+
+ private static final Log LOG = PlatformUtil.getLog(OpenPlaceReviewsPlugin.class);
+
+ private static final String ID = "osmand.openplacereviews";
+
+ private MapActivity mapActivity;
+
+ public OpenPlaceReviewsPlugin(OsmandApplication app) {
+ super(app);
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+
+ @Override
+ public String getName() {
+ return app.getString(R.string.open_place_reviews);
+ }
+
+ @Override
+ public CharSequence getDescription() {
+ return app.getString(R.string.open_place_reviews_plugin_description);
+ }
+
+ @Override
+ public SettingsScreenType getSettingsScreenType() {
+ return SettingsScreenType.OPEN_PLACE_REVIEWS;
+ }
+
+ @Override
+ public int getLogoResourceId() {
+ return R.drawable.ic_img_logo_openplacereview;
+ }
+
+ @Override
+ public Drawable getAssetResourceImage() {
+ return app.getUIUtilities().getIcon(R.drawable.img_plugin_openplacereviews);
+ }
+
+ @Override
+ public void mapActivityResume(MapActivity activity) {
+ this.mapActivity = activity;
+ }
+
+ @Override
+ public void mapActivityResumeOnTop(MapActivity activity) {
+ this.mapActivity = activity;
+ }
+
+ @Override
+ public void mapActivityPause(MapActivity activity) {
+ this.mapActivity = null;
+ }
+
+ @Override
+ protected List getContextMenuImageCards(@NonNull Map params,
+ @Nullable Map additionalParams,
+ @Nullable GetImageCardsListener listener) {
+ List imageCards = new ArrayList<>();
+ if (mapActivity != null) {
+ Object object = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject();
+ if (object instanceof Amenity) {
+ Amenity am = (Amenity) object;
+ long amenityId = am.getId() >> 1;
+ 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.emptyMap(),
+ "Requesting location images...", false, false);
+ if (response != null) {
+ getPicturesForPlace(imageCards, response);
+ if (listener != null) {
+ listener.onPlaceIdAcquired(getIdFromResponse(response));
+ }
+ }
+ }
+ }
+ return imageCards;
+ }
+
+ private void getPicturesForPlace(List result, String response) {
+ try {
+ if (!Algorithms.isEmpty(response)) {
+ JSONArray obj = new JSONObject(response).getJSONArray("objects");
+ JSONObject imagesWrapper = ((JSONObject) ((JSONObject) obj.get(0)).get("images"));
+ Iterator it = imagesWrapper.keys();
+ while (it.hasNext()) {
+ JSONArray images = imagesWrapper.getJSONArray(it.next());
+ 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 = createCardOpr(mapActivity, imageObject);
+ if (imageCard != null) {
+ result.add(imageCard);
+ }
+ }
+ } catch (JSONException e) {
+ LOG.error(e);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.error(e);
+ }
+ }
+
+ public static ImageCard createCardOpr(MapActivity mapActivity, JSONObject imageObject) {
+ ImageCard imageCard = null;
+ if (imageObject.has("cid")) {
+ imageCard = new IPFSImageCard(mapActivity, imageObject);
+ }
+ return imageCard;
+ }
+
+ private static String[] getIdFromResponse(String response) {
+ try {
+ JSONArray obj = new JSONObject(response).getJSONArray("objects");
+ JSONArray images = (JSONArray) ((JSONObject) obj.get(0)).get("id");
+ return toStringArray(images);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return new String[0];
+ }
+
+ private static String[] toStringArray(JSONArray array) {
+ if (array == null)
+ return null;
+
+ String[] arr = new String[array.length()];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = array.optString(i);
+ }
+ return arr;
+ }
+
+ @Override
+ public void disable(OsmandApplication app) {
+ if (app.getSettings().OPR_USE_DEV_URL.get()) {
+ app.getSettings().OPR_USE_DEV_URL.set(false);
+ app.getOprAuthHelper().resetAuthorization();
+ }
+ super.disable(app);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprAuthHelper.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprAuthHelper.java
new file mode 100644
index 0000000000..bc71900091
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprAuthHelper.java
@@ -0,0 +1,95 @@
+package net.osmand.plus.openplacereviews;
+
+import android.os.AsyncTask;
+
+import androidx.annotation.NonNull;
+
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.osmedit.opr.OpenDBAPI;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.util.Algorithms;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class OprAuthHelper {
+
+ private final OsmandApplication app;
+ private final OsmandSettings settings;
+ private final Set listeners = new HashSet<>();
+
+ public OprAuthHelper(@NonNull OsmandApplication app) {
+ this.app = app;
+ settings = app.getSettings();
+ }
+
+ public void addListener(OprAuthorizationListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(OprAuthorizationListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void resetAuthorization() {
+ if (isLoginExists()) {
+ settings.OPR_USERNAME.resetToDefault();
+ settings.OPR_ACCESS_TOKEN.resetToDefault();
+ settings.OPR_BLOCKCHAIN_NAME.resetToDefault();
+ }
+ }
+
+ public boolean isLoginExists() {
+ return !Algorithms.isEmpty(settings.OPR_USERNAME.get())
+ && !Algorithms.isEmpty(settings.OPR_BLOCKCHAIN_NAME.get())
+ && !Algorithms.isEmpty(settings.OPR_ACCESS_TOKEN.get());
+ }
+
+ private void notifyAndRemoveListeners() {
+ for (OprAuthorizationListener listener : listeners) {
+ listener.authorizationCompleted();
+ }
+ listeners.clear();
+ }
+
+ public void authorize(final String token, final String username) {
+ CheckOprAuthTask checkOprAuthTask = new CheckOprAuthTask(app, token, username);
+ checkOprAuthTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+ }
+
+ private static class CheckOprAuthTask extends AsyncTask {
+
+ private final OsmandApplication app;
+ private final OpenDBAPI openDBAPI = new OpenDBAPI();
+
+ private final String token;
+ private final String username;
+
+ private CheckOprAuthTask(@NonNull OsmandApplication app, String token, String username) {
+ this.app = app;
+ this.token = token;
+ this.username = username;
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ String baseUrl = OPRConstants.getBaseUrl(app);
+ return openDBAPI.checkPrivateKeyValid(app, baseUrl, username, token);
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ if (result) {
+ app.getSettings().OPR_ACCESS_TOKEN.set(token);
+ app.getSettings().OPR_USERNAME.set(username);
+ } else {
+ app.getOprAuthHelper().resetAuthorization();
+ }
+ app.getOprAuthHelper().notifyAndRemoveListeners();
+ }
+ }
+
+ public interface OprAuthorizationListener {
+ void authorizationCompleted();
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprSettingsFragment.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprSettingsFragment.java
new file mode 100644
index 0000000000..7ae0b5b825
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprSettingsFragment.java
@@ -0,0 +1,119 @@
+package net.osmand.plus.openplacereviews;
+
+import android.os.Bundle;
+
+import androidx.activity.OnBackPressedCallback;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+import androidx.preference.Preference;
+
+import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
+import net.osmand.plus.settings.fragments.BaseSettingsFragment;
+import net.osmand.plus.settings.fragments.OnPreferenceChanged;
+import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
+
+public class OprSettingsFragment extends BaseSettingsFragment implements OnPreferenceChanged, OprAuthorizationListener {
+
+ private static final String OPR_LOGOUT = "opr_logout";
+ public static final String OPR_LOGIN_DATA = "opr_login_data";
+
+ private OprAuthHelper authHelper;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ authHelper = app.getOprAuthHelper();
+
+ FragmentActivity activity = requireMyActivity();
+ activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
+ public void handleOnBackPressed() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ mapActivity.launchPrevActivityIntent();
+ }
+ dismiss();
+ }
+ });
+ }
+
+ @Override
+ protected void setupPreferences() {
+ Preference oprSettingsInfo = findPreference("opr_settings_info");
+ oprSettingsInfo.setIconSpaceReserved(false);
+
+ setupLoginPref();
+ setupLogoutPref();
+ setupUseDevUrlPref();
+ }
+
+ private void setupLoginPref() {
+ Preference nameAndPasswordPref = findPreference(OPR_LOGIN_DATA);
+ nameAndPasswordPref.setVisible(!authHelper.isLoginExists());
+ nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
+ }
+
+ private void setupLogoutPref() {
+ Preference nameAndPasswordPref = findPreference(OPR_LOGOUT);
+ nameAndPasswordPref.setVisible(authHelper.isLoginExists());
+ nameAndPasswordPref.setSummary(settings.OPR_USERNAME.get());
+ nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
+ }
+
+ private void setupUseDevUrlPref() {
+ SwitchPreferenceEx useDevUrlPref = findPreference(settings.OPR_USE_DEV_URL.getId());
+ useDevUrlPref.setVisible(OsmandPlugin.isDevelopment());
+ useDevUrlPref.setIcon(getPersistentPrefIcon(R.drawable.ic_plugin_developer));
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ String prefId = preference.getKey();
+ if (OPR_LOGIN_DATA.equals(prefId)) {
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ OprStartFragment.showInstance(fragmentManager);
+ return true;
+ }
+ } else if (OPR_LOGOUT.equals(prefId)) {
+ oprLogout();
+ return true;
+ }
+ return super.onPreferenceClick(preference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String prefId = preference.getKey();
+ if (settings.OPR_USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) {
+ settings.OPR_USE_DEV_URL.set((Boolean) newValue);
+ oprLogout();
+ return true;
+ }
+ return super.onPreferenceChange(preference, newValue);
+ }
+
+ public void oprLogout() {
+ authHelper.resetAuthorization();
+ app.showShortToastMessage(R.string.osm_edit_logout_success);
+ updateAllSettings();
+ }
+
+ @Override
+ public void onPreferenceChanged(String prefId) {
+ if (settings.OPR_USE_DEV_URL.getId().equals(prefId)) {
+ oprLogout();
+ }
+ updateAllSettings();
+ }
+
+ @Override
+ public void authorizationCompleted() {
+ if (getContext() != null) {
+ updateAllSettings();
+ }
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java
index 1b435654ef..e1f5b56e9d 100644
--- a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java
+++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java
@@ -16,18 +16,21 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.widget.Toolbar;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
+import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BaseOsmAndFragment;
+import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
import org.apache.commons.logging.Log;
-public class OprStartFragment extends BaseOsmAndFragment {
+public class OprStartFragment extends BaseOsmAndFragment implements OprAuthorizationListener {
private static final String TAG = OprStartFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(OprStartFragment.class);
private static final String openPlaceReviewsUrl = "OpenPlaceReviews.org";
@@ -36,18 +39,22 @@ public class OprStartFragment extends BaseOsmAndFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
- View v = UiUtilities.getInflater(requireMyActivity(), nightMode).inflate(R.layout.fragment_opr_login, container,
- false);
- View createAccount = v.findViewById(R.id.register_opr_create_account);
- v.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
+
+ View v = UiUtilities.getInflater(requireMyActivity(), nightMode).inflate(R.layout.fragment_opr_login, container, false);
+ AndroidUtils.addStatusBarPadding21v(requireMyActivity(), v);
+
+ Toolbar toolbar = (Toolbar) v.findViewById(R.id.toolbar);
+ int icBackResId = AndroidUtils.getNavigationIconResId(v.getContext());
+ toolbar.setNavigationIcon(getContentIcon(icBackResId));
+ toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
- public void onClick(View view) {
- FragmentActivity activity = getActivity();
- if (activity != null) {
- activity.getSupportFragmentManager().popBackStack();
- }
+ public void onClick(View v) {
+ dismiss();
}
});
+
+ View createAccount = v.findViewById(R.id.register_opr_create_account);
UiUtilities.setupDialogButton(nightMode, createAccount, UiUtilities.DialogButtonType.PRIMARY,
R.string.register_opr_create_new_account);
createAccount.setOnClickListener(new View.OnClickListener() {
@@ -70,14 +77,14 @@ public class OprStartFragment extends BaseOsmAndFragment {
}
private void handleHaveAccount() {
- String url = OPRConstants.getLoginUrl(requireContext());
+ String url = OPRConstants.getLoginUrl(requireMyApplication());
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(requireContext(), Uri.parse(url));
}
private void handleCreateAccount() {
- String url = OPRConstants.getRegisterUrl(requireContext());
+ String url = OPRConstants.getRegisterUrl(requireMyApplication());
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(requireContext(), Uri.parse(url));
@@ -114,6 +121,17 @@ public class OprStartFragment extends BaseOsmAndFragment {
}
}
+ @Override
+ public void authorizationCompleted() {
+ dismiss();
+ }
+
+ protected void dismiss() {
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ activity.getSupportFragmentManager().popBackStack();
+ }
+ }
public static void showInstance(@NonNull FragmentManager fm) {
try {
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java
index 877ebae773..c4a2d1bdce 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java
@@ -52,8 +52,8 @@ public class EditPOIMenuController extends MenuController {
OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
boolean isLogged = client.isValidToken()
- || !Algorithms.isEmpty(settings.USER_NAME.get())
- && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
+ || !Algorithms.isEmpty(settings.OSM_USER_NAME.get())
+ && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (point instanceof OpenstreetmapPoint) {
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java
index 8cefebd9ad..a35661b3a4 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java
@@ -84,7 +84,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
additionalData.put("tags", tagstring);
additionalData.put("visibility", visibility);
return NetworkUtils.uploadFile(url, f,
- settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(),
+ settings.OSM_USER_NAME.get() + ":" + settings.OSM_USER_PASSWORD.get(),
adapter.getClient(),
"file",
true, additionalData);
@@ -138,7 +138,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
StringBuilder responseBody = new StringBuilder();
- String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
+ String token = settings.OSM_USER_NAME.get() + ":" + settings.OSM_USER_PASSWORD.get(); //$NON-NLS-1$
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
connection.setDoInput(true);
if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -322,9 +322,9 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
if (n instanceof Node) {
- writeNode((Node) n, info, ser, changeSetId, settings.USER_NAME.get());
+ writeNode((Node) n, info, ser, changeSetId, settings.OSM_USER_NAME.get());
} else if (n instanceof Way) {
- writeWay((Way) n, info, ser, changeSetId, settings.USER_NAME.get());
+ writeWay((Way) n, info, ser, changeSetId, settings.OSM_USER_NAME.get());
}
ser.endTag(null, OsmPoint.stringAction.get(action));
ser.endTag(null, "osmChange"); //$NON-NLS-1$
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java
index 5d6c172738..30f9074a76 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java
@@ -141,7 +141,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(app));
if (!anonymous) {
- String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get();
+ String token = settings.OSM_USER_NAME.get() + ":" + settings.OSM_USER_PASSWORD.get();
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes(StandardCharsets.UTF_8)));
}
connection.setDoInput(true);
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java
index 81cebe393d..153c730709 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java
@@ -112,7 +112,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
boolean validToken = isValidToken();
Preference nameAndPasswordPref = findPreference(OSM_LOGOUT);
if (validToken || isLoginExists()) {
- String userName = validToken ? settings.USER_DISPLAY_NAME.get() : settings.USER_NAME.get();
+ String userName = validToken ? settings.OSM_USER_DISPLAY_NAME.get() : settings.OSM_USER_NAME.get();
nameAndPasswordPref.setVisible(true);
nameAndPasswordPref.setSummary(userName);
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
@@ -126,7 +126,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
}
private boolean isLoginExists() {
- return !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
+ return !Algorithms.isEmpty(settings.OSM_USER_NAME.get()) && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
}
private void setupOfflineEditingPref() {
@@ -140,7 +140,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
}
private void setupUseDevUrlPref() {
- SwitchPreferenceEx useDevUrlPref = findPreference(settings.USE_DEV_URL.getId());
+ SwitchPreferenceEx useDevUrlPref = findPreference(settings.OSM_USE_DEV_URL.getId());
if (OsmandPlugin.isDevelopment()) {
Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_laptop);
useDevUrlPref.setDescription(getString(R.string.use_dev_url_descr));
@@ -176,8 +176,8 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
- if (settings.USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) {
- settings.USE_DEV_URL.set((Boolean) newValue);
+ if (settings.OSM_USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) {
+ settings.OSM_USE_DEV_URL.set((Boolean) newValue);
osmLogout();
return true;
}
@@ -220,7 +220,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override
public void onPreferenceChanged(String prefId) {
- if (settings.USE_DEV_URL.getId().equals(prefId)) {
+ if (settings.OSM_USE_DEV_URL.getId().equals(prefId)) {
osmLogout();
}
updateAllSettings();
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
index f734b1c718..4f25b58761 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
@@ -457,9 +457,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
public boolean sendGPXFiles(final FragmentActivity activity, Fragment fragment, final GpxInfo... info) {
- String name = settings.USER_NAME.get();
- String pwd = settings.USER_PASSWORD.get();
- String authToken = settings.USER_ACCESS_TOKEN.get();
+ String name = settings.OSM_USER_NAME.get();
+ String pwd = settings.OSM_USER_PASSWORD.get();
+ String authToken = settings.OSM_USER_ACCESS_TOKEN.get();
if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment);
return false;
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java
index 5dabe123b4..ec028e87fd 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java
@@ -30,8 +30,8 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared();
- public final OsmandPreference USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared();
+ public final OsmandPreference OSM_USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared();
+ public final OsmandPreference OSM_USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared();
public static final String BILLING_USER_DONATION_WORLD_PARAMETER = "";
public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none";
@@ -1156,13 +1156,13 @@ public class OsmandSettings {
new StringPreference(this, "user_osm_bug_name", "NoName/OsmAnd").makeGlobal().makeShared();
// this value string is synchronized with settings_pref.xml preference name
- public final OsmandPreference USER_PASSWORD =
+ public final OsmandPreference OSM_USER_PASSWORD =
new StringPreference(this, "user_password", "").makeGlobal().makeShared();
- public final OsmandPreference USER_ACCESS_TOKEN =
+ public final OsmandPreference OSM_USER_ACCESS_TOKEN =
new StringPreference(this, "user_access_token", "").makeGlobal();
- public final OsmandPreference USER_ACCESS_TOKEN_SECRET =
+ public final OsmandPreference OSM_USER_ACCESS_TOKEN_SECRET =
new StringPreference(this, "user_access_token_secret", "").makeGlobal();
public final OsmandPreference OPR_ACCESS_TOKEN =
@@ -1174,13 +1174,15 @@ public class OsmandSettings {
public final OsmandPreference OPR_BLOCKCHAIN_NAME =
new StringPreference(this, "opr_blockchain_name", "").makeGlobal();
+ public final OsmandPreference OPR_USE_DEV_URL = new BooleanPreference(this, "opr_use_dev_url", false).makeGlobal().makeShared();
+
// this value boolean is synchronized with settings_pref.xml preference offline POI/Bugs edition
public final OsmandPreference OFFLINE_EDITION = new BooleanPreference(this, "offline_osm_editing", true).makeGlobal().makeShared();
- public final OsmandPreference USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
+ public final OsmandPreference OSM_USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
public String getOsmUrl() {
String osmUrl;
- if (USE_DEV_URL.get()) {
+ if (OSM_USE_DEV_URL.get()) {
osmUrl = "https://master.apis.dev.openstreetmap.org/";
} else {
osmUrl = "https://api.openstreetmap.org/";
@@ -1188,6 +1190,10 @@ public class OsmandSettings {
return osmUrl;
}
+ public String getOprUrl() {
+ return ctx.getString(OPR_USE_DEV_URL.get() ? R.string.dev_opr_base_url : R.string.opr_base_url);
+ }
+
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference DAYNIGHT_MODE =
new EnumStringPreference(this, "daynight_mode", DayNightMode.DAY, DayNightMode.values());
diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java
index 384f5457da..00d3c674f4 100644
--- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java
@@ -6,7 +6,6 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
-import android.widget.ScrollView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -49,8 +48,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
userNameEditText = view.findViewById(R.id.name_edit_text);
passwordEditText = view.findViewById(R.id.password_edit_text);
- String name = app.getSettings().USER_NAME.get();
- String password = app.getSettings().USER_PASSWORD.get();
+ String name = app.getSettings().OSM_USER_NAME.get();
+ String password = app.getSettings().OSM_USER_PASSWORD.get();
if (savedInstanceState != null) {
name = savedInstanceState.getString(USER_NAME_KEY, null);
@@ -96,8 +95,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
protected void onRightBottomButtonClick() {
OsmandApplication app = requiredMyApplication();
- app.getSettings().USER_NAME.set(userNameEditText.getText().toString());
- app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString());
+ app.getSettings().OSM_USER_NAME.set(userNameEditText.getText().toString());
+ app.getSettings().OSM_USER_PASSWORD.set(passwordEditText.getText().toString());
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof ValidateOsmLoginListener) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java
index 947a331290..63dab74fd4 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java
@@ -61,6 +61,7 @@ import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.audionotes.MultimediaNotesFragment;
import net.osmand.plus.development.DevelopmentSettingsFragment;
import net.osmand.plus.monitoring.MonitoringSettingsFragment;
+import net.osmand.plus.openplacereviews.OprSettingsFragment;
import net.osmand.plus.osmedit.OsmEditingFragment;
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment.AppModeChangedListener;
@@ -133,6 +134,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
MONITORING_SETTINGS(MonitoringSettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.monitoring_settings, R.layout.profile_preference_toolbar),
LIVE_MONITORING(LiveMonitoringFragment.class.getName(), false, ApplyQueryType.SNACK_BAR, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch),
ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.accessibility_settings, R.layout.profile_preference_toolbar),
+ OPEN_PLACE_REVIEWS(OprSettingsFragment.class.getName(), false, null, R.xml.open_place_reviews, R.layout.global_preference_toolbar),
DEVELOPMENT_SETTINGS(DevelopmentSettingsFragment.class.getName(), false, null, R.xml.development_settings, R.layout.global_preference_toolbar);
public final String fragmentName;
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
index 4b58c0b9dc..479c73da5f 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
@@ -890,8 +890,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private void updateMenuState() {
if (menuType == TrackMenuType.OPTIONS) {
openMenuFullScreen();
- } else if (menuType == TrackMenuType.OVERVIEW) {
- openMenuHeaderOnly();
} else {
openMenuHalfScreen();
}
@@ -1130,7 +1128,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
- showInstance(mapActivity, selectedGpxFile, null);
+ if (selectedGpxFile != null) {
+ showInstance(mapActivity, selectedGpxFile, null);
+ }
}
if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
progress.dismiss();
@@ -1142,7 +1142,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
}
- public static boolean showInstance(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile, @Nullable LatLon latLon) {
+ public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile, @Nullable LatLon latLon) {
try {
Bundle args = new Bundle();
args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY);
diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java
index 88b7618185..6b5559c3a8 100644
--- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java
@@ -5,6 +5,7 @@ import android.view.View;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils;
@@ -24,6 +25,8 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
+import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.search.QuickSearchDialogFragment;
@@ -32,8 +35,9 @@ import net.osmand.plus.search.listitems.QuickSearchBannerListItem;
import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.views.layers.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView;
+import net.osmand.plus.views.layers.DownloadedRegionsLayer;
+import net.osmand.plus.wikimedia.WikiImageHelper;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms;
@@ -42,6 +46,7 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
@@ -91,6 +96,11 @@ public class WikipediaPlugin extends OsmandPlugin {
this.mapActivity = activity;
}
+ @Override
+ public void mapActivityResumeOnTop(MapActivity activity) {
+ this.mapActivity = activity;
+ }
+
@Override
public void mapActivityPause(MapActivity activity) {
this.mapActivity = null;
@@ -435,4 +445,25 @@ public class WikipediaPlugin extends OsmandPlugin {
}
return false;
}
+
+ @Override
+ protected List getContextMenuImageCards(@NonNull Map params, @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) {
+ List imageCards = new ArrayList<>();
+ if (mapActivity != null) {
+ if (additionalParams != null) {
+ String wikidataId = additionalParams.get(Amenity.WIKIDATA);
+ if (wikidataId != null) {
+ additionalParams.remove(Amenity.WIKIDATA);
+ WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, imageCards);
+ }
+ String wikimediaContent = additionalParams.get(Amenity.WIKIMEDIA_COMMONS);
+ if (wikimediaContent != null) {
+ additionalParams.remove(Amenity.WIKIMEDIA_COMMONS);
+ WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, imageCards);
+ }
+ params.putAll(additionalParams);
+ }
+ }
+ return imageCards;
+ }
}
\ No newline at end of file