Merge branch 'master' into travel_obf_gpx_profile

# Conflicts:
#	OsmAnd/res/values/strings.xml
This commit is contained in:
Dima-1 2021-02-04 10:53:31 +02:00
commit df3c171a9c
55 changed files with 1147 additions and 488 deletions

View file

@ -94,6 +94,10 @@ public class OsmOAuthAuthorizationClient {
return accessToken; return accessToken;
} }
public OAuth1RequestToken getRequestToken() {
return requestToken;
}
public Response performRequestWithoutAuth(String url, String requestMethod, String requestBody) public Response performRequestWithoutAuth(String url, String requestMethod, String requestBody)
throws InterruptedException, ExecutionException, IOException { throws InterruptedException, ExecutionException, IOException {
Verb verb = parseRequestMethod(requestMethod); Verb verb = parseRequestMethod(requestMethod);

View file

@ -367,8 +367,9 @@ public class RouteStatisticsHelper {
RouteDataObject obj = segment.obj; RouteDataObject obj = segment.obj;
for (int type : obj.getTypes()) { for (int type : obj.getTypes()) {
BinaryMapRouteReaderAdapter.RouteTypeRule tp = obj.region.quickGetEncodingRule(type); BinaryMapRouteReaderAdapter.RouteTypeRule tp = obj.region.quickGetEncodingRule(type);
if (tp.getTag().equals("highway") || tp.getTag().equals("route") || if (tp.getTag().equals("highway") || tp.getTag().equals("route")
tp.getTag().equals("railway") || tp.getTag().equals("aeroway") || tp.getTag().equals("aerialway")) { || tp.getTag().equals("railway") || tp.getTag().equals("aeroway")
|| tp.getTag().equals("aerialway") || tp.getTag().equals("piste:type")) {
if (!mainTagAdded) { if (!mainTagAdded) {
req.setStringFilter(rrs.PROPS.R_TAG, tp.getTag()); req.setStringFilter(rrs.PROPS.R_TAG, tp.getTag());
req.setStringFilter(rrs.PROPS.R_VALUE, tp.getValue()); req.setStringFilter(rrs.PROPS.R_VALUE, tp.getValue());

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -1,36 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:clickable="true" android:orientation="vertical">
android:focusable="true"
android:orientation="vertical">
<LinearLayout <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" android:layout_height="@dimen/toolbar_height"
android:layout_marginTop="@dimen/dialog_content_margin"> android:gravity="center_vertical"
android:padding="0dp" />
<androidx.appcompat.widget.AppCompatImageView <ScrollView
android:id="@+id/back_button"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:contentDescription="@string/shared_string_back"
app:srcCompat="@drawable/ic_arrow_back"
app:tint="@color/icon_color_default_light" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:layout_below="@id/toolbar" android:layout_weight="1">
android:layout_above="@id/buttons">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -49,7 +35,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding" android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/dashPadding" android:layout_marginBottom="@dimen/dashPadding"
android:gravity="center_horizontal" android:gravity="center_horizontal"
@ -68,23 +54,25 @@
android:layout_marginTop="@dimen/dashPadding" android:layout_marginTop="@dimen/dashPadding"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
app:typeface="@string/font_roboto_regular"
android:text="@string/register_on_openplacereviews_desc" android:text="@string/register_on_openplacereviews_desc"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textColorLink="@color/icon_color_active_light"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
android:textColorLink="@color/icon_color_active_light" /> app:typeface="@string/font_roboto_regular" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>
</ScrollView>
<LinearLayout <LinearLayout
android:id="@+id/buttons" android:id="@+id/buttons"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding_small" android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_small" android:layout_marginBottom="@dimen/content_padding_small"
android:layout_alignParentBottom="true"
android:orientation="vertical"> android:orientation="vertical">
<include <include
@ -102,4 +90,4 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>

View file

@ -61,6 +61,13 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/amenity_type_finance"/> android:text="@string/amenity_type_finance"/>
<LinearLayout
android:id="@+id/context_menu_custom_address_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -1,5 +1,4 @@
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -8,7 +7,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="56dp" android:layout_height="wrap_content"
android:minHeight="@dimen/context_menu_action_buttons_height"
android:background="?attr/pstsTabBackground" android:background="?attr/pstsTabBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
@ -19,19 +19,19 @@
android:layout_width="52dp" android:layout_width="52dp"
android:layout_height="52dp" android:layout_height="52dp"
android:contentDescription="@string/shared_string_close" android:contentDescription="@string/shared_string_close"
app:srcCompat="@drawable/ic_action_remove_dark"/> app:srcCompat="@drawable/ic_action_remove_dark" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/titleTextView" android:id="@+id/titleTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:text="@string/osm_live_subscription" android:text="@string/osm_live_subscription"
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size_large" android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold" android:textStyle="bold"
app:typeface="@string/font_roboto_regular" app:typeface="@string/font_roboto_regular" />
android:layout_marginStart="20dp" />
</LinearLayout> </LinearLayout>
@ -39,7 +39,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/card_bottom_divider"/> <include layout="@layout/card_bottom_divider" />
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -67,8 +67,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:minHeight="56dp" android:minHeight="56dp"
android:orientation="horizontal"> android:orientation="horizontal">
@ -76,54 +76,81 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="48dp" android:layout_height="48dp"
android:scaleType="center" 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" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:paddingStart="2dp"
android:paddingLeft="2dp" android:paddingLeft="2dp"
android:text="@string/osm_live_subscription_desc" android:text="@string/osm_live_subscription_desc"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary" />
android:layout_marginEnd="16dp"
android:paddingStart="2dp"
android:layout_marginStart="16dp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:minHeight="56dp" android:minHeight="56dp"
android:orientation="vertical"> android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatCheckBox <androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/donationCheckbox" android:id="@+id/donationCheckbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="16dp" android:layout_marginTop="@dimen/context_menu_second_line_top_margin"
android:paddingLeft="34dp" android:layout_marginStart="@dimen/list_content_padding"
android:text="@string/donation_to_osm" android:layout_marginLeft="@dimen/list_content_padding"
android:paddingStart="34dp" android:paddingStart="@dimen/local_size_height"
android:layout_marginStart="16dp" /> android:paddingLeft="@dimen/local_size_height"
android:paddingEnd="@dimen/local_size_height"
android:paddingRight="@dimen/local_size_height"
android:text="@string/donation_to_osm" />
<TextView <LinearLayout
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="72dp" android:minHeight="56dp"
android:layout_marginRight="16dp" android:orientation="vertical">
android:layout_marginTop="8dp"
android:paddingLeft="2dp" <TextView
android:text="@string/donation_to_osm_desc" android:layout_width="match_parent"
android:textColor="?android:attr/textColorSecondary" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginStart="@dimen/list_content_padding_large"
android:layout_marginStart="72dp" android:layout_marginLeft="@dimen/context_menu_progress_padding_left"
android:paddingStart="2dp" /> android:layout_marginEnd="@dimen/context_menu_progress_padding_left"
android:layout_marginRight="@dimen/context_menu_progress_padding_left"
android:paddingStart="@dimen/subHeaderPadding"
android:paddingLeft="@dimen/subHeaderPadding"
android:paddingEnd="@dimen/subHeaderPadding"
android:paddingRight="@dimen/subHeaderPadding"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:text="@string/donation_to_osm" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/list_content_padding_large"
android:layout_marginLeft="@dimen/context_menu_progress_padding_left"
android:layout_marginEnd="@dimen/context_menu_progress_padding_left"
android:layout_marginRight="@dimen/context_menu_progress_padding_left"
android:paddingStart="@dimen/subHeaderPadding"
android:paddingLeft="@dimen/subHeaderPadding"
android:paddingEnd="@dimen/subHeaderPadding"
android:paddingRight="@dimen/subHeaderPadding"
android:text="@string/donation_to_osm_desc"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
@ -140,13 +167,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:background="?attr/dashboard_divider"/> android:background="?attr/dashboard_divider" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:minHeight="56dp" android:minHeight="56dp"
android:orientation="horizontal"> android:orientation="horizontal">
@ -155,47 +182,48 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="48dp" android:layout_height="48dp"
android:scaleType="center" android:scaleType="center"
app:srcCompat="@drawable/ic_world_globe_dark"/> app:srcCompat="@drawable/ic_world_globe_dark" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:orientation="vertical" android:layout_marginEnd="16dp"
android:layout_marginStart="16dp" android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"> android:orientation="vertical">
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="2dp" android:paddingStart="@dimen/subHeaderPadding"
android:paddingEnd="@dimen/subHeaderPadding"
android:paddingLeft="@dimen/subHeaderPadding"
android:paddingRight="@dimen/subHeaderPadding"
android:text="@string/osm_live_support_region" android:text="@string/osm_live_support_region"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary" />
android:paddingStart="2dp" />
<net.osmand.plus.widgets.AutoCompleteTextViewEx <net.osmand.plus.widgets.AutoCompleteTextViewEx
android:id="@+id/selectCountryEdit" android:id="@+id/selectCountryEdit"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:drawableRightCompat="@drawable/ic_action_arrow_drop_down" android:paddingStart="2dp"
app:drawableEndCompat="@drawable/ic_action_arrow_drop_down"
android:editable="false"
android:paddingLeft="2dp" android:paddingLeft="2dp"
android:paddingEnd="0dp"
android:paddingRight="0dp" android:paddingRight="0dp"
android:text="Ukraine" android:text="Ukraine"
android:paddingStart="2dp" app:drawableEndCompat="@drawable/ic_action_arrow_drop_down"
android:paddingEnd="0dp" /> app:drawableRightCompat="@drawable/ic_action_arrow_drop_down" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:paddingStart="2dp"
android:paddingLeft="2dp" android:paddingLeft="2dp"
android:text="@string/osm_live_region_desc" android:text="@string/osm_live_region_desc"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary" />
android:paddingStart="2dp" />
</LinearLayout> </LinearLayout>
@ -213,21 +241,21 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="48dp" android:layout_height="48dp"
android:scaleType="center" android:scaleType="center"
app:srcCompat="@drawable/ic_action_message"/> app:srcCompat="@drawable/ic_action_message" />
<EditText <EditText
android:id="@+id/emailEdit" android:id="@+id/emailEdit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:hint="@string/shared_string_email_address" android:hint="@string/shared_string_email_address"
android:inputType="textEmailAddress" android:inputType="textEmailAddress"
android:paddingLeft="2dp" android:paddingStart="2dp"
android:layout_marginStart="16dp" android:paddingLeft="2dp" />
android:layout_marginEnd="16dp"
android:paddingStart="2dp" />
</LinearLayout> </LinearLayout>
@ -235,14 +263,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="72dp"
android:layout_marginLeft="72dp" android:layout_marginLeft="72dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:paddingStart="2dp"
android:paddingLeft="2dp" android:paddingLeft="2dp"
android:text="@string/osm_live_email_desc" android:text="@string/osm_live_email_desc"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary" />
android:paddingStart="2dp"
android:layout_marginStart="72dp"
android:layout_marginEnd="16dp" />
<LinearLayout <LinearLayout
@ -261,21 +289,21 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="48dp" android:layout_height="48dp"
android:scaleType="center" android:scaleType="center"
app:srcCompat="@drawable/ic_action_user"/> app:srcCompat="@drawable/ic_action_user" />
<EditText <EditText
android:id="@+id/userNameEdit" android:id="@+id/userNameEdit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:hint="@string/osm_live_user_public_name" android:hint="@string/osm_live_user_public_name"
android:inputType="text" android:inputType="text"
android:paddingLeft="2dp" android:paddingStart="2dp"
android:layout_marginEnd="16dp" android:paddingLeft="2dp" />
android:layout_marginStart="16dp"
android:paddingStart="2dp" />
</LinearLayout> </LinearLayout>
@ -284,16 +312,16 @@
android:id="@+id/hideUserNameCheckbox" android:id="@+id/hideUserNameCheckbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginStart="72dp"
android:layout_marginLeft="72dp" android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
android:paddingStart="4dp"
android:paddingLeft="4dp" android:paddingLeft="4dp"
android:text="@string/osm_live_hide_user_name" android:text="@string/osm_live_hide_user_name"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary" />
android:layout_marginEnd="16dp"
android:paddingStart="4dp"
android:layout_marginStart="72dp" />
</LinearLayout> </LinearLayout>
@ -303,35 +331,35 @@
android:id="@+id/editModeBottomView" android:id="@+id/editModeBottomView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:visibility="visible"> android:visibility="visible">
<Button <Button
android:id="@+id/saveChangesButton" android:id="@+id/saveChangesButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginLeft="72dp" android:layout_marginLeft="72dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:background="?attr/btn_round" android:background="?attr/btn_round"
android:paddingStart="16dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingEnd="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"
android:text="@string/shared_string_save_changes" android:text="@string/shared_string_save_changes"
android:textColor="@color/color_white" android:textColor="@color/color_white" />
android:layout_marginStart="72dp"
android:layout_marginEnd="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<include layout="@layout/card_bottom_divider"/> <include layout="@layout/card_bottom_divider" />
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="16dp"/> android:layout_height="16dp" />
</LinearLayout> </LinearLayout>

View file

@ -24,7 +24,7 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin" android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:src="@drawable/ic_map" tools:src="@drawable/ic_map"
android:layout_marginEnd="@dimen/favorites_icon_right_margin" /> android:layout_marginEnd="@dimen/favorites_icon_right_margin" />
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
@ -81,26 +81,26 @@
android:visibility="gone" android:visibility="gone"
tools:src="@drawable/ic_action_import" tools:src="@drawable/ic_action_import"
tools:visibility="visible" tools:visibility="visible"
android:layout_marginStart="@dimen/dashFavIconMargin" /> android:layout_marginStart="@dimen/dashFavIconMargin" />
<Button <Button
android:id="@+id/rightButton" android:id="@+id/rightButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="33dp" android:layout_height="wrap_content"
android:minWidth="40dp"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:background="@drawable/buy_btn_background_light"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/dashFavIconMargin"
android:layout_marginLeft="@dimen/dashFavIconMargin" android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="8dp" android:layout_marginEnd="@dimen/list_header_padding"
android:textColor="@color/buy_button_color" android:layout_marginRight="@dimen/list_header_padding"
android:minWidth="@dimen/list_header_height"
android:minHeight="@dimen/list_content_padding_large"
android:paddingStart="@dimen/context_menu_progress_padding_left"
android:paddingLeft="@dimen/context_menu_progress_padding_left"
android:paddingEnd="@dimen/context_menu_progress_padding_left"
android:paddingRight="@dimen/context_menu_progress_padding_left"
android:text="@string/buy" android:text="@string/buy"
android:visibility="gone" android:textColor="@color/text_color_tab_active_light"
android:layout_marginStart="@dimen/dashFavIconMargin" android:visibility="gone" />
android:layout_marginEnd="8dp"
android:paddingEnd="18dp"
android:paddingStart="18dp" />
</LinearLayout> </LinearLayout>

View file

@ -1219,7 +1219,7 @@
<string name="display_zoom_level">显示缩放等级:%1$s</string> <string name="display_zoom_level">显示缩放等级:%1$s</string>
<string name="online_map">在线地图</string> <string name="online_map">在线地图</string>
<string name="roads_only">仅道路</string> <string name="roads_only">仅道路</string>
<string name="device_memory">设备</string> <string name="device_memory">设备</string>
<string name="first_usage_item">初次使用</string> <string name="first_usage_item">初次使用</string>
<string name="tips_and_tricks_descr">常见问题、最近修改和其它内容。</string> <string name="tips_and_tricks_descr">常见问题、最近修改和其它内容。</string>
<string name="faq_item_description">常见问题</string> <string name="faq_item_description">常见问题</string>

View file

@ -25,6 +25,10 @@
<string name="activity_type_snowmobile">Snowmobile</string> <string name="activity_type_snowmobile">Snowmobile</string>
<string name="activity_type_winter">Winter</string> <string name="activity_type_winter">Winter</string>
<string name="activity_type_water">Water</string> <string name="activity_type_water">Water</string>
<string name="login_open_place_reviews">Login to OpenPlaceReviews</string>
<string name="opr_use_dev_url">Use test.openplacereviews.org</string>
<string name="open_place_reviews">OpenPlaceReviews</string>
<string name="open_place_reviews_plugin_description">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</string>
<string name="hillshade_slope_contour_lines">Hillshade / Slope / Contour lines</string> <string name="hillshade_slope_contour_lines">Hillshade / Slope / Contour lines</string>
<string name="toast_select_edits_for_upload">Select edits for upload</string> <string name="toast_select_edits_for_upload">Select edits for upload</string>
<string name="uploaded_count">Uploaded %1$d of %2$d</string> <string name="uploaded_count">Uploaded %1$d of %2$d</string>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/open_place_reviews">
<Preference
android:key="opr_settings_info"
android:layout="@layout/preference_info"
android:persistent="false"
android:selectable="false"
android:title="@string/plugin_global_prefs_info" />
<Preference
android:key="opr_login_data"
android:layout="@layout/preference_with_descr"
android:persistent="false"
android:title="@string/login_open_place_reviews" />
<Preference
android:key="opr_logout"
android:layout="@layout/preference_login"
android:persistent="false"
android:title="@string/login_account" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="opr_use_dev_url"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:title="@string/opr_use_dev_url"
tools:icon="@drawable/ic_plugin_developer" />
</PreferenceScreen>

View file

@ -28,7 +28,6 @@ import net.osmand.map.OsmandRegions.RegionTranslation;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.activities.LocalIndexHelper; import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.SavingTrackHelper; 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.DownloadActivity;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.helpers.LockHelper; import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppPurchaseHelperImpl; 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.LiveMonitoringHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper; import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
import net.osmand.plus.openplacereviews.OprAuthHelper;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper; import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
@ -468,6 +469,7 @@ public class AppInitializer implements IProgress {
app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class); app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class);
app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class); app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.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); app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
initOpeningHoursParser(); initOpeningHoursParser();

View file

@ -344,8 +344,8 @@ public class OsmAndFormatter {
if (minperkm >= 10) { if (minperkm >= 10) {
return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx); return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx);
} else { } else {
int mph10 = (int) Math.round(minperkm * 10f); int seconds = Math.round(minperkm * 60);
return (mph10 / 10f) + " " + mc.toShortString(ctx); return Algorithms.formatDuration(seconds, false) + " " + mc.toShortString(ctx);
} }
} else if (mc == SpeedConstants.MINUTES_PER_MILE) { } else if (mc == SpeedConstants.MINUTES_PER_MILE) {
if (metersperseconds < 0.111111111) { if (metersperseconds < 0.111111111) {

View file

@ -24,6 +24,8 @@ import android.view.View;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDex; import androidx.multidex.MultiDex;
@ -68,6 +70,7 @@ import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper; import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
import net.osmand.plus.openplacereviews.OprAuthHelper;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper; import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
@ -159,6 +162,7 @@ public class OsmandApplication extends MultiDexApplication {
GpxDbHelper gpxDbHelper; GpxDbHelper gpxDbHelper;
QuickActionRegistry quickActionRegistry; QuickActionRegistry quickActionRegistry;
OsmOAuthHelper osmOAuthHelper; OsmOAuthHelper osmOAuthHelper;
OprAuthHelper oprAuthHelper;
MeasurementEditingContext measurementEditingContext; MeasurementEditingContext measurementEditingContext;
OnlineRoutingHelper onlineRoutingHelper; OnlineRoutingHelper onlineRoutingHelper;
@ -394,6 +398,10 @@ public class OsmandApplication extends MultiDexApplication {
return osmOAuthHelper; return osmOAuthHelper;
} }
public OprAuthHelper getOprAuthHelper() {
return oprAuthHelper;
}
public synchronized DownloadIndexesThread getDownloadThread() { public synchronized DownloadIndexesThread getDownloadThread() {
if (downloadIndexesThread == null) { if (downloadIndexesThread == null) {
downloadIndexesThread = new DownloadIndexesThread(this); downloadIndexesThread = new DownloadIndexesThread(this);
@ -910,6 +918,7 @@ public class OsmandApplication extends MultiDexApplication {
return customRoutingConfigs.get(key); return customRoutingConfigs.get(key);
} }
@NonNull
public RoutingConfiguration.Builder getRoutingConfigForMode(ApplicationMode mode) { public RoutingConfiguration.Builder getRoutingConfigForMode(ApplicationMode mode) {
RoutingConfiguration.Builder builder = null; RoutingConfiguration.Builder builder = null;
String routingProfileKey = mode.getRoutingProfile(); String routingProfileKey = mode.getRoutingProfile();
@ -923,11 +932,13 @@ public class OsmandApplication extends MultiDexApplication {
return builder != null ? builder : getDefaultRoutingConfig(); return builder != null ? builder : getDefaultRoutingConfig();
} }
@Nullable
public GeneralRouter getRouter(ApplicationMode mode) { public GeneralRouter getRouter(ApplicationMode mode) {
Builder builder = getRoutingConfigForMode(mode); Builder builder = getRoutingConfigForMode(mode);
return getRouter(builder, mode); return getRouter(builder, mode);
} }
@Nullable
public GeneralRouter getRouter(Builder builder, ApplicationMode am) { public GeneralRouter getRouter(Builder builder, ApplicationMode am) {
GeneralRouter router = builder.getRouter(am.getRoutingProfile()); GeneralRouter router = builder.getRouter(am.getRoutingProfile());
if (router == null && am.getParent() != null) { if (router == null && am.getParent() != null) {

View file

@ -35,9 +35,12 @@ import net.osmand.plus.dialogs.PluginInstalledBottomSheetDialog;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController; 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.mapillary.MapillaryPlugin;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
@ -66,6 +69,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
public abstract class OsmandPlugin { public abstract class OsmandPlugin {
@ -133,7 +137,7 @@ public abstract class OsmandPlugin {
public boolean init(@NonNull OsmandApplication app, @Nullable Activity activity) { public boolean init(@NonNull OsmandApplication app, @Nullable Activity activity) {
if (activity != null) { if (activity != null) {
// called from UI // called from UI
for (ApplicationMode appMode: getAddedAppModes()) { for (ApplicationMode appMode : getAddedAppModes()) {
ApplicationMode.changeProfileAvailability(appMode, true, app); ApplicationMode.changeProfileAvailability(appMode, true, app);
} }
} }
@ -208,6 +212,16 @@ public abstract class OsmandPlugin {
return Collections.emptyList(); return Collections.emptyList();
} }
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams,
@Nullable GetImageCardsListener listener) {
return Collections.emptyList();
}
protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
return null;
}
/** /**
* Plugin was installed * Plugin was installed
*/ */
@ -263,25 +277,19 @@ public abstract class OsmandPlugin {
public static void initPlugins(@NonNull OsmandApplication app) { public static void initPlugins(@NonNull OsmandApplication app) {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins(); Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
allPlugins.clear(); allPlugins.clear();
enablePluginByDefault(app, enabledPlugins, new WikipediaPlugin(app));
enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app));
enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app)); allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app)); allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app)); checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
// ? questionable - definitely not market plugin
// checkMarketPlugin(app, enabledPlugins, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
checkMarketPlugin(app, enabledPlugins, new NauticalMapsPlugin(app)); checkMarketPlugin(app, enabledPlugins, new NauticalMapsPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SkiMapsPlugin(app)); checkMarketPlugin(app, enabledPlugins, new SkiMapsPlugin(app));
allPlugins.add(new AudioVideoNotesPlugin(app)); allPlugins.add(new AudioVideoNotesPlugin(app));
checkMarketPlugin(app, enabledPlugins, new ParkingPositionPlugin(app)); checkMarketPlugin(app, enabledPlugins, new ParkingPositionPlugin(app));
allPlugins.add(new AccessibilityPlugin(app));
allPlugins.add(new OsmEditingPlugin(app)); allPlugins.add(new OsmEditingPlugin(app));
enablePluginByDefault(app, enabledPlugins, new OpenPlaceReviewsPlugin(app));
enablePluginByDefault(app, enabledPlugins, new MapillaryPlugin(app));
allPlugins.add(new AccessibilityPlugin(app));
allPlugins.add(new OsmandDevelopmentPlugin(app)); allPlugins.add(new OsmandDevelopmentPlugin(app));
loadCustomPlugins(app); loadCustomPlugins(app);
@ -373,7 +381,7 @@ public abstract class OsmandPlugin {
} }
} }
private static void enableHiddenPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) { private static void enablePluginByDefault(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
allPlugins.add(plugin); allPlugins.add(plugin);
if (!enabledPlugins.contains(plugin.getId()) && !app.getSettings().getPlugins().contains("-" + plugin.getId())) { if (!enabledPlugins.contains(plugin.getId()) && !app.getSettings().getPlugins().contains("-" + plugin.getId())) {
enabledPlugins.add(plugin.getId()); enabledPlugins.add(plugin.getId());
@ -734,7 +742,6 @@ public abstract class OsmandPlugin {
return l; return l;
} }
public static void onMapActivityCreate(MapActivity activity) { public static void onMapActivityCreate(MapActivity activity) {
for (OsmandPlugin plugin : getEnabledPlugins()) { for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.mapActivityCreate(activity); plugin.mapActivityCreate(activity);
@ -868,6 +875,23 @@ public abstract class OsmandPlugin {
return collection; return collection;
} }
public static void populateContextMenuImageCards(@NonNull List<ImageCard> imageCards, @NonNull Map<String, String> params,
@Nullable Map<String, String> 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) { public static boolean isPackageInstalled(String packageInfo, Context ctx) {
if (packageInfo == null) { if (packageInfo == null) {
return false; return false;

View file

@ -10,6 +10,7 @@ import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -88,6 +89,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
public static final int IMPORT_FAVOURITES_ID = 7; public static final int IMPORT_FAVOURITES_ID = 7;
public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded"; public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded";
private static final int MAX_POINTS_IN_DESCRIPTION = 100;
private FavouritesAdapter favouritesAdapter; private FavouritesAdapter favouritesAdapter;
private FavouritesDbHelper helper; private FavouritesDbHelper helper;
@ -606,29 +609,39 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
} }
} }
private StringBuilder generateHtmlPrint(List<FavoriteGroup> groups) { private String generateHtmlPrint(List<FavoriteGroup> groups) {
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
html.append("<h1>My Favorites</h1>"); html.append("<h1>My Favorites</h1>");
int addedPoints = 0;
for (FavoriteGroup group : groups) { for (FavoriteGroup group : groups) {
html.append("<h3>" + group.getDisplayName(app) + "</h3>"); html.append("<h3>").append(group.getDisplayName(app)).append("</h3>");
for (FavouritePoint fp : group.getPoints()) { for (FavouritePoint fp : group.getPoints()) {
String url = "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "?m=" + fp.getName(); if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
html.append("<p>" + fp.getDisplayName(app) + " - " + "<a href=\"" + url + "\">geo:" break;
+ ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "</a><br>");
if (fp.isAddressSpecified()) {
html.append(": " + fp.getAddress());
html.append("<br>");
} }
if (!Algorithms.isEmpty(fp.getDescription())) {
html.append(": " + fp.getDescription()); float lat = (float) fp.getLatitude();
} float lon = (float) fp.getLongitude();
html.append("</p>"); String url = "geo:" + lat + "," + lon + "?m=" + fp.getName();
html.append("<p>")
.append(fp.getDisplayName(app))
.append(" - <a href=\"")
.append(url)
.append("\">geo:")
.append(lat).append(",").append(lon)
.append("</a><br></p>");
addedPoints++;
}
if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
html.append("<p>...</p>");
break;
} }
} }
return html; return html.toString();
} }
private void shareFavourites() { private void shareFavourites() {
if (favouritesAdapter.isEmpty()) { if (favouritesAdapter.isEmpty()) {
Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show();
@ -646,6 +659,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
File src = null; File src = null;
File dst = null; File dst = null;
Spanned descriptionOfPoints;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -662,9 +676,15 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
List<FavoriteGroup> groups;
if (group != null) { if (group != null) {
helper.saveFile(group.getPoints(), dst); helper.saveFile(group.getPoints(), dst);
groups = new ArrayList<>();
groups.add(group);
} else {
groups = getMyApplication().getFavorites().getFavoriteGroups();
} }
descriptionOfPoints = Html.fromHtml(generateHtmlPrint(groups));
return null; return null;
} }
@ -680,19 +700,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
Algorithms.fileCopy(src, dst); Algorithms.fileCopy(src, dst);
} }
final Intent sendIntent = new Intent(); final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setAction(Intent.ACTION_SEND)
List<FavoriteGroup> groups; .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject))
if (group != null) { .putExtra(Intent.EXTRA_TEXT, descriptionOfPoints)
groups = new ArrayList<>(); .putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst))
groups.add(group); .setType("text/plain")
} else { .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
groups = getMyApplication().getFavorites().getFavoriteGroups();
}
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(getMyApplication(), dst));
sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(sendIntent); startActivity(sendIntent);
} catch (IOException e) { } catch (IOException e) {
Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show();

View file

@ -143,8 +143,8 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
@Override @Override
public void disable(OsmandApplication app) { public void disable(OsmandApplication app) {
if (app.getSettings().USE_DEV_URL.get()) { if (app.getSettings().OSM_USE_DEV_URL.get()) {
app.getSettings().USE_DEV_URL.set(false); app.getSettings().OSM_USE_DEV_URL.set(false);
app.getOsmOAuthHelper().resetAuthorization(); app.getOsmOAuthHelper().resetAuthorization();
} }
super.disable(app); super.disable(app);

View file

@ -19,9 +19,9 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; 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(); 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; 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(); UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.setMaxProgress(maxProgress); fragment.setMaxProgress(maxProgress);

View file

@ -22,6 +22,7 @@ import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants; import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
@ -326,8 +327,8 @@ public class IntentHelper {
if (uri.toString().startsWith(OPRConstants.OPR_OAUTH_PREFIX)) { if (uri.toString().startsWith(OPRConstants.OPR_OAUTH_PREFIX)) {
String token = uri.getQueryParameter("opr-token"); String token = uri.getQueryParameter("opr-token");
String username = uri.getQueryParameter("opr-nickname"); String username = uri.getQueryParameter("opr-nickname");
app.getSettings().OPR_ACCESS_TOKEN.set(token); app.getOprAuthHelper().addListener(getOprAuthorizationListener());
app.getSettings().OPR_USERNAME.set(username); app.getOprAuthHelper().authorize(token, username);
mapActivity.setIntent(null); mapActivity.setIntent(null);
return true; 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) { private boolean handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (!Algorithms.isEmpty(sharedText)) { if (!Algorithms.isEmpty(sharedText)) {

View file

@ -63,7 +63,7 @@ class GpxOrFavouritesImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
ZipEntry entry; ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) { while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(ImportHelper.KML_SUFFIX)) { if (entry.getName().endsWith(ImportHelper.KML_SUFFIX)) {
InputStream gpxStream = convertKmlToGpxStream(is); InputStream gpxStream = convertKmlToGpxStream(zis);
if (gpxStream != null) { if (gpxStream != null) {
fileSize = gpxStream.available(); fileSize = gpxStream.available();
return GPXUtilities.loadGPXFile(gpxStream); return GPXUtilities.loadGPXFile(gpxStream);

View file

@ -49,7 +49,7 @@ class KmzImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
ZipEntry entry; ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) { while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(KML_SUFFIX)) { if (entry.getName().endsWith(KML_SUFFIX)) {
InputStream gpxStream = convertKmlToGpxStream(is); InputStream gpxStream = convertKmlToGpxStream(zis);
if (gpxStream != null) { if (gpxStream != null) {
fileSize = gpxStream.available(); fileSize = gpxStream.available();
return GPXUtilities.loadGPXFile(gpxStream); return GPXUtilities.loadGPXFile(gpxStream);

View file

@ -58,6 +58,7 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.LockableScrollView; import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.backend.MainContextMenuItemsSettings; import net.osmand.plus.settings.backend.MainContextMenuItemsSettings;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -1674,6 +1675,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
line2MeasuredHeight = line2.getMeasuredHeight(); line2MeasuredHeight = line2.getMeasuredHeight();
} }
int customAddressLineHeight = 0;
View customAddressLine = view.findViewById(R.id.context_menu_custom_address_line);
if (customAddressLine.getVisibility() == View.VISIBLE) {
customAddressLineHeight = customAddressLine.getMeasuredHeight();
}
int line3Height = 0; int line3Height = 0;
View line3Container = view.findViewById(R.id.additional_info_row_container); View line3Container = view.findViewById(R.id.additional_info_row_container);
if (line3Container.getVisibility() == View.VISIBLE) { if (line3Container.getVisibility() == View.VISIBLE) {
@ -1717,12 +1724,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
titleHeight = line1.getMeasuredHeight() + line2MeasuredHeight; titleHeight = line1.getMeasuredHeight() + line2MeasuredHeight;
} }
newMenuTopViewHeight = menuTopViewHeightExcludingTitle + titleHeight newMenuTopViewHeight = menuTopViewHeightExcludingTitle + titleHeight
+ titleButtonHeight + downloadButtonsHeight + titleButtonHeight + customAddressLineHeight + downloadButtonsHeight
+ titleBottomButtonHeight + additionalButtonsHeight + titleProgressHeight + line3Height; + titleBottomButtonHeight + additionalButtonsHeight + titleProgressHeight + line3Height;
dy = Math.max(0, newMenuTopViewHeight - menuTopViewHeight dy = Math.max(0, newMenuTopViewHeight - menuTopViewHeight
- (newMenuTopShadowAllHeight - menuTopShadowAllHeight)); - (newMenuTopShadowAllHeight - menuTopShadowAllHeight));
} else { } else {
menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight - customAddressLineHeight
- titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight - line3Height; - titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight - line3Height;
menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight()) menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight())
+ (line2MeasuredHeight - line2LineCount * line2LineHeight); + (line2MeasuredHeight - line2LineCount * line2LineHeight);
@ -1818,12 +1825,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
line1.setText(menu.getTitleStr()); line1.setText(menu.getTitleStr());
toolbarTextView.setText(menu.getTitleStr()); toolbarTextView.setText(menu.getTitleStr());
// Text line 2 // Text line 2
LinearLayout line2layout = view.findViewById(R.id.context_menu_line2_layout);
TextView line2 = view.findViewById(R.id.context_menu_line2); TextView line2 = view.findViewById(R.id.context_menu_line2);
LinearLayout customAddressLine = view.findViewById(R.id.context_menu_custom_address_line);
customAddressLine.removeAllViews();
if (menu.hasCustomAddressLine()) { if (menu.hasCustomAddressLine()) {
line2layout.removeAllViews(); menu.buildCustomAddressLine(customAddressLine);
menu.buildCustomAddressLine(line2layout); AndroidUiHelper.updateVisibility(line2, false);
AndroidUiHelper.updateVisibility(customAddressLine, true);
} else { } else {
AndroidUiHelper.updateVisibility(line2, true);
AndroidUiHelper.updateVisibility(customAddressLine, false);
String typeStr = menu.getTypeStr(); String typeStr = menu.getTypeStr();
String streetStr = menu.getStreetStr(); String streetStr = menu.getStreetStr();
StringBuilder line2Str = new StringBuilder(); StringBuilder line2Str = new StringBuilder();

View file

@ -36,6 +36,7 @@ import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -47,11 +48,12 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.ActivityResultListener; import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener; import net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; 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.AbstractCard;
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; 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.Algorithms;
import net.osmand.util.MapUtils; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -87,6 +93,7 @@ import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCa
public class MenuBuilder { public class MenuBuilder {
private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class);
private static final int PICK_IMAGE = 1231; private static final int PICK_IMAGE = 1231;
public static final float SHADOW_HEIGHT_TOP_DP = 17f; public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60; public static final int TITLE_LIMIT = 60;
@ -131,16 +138,14 @@ public class MenuBuilder {
} }
@Override @Override
public void onPlaceIdAcquired(String[] placeId) { public void onPlaceIdAcquired(final String[] placeId) {
MenuBuilder.this.placeId = placeId; MenuBuilder.this.placeId = placeId;
if (placeId.length < 2) { app.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() { @Override
@Override public void run() {
public void run() { AndroidUiHelper.updateVisibility(photoButton, placeId.length >= 2);
photoButton.setVisibility(View.GONE); }
} });
});
}
} }
@Override @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 { public interface CollapseExpandListener {
void onCollapseExpand(boolean collapsed); void onCollapseExpand(boolean collapsed);
} }
@ -443,10 +458,7 @@ public class MenuBuilder {
} }
} }
}); });
//TODO This feature is under development AndroidUiHelper.updateVisibility(view, false);
if (!Version.isDeveloperVersion(app)) {
view.setVisibility(View.GONE);
}
photoButton = view; photoButton = view;
return 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));
} }
} }
})); }));

View file

@ -4,7 +4,6 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -13,14 +12,11 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.osm.io.NetworkUtils; import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.UploadPhotoProgressBottomSheet; 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.OPRConstants;
import net.osmand.plus.openplacereviews.OprStartFragment; import net.osmand.plus.openplacereviews.OprStartFragment;
import net.osmand.plus.osmedit.opr.OpenDBAPI; import net.osmand.plus.osmedit.opr.OpenDBAPI;
@ -36,7 +32,6 @@ import java.io.InputStream;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> { public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@ -47,22 +42,17 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private final OsmandApplication app; private final OsmandApplication app;
private final WeakReference<MapActivity> activityRef; private final WeakReference<MapActivity> activityRef;
private final OpenDBAPI openDBAPI = new OpenDBAPI(); private final OpenDBAPI openDBAPI = new OpenDBAPI();
private final LatLon latLon;
private final List<Uri> data; private final List<Uri> data;
private final String[] placeId; private final String[] placeId;
private final Map<String, String> params; private final UploadPhotosListener listener;
private final GetImageCardsListener imageCardListener; private UploadPhotosProgressListener progressListener;
private UploadPhotosListener listener;
public UploadPhotosAsyncTask(MapActivity activity, List<Uri> data, LatLon latLon, String[] placeId, public UploadPhotosAsyncTask(MapActivity activity, List<Uri> data, String[] placeId, UploadPhotosListener listener) {
Map<String, String> params, GetImageCardsListener imageCardListener) {
app = (OsmandApplication) activity.getApplicationContext(); app = (OsmandApplication) activity.getApplicationContext();
activityRef = new WeakReference<>(activity); activityRef = new WeakReference<>(activity);
this.data = data; this.data = data;
this.latLon = latLon;
this.params = params;
this.placeId = placeId; this.placeId = placeId;
this.imageCardListener = imageCardListener; this.listener = listener;
} }
@Override @Override
@ -70,7 +60,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
FragmentActivity activity = activityRef.get(); FragmentActivity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) { if (AndroidUtils.isActivityNotDestroyed(activity)) {
FragmentManager manager = activity.getSupportFragmentManager(); FragmentManager manager = activity.getSupportFragmentManager();
listener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() { progressListener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
cancel(false); cancel(false);
@ -81,8 +71,8 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override @Override
protected void onProgressUpdate(Integer... values) { protected void onProgressUpdate(Integer... values) {
if (listener != null) { if (progressListener != null) {
listener.uploadPhotosProgressUpdate(values[0]); progressListener.uploadPhotosProgressUpdate(values[0]);
} }
} }
@ -103,18 +93,19 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
if (listener != null) { if (progressListener != null) {
listener.uploadPhotosFinished(); progressListener.uploadPhotosFinished();
} }
} }
private boolean handleSelectedImage(final Uri uri) { private boolean handleSelectedImage(final Uri uri) {
boolean success = false; boolean success = false;
InputStream inputStream = null; InputStream inputStream = null;
int[] imageDimensions = null;
try { try {
inputStream = app.getContentResolver().openInputStream(uri); inputStream = app.getContentResolver().openInputStream(uri);
if (inputStream != null) { if (inputStream != null) {
success = uploadImageToPlace(inputStream); imageDimensions = calcImageDimensions(inputStream);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error(e); LOG.error(e);
@ -122,12 +113,27 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
} finally { } finally {
Algorithms.closeStream(inputStream); Algorithms.closeStream(inputStream);
} }
if (imageDimensions != null && imageDimensions.length == 2) {
try {
inputStream = app.getContentResolver().openInputStream(uri);
if (inputStream != null) {
int width = imageDimensions[0];
int height = imageDimensions[1];
success = uploadImageToPlace(inputStream, width, height);
}
} catch (Exception e) {
LOG.error(e);
app.showToastMessage(R.string.cannot_upload_image);
} finally {
Algorithms.closeStream(inputStream);
}
}
return success; return success;
} }
private boolean uploadImageToPlace(InputStream image) { private boolean uploadImageToPlace(InputStream image, int width, int height) {
boolean success = false; boolean success = false;
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image)); InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image, width, height));
String baseUrl = OPRConstants.getBaseUrl(app); String baseUrl = OPRConstants.getBaseUrl(app);
// all these should be constant // all these should be constant
String url = baseUrl + "api/ipfs/image"; String url = baseUrl + "api/ipfs/image";
@ -156,13 +162,9 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
checkTokenAndShowScreen(); checkTokenAndShowScreen();
} else { } else {
success = true; success = true;
String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
app.showToastMessage(str);
//refresh the image //refresh the image
if (listener != null) {
MapActivity activity = activityRef.get(); listener.uploadPhotosSuccess(response);
if (activity != null) {
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
} }
} }
} else { } else {
@ -191,36 +193,50 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
} }
} }
private byte[] compressImageToJpeg(InputStream image) { private int[] calcImageDimensions(InputStream image) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(image); BufferedInputStream bufferedInputStream = new BufferedInputStream(image);
Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream); BitmapFactory.Options opts = new BitmapFactory.Options();
ByteArrayOutputStream os = new ByteArrayOutputStream(); opts.inJustDecodeBounds = true;
int h = bmp.getHeight(); BitmapFactory.decodeStream(bufferedInputStream, null, opts);
int w = bmp.getWidth(); return new int[] { opts.outWidth, opts.outHeight };
}
private byte[] compressImageToJpeg(InputStream image, int width, int height) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(image);
int w = width;
int h = height;
boolean scale = false; boolean scale = false;
int divider = 1;
while (w > MAX_IMAGE_LENGTH || h > MAX_IMAGE_LENGTH) { while (w > MAX_IMAGE_LENGTH || h > MAX_IMAGE_LENGTH) {
w = w / 2; w /= 2;
h = h / 2; h /= 2;
divider *= 2;
scale = true; scale = true;
} }
Bitmap bmp;
if (scale) { if (scale) {
Matrix matrix = new Matrix(); BitmapFactory.Options opts = new BitmapFactory.Options();
matrix.postScale(w, h); opts.inSampleSize = divider;
Bitmap resizedBitmap = Bitmap.createBitmap( bmp = BitmapFactory.decodeStream(bufferedInputStream, null, opts);
bmp, 0, 0, w, h, matrix, false); } else {
bmp.recycle(); bmp = BitmapFactory.decodeStream(bufferedInputStream);
bmp = resizedBitmap;
} }
ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 90, os); bmp.compress(Bitmap.CompressFormat.JPEG, 90, os);
return os.toByteArray(); return os.toByteArray();
} }
public interface UploadPhotosProgressListener {
public interface UploadPhotosListener {
void uploadPhotosProgressUpdate(int progress); void uploadPhotosProgressUpdate(int progress);
void uploadPhotosFinished(); void uploadPhotosFinished();
} }
public interface UploadPhotosListener {
void uploadPhotosSuccess(String response);
}
} }

View file

@ -19,17 +19,13 @@ import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapillary.MapillaryContributeCard;
import net.osmand.plus.mapillary.MapillaryImageCard;
import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.wikimedia.WikiImageHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -41,18 +37,17 @@ import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; 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 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); private static final Log LOG = PlatformUtil.getLog(ImageCard.class);
protected String type; protected String type;
@ -184,11 +179,7 @@ public abstract class ImageCard extends AbstractCard {
try { try {
if (imageObject.has("type")) { if (imageObject.has("type")) {
String type = imageObject.getString("type"); String type = imageObject.getString("type");
if (TYPE_MAPILLARY_PHOTO.equals(type)) { if (!TYPE_MAPILLARY_CONTRIBUTE.equals(type) && !TYPE_MAPILLARY_PHOTO.equals(type)) {
imageCard = new MapillaryImageCard(mapActivity, imageObject);
} else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) {
imageCard = new MapillaryContributeCard(mapActivity, imageObject);
} else {
imageCard = new UrlImageCard(mapActivity, imageObject); imageCard = new UrlImageCard(mapActivity, imageObject);
} }
} }
@ -198,14 +189,6 @@ public abstract class ImageCard extends AbstractCard {
return imageCard; 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() { public double getCa() {
return ca; 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<Void, Void, List<ImageCard>> { public static class GetImageCardsTask extends AsyncTask<Void, Void, List<ImageCard>> {
private MapActivity mapActivity; private MapActivity mapActivity;
@ -451,7 +412,7 @@ public abstract class ImageCard extends AbstractCard {
} }
public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon,
@Nullable Map<String, String> params, GetImageCardsListener listener) { @Nullable Map<String, String> params, GetImageCardsListener listener) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication(); this.app = mapActivity.getMyApplication();
this.latLon = latLon; this.latLon = latLon;
@ -460,23 +421,9 @@ public abstract class ImageCard extends AbstractCard {
} }
@Override @Override
protected List<ImageCard> doInBackground(Void... params) { protected List<ImageCard> doInBackground(Void... voids) {
TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID); TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID);
List<ImageCard> result = new ArrayList<>(); List<ImageCard> 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.<String, String>emptyMap(),
"Requesting location images...", false, false);
if (response != null) {
getPicturesForPlace(result, response);
String[] id = getIdFromResponse(response);
listener.onPlaceIdAcquired(id);
}
}
try { try {
final Map<String, String> pms = new LinkedHashMap<>(); final Map<String, String> pms = new LinkedHashMap<>();
pms.put("lat", "" + (float) latLon.getLatitude()); pms.put("lat", "" + (float) latLon.getLatitude());
@ -493,19 +440,8 @@ public abstract class ImageCard extends AbstractCard {
if (!Algorithms.isEmpty(preferredLang)) { if (!Algorithms.isEmpty(preferredLang)) {
pms.put("lang", preferredLang); pms.put("lang", preferredLang);
} }
if (this.params != null) { OsmandPlugin.populateContextMenuImageCards(result, pms, params, listener);
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, String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
"Requesting location images...", false, false); "Requesting location images...", false, false);
@ -517,7 +453,10 @@ public abstract class ImageCard extends AbstractCard {
try { try {
JSONObject imageObject = (JSONObject) images.get(i); JSONObject imageObject = (JSONObject) images.get(i);
if (imageObject != JSONObject.NULL) { 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) { if (imageCard != null) {
result.add(imageCard); result.add(imageCard);
} }
@ -537,36 +476,6 @@ public abstract class ImageCard extends AbstractCard {
return result; return result;
} }
private void getPicturesForPlace(List<ImageCard> 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<String> 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 @Override
protected void onPostExecute(List<ImageCard> cardList) { protected void onPostExecute(List<ImageCard> cardList) {
result = cardList; result = cardList;

View file

@ -17,27 +17,34 @@ import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.dashboard.DashboardOnMap; 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.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView; 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.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; 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.text.MessageFormat;
import java.util.List; import java.util.List;
@ -47,11 +54,18 @@ import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction;
public class MapillaryPlugin extends OsmandPlugin { 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"; public static final String ID = "osmand.mapillary";
private static final String MAPILLARY_PACKAGE_ID = "app.mapillary"; private static final String MAPILLARY_PACKAGE_ID = "app.mapillary";
private static final Log LOG = PlatformUtil.getLog(OpenPlaceReviewsPlugin.class);
private OsmandSettings settings; private OsmandSettings settings;
private MapActivity mapActivity;
private MapillaryRasterLayer rasterLayer; private MapillaryRasterLayer rasterLayer;
private MapillaryVectorLayer vectorLayer; private MapillaryVectorLayer vectorLayer;
private TextInfoWidget mapillaryControl; private TextInfoWidget mapillaryControl;
@ -62,11 +76,6 @@ public class MapillaryPlugin extends OsmandPlugin {
settings = app.getSettings(); settings = app.getSettings();
} }
@Override
public boolean isVisible() {
return false;
}
@Override @Override
public int getLogoResourceId() { public int getLogoResourceId() {
return R.drawable.ic_action_mapillary; return R.drawable.ic_action_mapillary;
@ -92,6 +101,14 @@ public class MapillaryPlugin extends OsmandPlugin {
return app.getString(R.string.mapillary); return app.getString(R.string.mapillary);
} }
@Override
public boolean init(@NonNull OsmandApplication app, Activity activity) {
if (activity instanceof MapActivity) {
mapActivity = (MapActivity) activity;
}
return true;
}
@Override @Override
public void registerLayers(MapActivity activity) { public void registerLayers(MapActivity activity) {
createLayers(); createLayers();
@ -228,6 +245,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) { public static boolean openMapillary(FragmentActivity activity, String imageKey) {
boolean success = false; boolean success = false;
OsmandApplication app = (OsmandApplication) activity.getApplication(); OsmandApplication app = (OsmandApplication) activity.getApplication();

View file

@ -1,12 +1,16 @@
package net.osmand.plus.mapcontextmenu.builders.cards; package net.osmand.plus.openplacereviews;
import android.view.View; import android.view.View;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -16,16 +20,17 @@ public class IPFSImageCard extends ImageCard {
public IPFSImageCard(MapActivity mapActivity, JSONObject imageObject) { public IPFSImageCard(MapActivity mapActivity, JSONObject imageObject) {
super(mapActivity, imageObject); super(mapActivity, imageObject);
String cid = "";
try { try {
cid = (String) imageObject.get("cid"); String calcImageUrl = mapActivity.getString(R.string.opr_base_url) + "api/ipfs/image?";
calcImageUrl += "cid=" + (String) imageObject.getString("cid");
calcImageUrl += "&hash=" + (String) imageObject.getString("hash");
calcImageUrl += "&ext=" + (String) imageObject.getString("extension");
url = calcImageUrl;
imageHiresUrl = url;
imageUrl = url;
} catch (JSONException e) { } catch (JSONException e) {
LOG.error(e); LOG.error(e);
} }
String BASE_URL = mapActivity.getString(R.string.opr_base_url) + "api/ipfs/image-ipfs?cid=";
url = BASE_URL + cid;
imageHiresUrl = BASE_URL + cid;
imageUrl = BASE_URL + cid;
icon = ContextCompat.getDrawable(getMyApplication(), R.drawable.ic_logo_openplacereview); icon = ContextCompat.getDrawable(getMyApplication(), R.drawable.ic_logo_openplacereview);
if (!Algorithms.isEmpty(getUrl())) { if (!Algorithms.isEmpty(getUrl())) {
View.OnClickListener onClickListener = new View.OnClickListener() { View.OnClickListener onClickListener = new View.OnClickListener() {

View file

@ -1,9 +1,9 @@
package net.osmand.plus.openplacereviews; 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; import net.osmand.plus.osmedit.opr.OpenDBAPI;
public class OPRConstants { public class OPRConstants {
@ -11,28 +11,27 @@ public class OPRConstants {
private static final String PURPOSE = OpenDBAPI.PURPOSE; private static final String PURPOSE = OpenDBAPI.PURPOSE;
private static final String CALLBACK_URL = OPR_OAUTH_PREFIX + "://osmand_opr_auth"; private static final String CALLBACK_URL = OPR_OAUTH_PREFIX + "://osmand_opr_auth";
public static String getBaseUrl(Context ctx) { public static String getBaseUrl(@NonNull OsmandApplication app) {
return ctx.getString(R.string.opr_base_url); return app.getSettings().getOprUrl();
} }
public static String getLoginUrl(@NonNull OsmandApplication app) {
public static String getLoginUrl(Context ctx) { return getBaseUrl(app) + "login" + getQueryString();
return getBaseUrl(ctx) + "login" + getQueryString(ctx);
} }
public static String getRegisterUrl(Context ctx) { public static String getRegisterUrl(@NonNull OsmandApplication app) {
return getBaseUrl(ctx) + "signup" + getQueryString(ctx); return getBaseUrl(app) + "signup" + getQueryString();
} }
public static String getQueryString(Context ctx) { public static String getQueryString() {
return "?" + getPurposeParam(ctx) + "&" + getCallbackParam(ctx); return "?" + getPurposeParam() + "&" + getCallbackParam();
} }
public static String getPurposeParam(Context ctx) { public static String getPurposeParam() {
return "purpose=" + PURPOSE; return "purpose=" + PURPOSE;
} }
public static String getCallbackParam(Context ctx) { public static String getCallbackParam() {
return "callback=" + CALLBACK_URL; return "callback=" + CALLBACK_URL;
} }
} }

View file

@ -0,0 +1,199 @@
package net.osmand.plus.openplacereviews;
import android.app.Activity;
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);
public 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<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams,
@Nullable GetImageCardsListener listener) {
List<ImageCard> 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.<String, String>emptyMap(),
"Requesting location images...", false, false);
if (response != null) {
getPicturesForPlace(imageCards, response);
if (listener != null) {
listener.onPlaceIdAcquired(getIdFromResponse(response));
}
}
}
}
return imageCards;
}
@Override
protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
ImageCard imageCard = null;
if (mapActivity != null && imageObject != JSONObject.NULL) {
imageCard = createCardOpr(mapActivity, imageObject);
}
return imageCard;
}
private void getPicturesForPlace(List<ImageCard> 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<String> 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 boolean init(@NonNull OsmandApplication app, Activity activity) {
if (activity instanceof MapActivity) {
mapActivity = (MapActivity) activity;
}
return true;
}
@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);
}
}

View file

@ -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<OprAuthorizationListener> 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<Void, Void, Boolean> {
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();
}
}

View file

@ -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();
}
}
}

View file

@ -16,18 +16,21 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsIntent;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
import org.apache.commons.logging.Log; 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 String TAG = OprStartFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(OprStartFragment.class); private static final Log LOG = PlatformUtil.getLog(OprStartFragment.class);
private static final String openPlaceReviewsUrl = "OpenPlaceReviews.org"; private static final String openPlaceReviewsUrl = "OpenPlaceReviews.org";
@ -36,18 +39,22 @@ public class OprStartFragment extends BaseOsmAndFragment {
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
View v = UiUtilities.getInflater(requireMyActivity(), nightMode).inflate(R.layout.fragment_opr_login, container,
false); View v = UiUtilities.getInflater(requireMyActivity(), nightMode).inflate(R.layout.fragment_opr_login, container, false);
View createAccount = v.findViewById(R.id.register_opr_create_account); AndroidUtils.addStatusBarPadding21v(requireMyActivity(), v);
v.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
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 @Override
public void onClick(View view) { public void onClick(View v) {
FragmentActivity activity = getActivity(); dismiss();
if (activity != null) {
activity.getSupportFragmentManager().popBackStack();
}
} }
}); });
View createAccount = v.findViewById(R.id.register_opr_create_account);
UiUtilities.setupDialogButton(nightMode, createAccount, UiUtilities.DialogButtonType.PRIMARY, UiUtilities.setupDialogButton(nightMode, createAccount, UiUtilities.DialogButtonType.PRIMARY,
R.string.register_opr_create_new_account); R.string.register_opr_create_new_account);
createAccount.setOnClickListener(new View.OnClickListener() { createAccount.setOnClickListener(new View.OnClickListener() {
@ -70,14 +77,14 @@ public class OprStartFragment extends BaseOsmAndFragment {
} }
private void handleHaveAccount() { private void handleHaveAccount() {
String url = OPRConstants.getLoginUrl(requireContext()); String url = OPRConstants.getLoginUrl(requireMyApplication());
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(requireContext(), Uri.parse(url)); customTabsIntent.launchUrl(requireContext(), Uri.parse(url));
} }
private void handleCreateAccount() { private void handleCreateAccount() {
String url = OPRConstants.getRegisterUrl(requireContext()); String url = OPRConstants.getRegisterUrl(requireMyApplication());
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(requireContext(), Uri.parse(url)); 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) { public static void showInstance(@NonNull FragmentManager fm) {
try { try {

View file

@ -28,7 +28,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*; import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
/** /**
* Created by Denis * Created by Denis
@ -149,7 +149,9 @@ public class DashOsmEditsFragment extends DashBaseFragment
@Override @Override
public void authorizationCompleted() { public void authorizationCompleted() {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{selectedPoint}); if (selectedPoint != null) {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[] {selectedPoint});
}
} }
@Override @Override

View file

@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
@ -51,19 +52,18 @@ public class EditPOIMenuController extends MenuController {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
boolean isLogged = client.isValidToken() boolean isLogged = client.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get()) || !Algorithms.isEmpty(settings.OSM_USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get()); && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (point instanceof OpenstreetmapPoint) { if (point instanceof OpenstreetmapPoint) {
if (isLogged) { if (isLogged) {
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), SendPoiBottomSheetFragment.showInstance(fragmentManager, new OsmPoint[] {point});
new OsmPoint[]{getOsmPoint()});
} else { } else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); LoginBottomSheetFragment.showInstance(fragmentManager, null);
} }
} else if (point instanceof OsmNotesPoint) { } else if (point instanceof OsmNotesPoint) {
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), SendOsmNoteBottomSheetFragment.showInstance(fragmentManager, new OsmPoint[] {point});
new OsmPoint[]{getOsmPoint()});
} }
} }
} }

View file

@ -84,7 +84,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
additionalData.put("tags", tagstring); additionalData.put("tags", tagstring);
additionalData.put("visibility", visibility); additionalData.put("visibility", visibility);
return NetworkUtils.uploadFile(url, f, 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(), adapter.getClient(),
"file", "file",
true, additionalData); true, additionalData);
@ -138,7 +138,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
connection.setRequestMethod(requestMethod); connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$ connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
StringBuilder responseBody = new StringBuilder(); 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.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
connection.setDoInput(true); connection.setDoInput(true);
if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$ ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
if (n instanceof Node) { 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) { } 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, OsmPoint.stringAction.get(action));
ser.endTag(null, "osmChange"); //$NON-NLS-1$ ser.endTag(null, "osmChange"); //$NON-NLS-1$

View file

@ -141,7 +141,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
connection.setRequestMethod(requestMethod); connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(app)); connection.setRequestProperty("User-Agent", Version.getFullVersion(app));
if (!anonymous) { 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.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes(StandardCharsets.UTF_8)));
} }
connection.setDoInput(true); connection.setDoInput(true);

View file

@ -112,7 +112,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
boolean validToken = isValidToken(); boolean validToken = isValidToken();
Preference nameAndPasswordPref = findPreference(OSM_LOGOUT); Preference nameAndPasswordPref = findPreference(OSM_LOGOUT);
if (validToken || isLoginExists()) { 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.setVisible(true);
nameAndPasswordPref.setSummary(userName); nameAndPasswordPref.setSummary(userName);
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
@ -126,7 +126,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
} }
private boolean isLoginExists() { 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() { private void setupOfflineEditingPref() {
@ -140,7 +140,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
} }
private void setupUseDevUrlPref() { private void setupUseDevUrlPref() {
SwitchPreferenceEx useDevUrlPref = findPreference(settings.USE_DEV_URL.getId()); SwitchPreferenceEx useDevUrlPref = findPreference(settings.OSM_USE_DEV_URL.getId());
if (OsmandPlugin.isDevelopment()) { if (OsmandPlugin.isDevelopment()) {
Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_laptop); Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_laptop);
useDevUrlPref.setDescription(getString(R.string.use_dev_url_descr)); useDevUrlPref.setDescription(getString(R.string.use_dev_url_descr));
@ -176,8 +176,8 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey(); String prefId = preference.getKey();
if (settings.USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) { if (settings.OSM_USE_DEV_URL.getId().equals(prefId) && newValue instanceof Boolean) {
settings.USE_DEV_URL.set((Boolean) newValue); settings.OSM_USE_DEV_URL.set((Boolean) newValue);
osmLogout(); osmLogout();
return true; return true;
} }
@ -220,7 +220,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override @Override
public void onPreferenceChanged(String prefId) { public void onPreferenceChanged(String prefId) {
if (settings.USE_DEV_URL.getId().equals(prefId)) { if (settings.OSM_USE_DEV_URL.getId().equals(prefId)) {
osmLogout(); osmLogout();
} }
updateAllSettings(); updateAllSettings();

View file

@ -457,9 +457,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
public boolean sendGPXFiles(final FragmentActivity activity, Fragment fragment, final GpxInfo... info) { public boolean sendGPXFiles(final FragmentActivity activity, Fragment fragment, final GpxInfo... info) {
String name = settings.USER_NAME.get(); String name = settings.OSM_USER_NAME.get();
String pwd = settings.USER_PASSWORD.get(); String pwd = settings.OSM_USER_PASSWORD.get();
String authToken = settings.USER_ACCESS_TOKEN.get(); String authToken = settings.OSM_USER_ACCESS_TOKEN.get();
if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) { if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment); LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment);
return false; return false;

View file

@ -30,8 +30,8 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask<Void, Void, OsmBugRes
@Override @Override
protected void onPostExecute(OsmBugResult osmBugResult) { protected void onPostExecute(OsmBugResult osmBugResult) {
if (osmBugResult.warning != null) { if (osmBugResult.warning != null) {
app.getSettings().USER_NAME.resetToDefault(); app.getSettings().OSM_USER_NAME.resetToDefault();
app.getSettings().USER_PASSWORD.resetToDefault(); app.getSettings().OSM_USER_PASSWORD.resetToDefault();
app.showToastMessage(osmBugResult.warning); app.showToastMessage(osmBugResult.warning);
} else { } else {
app.showToastMessage(R.string.osm_authorization_success); app.showToastMessage(R.string.osm_authorization_success);

View file

@ -69,10 +69,10 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
messageField = sendGpxView.findViewById(R.id.message_field); messageField = sendGpxView.findViewById(R.id.message_field);
TextView accountName = sendGpxView.findViewById(R.id.user_name); TextView accountName = sendGpxView.findViewById(R.id.user_name);
if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) { if (!Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get())) {
accountName.setText(settings.USER_DISPLAY_NAME.get()); accountName.setText(settings.OSM_USER_DISPLAY_NAME.get());
} else { } else {
accountName.setText(settings.USER_NAME.get()); accountName.setText(settings.OSM_USER_NAME.get());
} }
String fileName = gpxInfos[0].getFileName(); String fileName = gpxInfos[0].getFileName();

View file

@ -61,7 +61,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
private EditText noteText; private EditText noteText;
private boolean isLoginOAuth() { private boolean isLoginOAuth() {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); return !Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get());
} }
@Override @Override
@ -150,8 +150,8 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
} }
private void updateAccountName() { private void updateAccountName() {
String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOAuth = settings.OSM_USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get(); String userNameOpenID = settings.OSM_USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
accountName.setText(userName); accountName.setText(userName);
updateSignIn(uploadAnonymously.isChecked()); updateSignIn(uploadAnonymously.isChecked());
@ -230,7 +230,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
private boolean isLogged() { private boolean isLogged() {
OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
return adapter.isValidToken() return adapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get()) || !Algorithms.isEmpty(settings.OSM_USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get()); && !Algorithms.isEmpty(settings.OSM_USER_PASSWORD.get());
} }
} }

View file

@ -47,7 +47,7 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
private boolean isLoginOAuth(OsmandSettings settings) { private boolean isLoginOAuth(OsmandSettings settings) {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); return !Algorithms.isEmpty(settings.OSM_USER_DISPLAY_NAME.get());
} }
@Override @Override
@ -68,8 +68,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
messageEditText.setSelection(messageEditText.getText().length()); messageEditText.setSelection(messageEditText.getText().length());
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOAuth = settings.OSM_USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get(); String userNameOpenID = settings.OSM_USER_NAME.get();
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID; String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
accountName.setText(userName); accountName.setText(userName);
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);

View file

@ -1,19 +1,10 @@
package net.osmand.plus.osmedit.oauth; package net.osmand.plus.osmedit.oauth;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.DefaultApi10a;
import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1AccessToken;
@ -24,7 +15,6 @@ import com.github.scribejava.core.model.Verb;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient; import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikipedia.WikipediaDialogFragment;
@ -52,7 +42,7 @@ public class OsmOAuthAuthorizationAdapter {
DefaultApi10a api10a; DefaultApi10a api10a;
String key; String key;
String secret; String secret;
if (app.getSettings().USE_DEV_URL.get()) { if (app.getSettings().OSM_USE_DEV_URL.get()) {
api10a = new OsmOAuthAuthorizationClient.OsmDevApi(); api10a = new OsmOAuthAuthorizationClient.OsmDevApi();
key = app.getString(R.string.osm_oauth_developer_key); key = app.getString(R.string.osm_oauth_developer_key);
secret = app.getString(R.string.osm_oauth_developer_secret); secret = app.getString(R.string.osm_oauth_developer_secret);
@ -78,8 +68,8 @@ public class OsmOAuthAuthorizationAdapter {
} }
public void restoreToken() { public void restoreToken() {
String token = app.getSettings().USER_ACCESS_TOKEN.get(); String token = app.getSettings().OSM_USER_ACCESS_TOKEN.get();
String tokenSecret = app.getSettings().USER_ACCESS_TOKEN_SECRET.get(); String tokenSecret = app.getSettings().OSM_USER_ACCESS_TOKEN_SECRET.get();
if (!(token.isEmpty() || tokenSecret.isEmpty())) { if (!(token.isEmpty() || tokenSecret.isEmpty())) {
client.setAccessToken(new OAuth1AccessToken(token, tokenSecret)); client.setAccessToken(new OAuth1AccessToken(token, tokenSecret));
} else { } else {
@ -93,8 +83,8 @@ public class OsmOAuthAuthorizationAdapter {
private void saveToken() { private void saveToken() {
OAuth1AccessToken accessToken = client.getAccessToken(); OAuth1AccessToken accessToken = client.getAccessToken();
app.getSettings().USER_ACCESS_TOKEN.set(accessToken.getToken()); app.getSettings().OSM_USER_ACCESS_TOKEN.set(accessToken.getToken());
app.getSettings().USER_ACCESS_TOKEN_SECRET.set(accessToken.getTokenSecret()); app.getSettings().OSM_USER_ACCESS_TOKEN_SECRET.set(accessToken.getTokenSecret());
} }
private void loadWebView(ViewGroup root, boolean nightMode, String url) { private void loadWebView(ViewGroup root, boolean nightMode, String url) {
@ -137,7 +127,7 @@ public class OsmOAuthAuthorizationAdapter {
} }
@Override @Override
protected void onPostExecute(@NonNull OAuth1RequestToken requestToken) { protected void onPostExecute(OAuth1RequestToken requestToken) {
if (requestToken != null) { if (requestToken != null) {
loadWebView(rootLayout, nightMode, client.getService().getAuthorizationUrl(requestToken)); loadWebView(rootLayout, nightMode, client.getService().getAuthorizationUrl(requestToken));
} else { } else {
@ -156,9 +146,11 @@ public class OsmOAuthAuthorizationAdapter {
@Override @Override
protected Void doInBackground(String... oauthVerifier) { protected Void doInBackground(String... oauthVerifier) {
client.authorize(oauthVerifier[0]); if (client.getRequestToken() != null) {
saveToken(); client.authorize(oauthVerifier[0]);
updateUserName(); saveToken();
updateUserName();
}
return null; return null;
} }
@ -180,7 +172,7 @@ public class OsmOAuthAuthorizationAdapter {
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
log.error(e); log.error(e);
} }
app.getSettings().USER_DISPLAY_NAME.set(userName); app.getSettings().OSM_USER_DISPLAY_NAME.set(userName);
} }
public String getUserName() throws InterruptedException, ExecutionException, IOException, XmlPullParserException { public String getUserName() throws InterruptedException, ExecutionException, IOException, XmlPullParserException {

View file

@ -54,18 +54,18 @@ public class OsmOAuthHelper {
public void resetAuthorization() { public void resetAuthorization() {
if (isValidToken()) { if (isValidToken()) {
settings.USER_ACCESS_TOKEN.resetToDefault(); settings.OSM_USER_ACCESS_TOKEN.resetToDefault();
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault(); settings.OSM_USER_ACCESS_TOKEN_SECRET.resetToDefault();
authorizationAdapter.resetToken(); authorizationAdapter.resetToken();
} else if (isLoginExists()) { } else if (isLoginExists()) {
settings.USER_NAME.resetToDefault(); settings.OSM_USER_NAME.resetToDefault();
settings.USER_PASSWORD.resetToDefault(); settings.OSM_USER_PASSWORD.resetToDefault();
} }
updateAdapter(); updateAdapter();
} }
private boolean isLoginExists() { 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());
} }
public void notifyAndRemoveListeners() { public void notifyAndRemoveListeners() {

View file

@ -1,7 +1,11 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import net.osmand.plus.settings.backend.ApplicationMode; import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.profiles.ConfigureProfileMenuAdapter.ProfileSelectedListener;
import net.osmand.plus.settings.backend.ApplicationMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -10,7 +14,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment<ConfigureProfileMenuAdapter> public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment<ConfigureProfileMenuAdapter>
implements ConfigureProfileMenuAdapter.ProfileSelectedListener { implements ProfileSelectedListener {
public static final String TAG = "ConfigureAppModesBottomSheetDialogFragment"; public static final String TAG = "ConfigureAppModesBottomSheetDialogFragment";
@ -56,4 +60,15 @@ public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSh
} }
ApplicationMode.changeProfileAvailability(item, isChecked, getMyApplication()); ApplicationMode.changeProfileAvailability(item, isChecked, getMyApplication());
} }
public static void showInstance(@NonNull FragmentManager fragmentManager, boolean usedOnMap, UpdateMapRouteMenuListener listener) {
if (fragmentManager.findFragmentByTag(TAG) == null) {
ConfigureAppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment();
fragment.setUsedOnMap(usedOnMap);
fragment.setUpdateMapRouteMenuListener(listener);
fragmentManager.beginTransaction()
.add(fragment, TAG)
.commitAllowingStateLoss();
}
}
} }

View file

@ -29,6 +29,8 @@ import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.transition.AutoTransition; import androidx.transition.AutoTransition;
import androidx.transition.Scene; import androidx.transition.Scene;
import androidx.transition.Transition; import androidx.transition.Transition;
@ -71,7 +73,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener;
import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
@ -870,16 +872,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
private void showProfileBottomSheetDialog() { private void showProfileBottomSheetDialog() {
final AppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment(); FragmentActivity activity = getMapActivity();
fragment.setUsedOnMap(true); if (activity != null) {
fragment.setUpdateMapRouteMenuListener(new AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener() { FragmentManager manager = activity.getSupportFragmentManager();
@Override ConfigureAppModesBottomSheetDialogFragment.showInstance(manager, true, new UpdateMapRouteMenuListener() {
public void updateAppModeMenu() { @Override
updateApplicationModes(); public void updateAppModeMenu() {
} updateApplicationModes();
}); }
getMapActivity().getSupportFragmentManager().beginTransaction() });
.add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss(); }
} }
private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) { private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) {

View file

@ -625,11 +625,14 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private List<RoutingParameter> getReliefParameters() { private List<RoutingParameter> getReliefParameters() {
List<RoutingParameter> reliefFactorParameters = new ArrayList<>(); List<RoutingParameter> reliefFactorParameters = new ArrayList<>();
Map<String, RoutingParameter> parameters = app.getRouter(applicationMode).getParameters(); GeneralRouter router = app.getRouter(applicationMode);
for (Map.Entry<String, RoutingParameter> entry : parameters.entrySet()) { if (router != null) {
RoutingParameter routingParameter = entry.getValue(); Map<String, RoutingParameter> parameters = router.getParameters();
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) { for (Map.Entry<String, RoutingParameter> entry : parameters.entrySet()) {
reliefFactorParameters.add(routingParameter); RoutingParameter routingParameter = entry.getValue();
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter);
}
} }
} }
return reliefFactorParameters; return reliefFactorParameters;

View file

@ -301,7 +301,12 @@ public class ApplicationMode {
} }
public boolean isCustomProfile() { public boolean isCustomProfile() {
return !defaultValues.contains(this); for (ApplicationMode mode : defaultValues) {
if (Algorithms.stringsEqual(mode.getStringKey(), getStringKey())) {
return false;
}
}
return true;
} }
public boolean isDerivedRoutingFrom(ApplicationMode mode) { public boolean isDerivedRoutingFrom(ApplicationMode mode) {

View file

@ -48,6 +48,7 @@ import net.osmand.plus.helpers.enums.TracksSortByMode;
import net.osmand.plus.mapillary.MapillaryPlugin; import net.osmand.plus.mapillary.MapillaryPlugin;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format; import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
import net.osmand.plus.mapmarkers.MapMarkersMode; import net.osmand.plus.mapmarkers.MapMarkersMode;
import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.profiles.NavigationIcon; import net.osmand.plus.profiles.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIconColors;
@ -653,7 +654,7 @@ public class OsmandSettings {
public static final String NUMBER_OF_FREE_DOWNLOADS_ID = "free_downloads_v3"; public static final String NUMBER_OF_FREE_DOWNLOADS_ID = "free_downloads_v3";
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
private final OsmandPreference<String> PLUGINS = new StringPreference(this, "enabled_plugins", MapillaryPlugin.ID).makeGlobal().makeShared(); private final OsmandPreference<String> PLUGINS = new StringPreference(this, "enabled_plugins", "").makeGlobal().makeShared();
public Set<String> getEnabledPlugins() { public Set<String> getEnabledPlugins() {
String plugs = PLUGINS.get(); String plugs = PLUGINS.get();
@ -1121,8 +1122,8 @@ public class OsmandSettings {
} }
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared(); public final OsmandPreference<String> OSM_USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared();
public final OsmandPreference<String> USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared(); public final OsmandPreference<String> 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_WORLD_PARAMETER = "";
public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none"; public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none";
@ -1156,13 +1157,13 @@ public class OsmandSettings {
new StringPreference(this, "user_osm_bug_name", "NoName/OsmAnd").makeGlobal().makeShared(); new StringPreference(this, "user_osm_bug_name", "NoName/OsmAnd").makeGlobal().makeShared();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> USER_PASSWORD = public final OsmandPreference<String> OSM_USER_PASSWORD =
new StringPreference(this, "user_password", "").makeGlobal().makeShared(); new StringPreference(this, "user_password", "").makeGlobal().makeShared();
public final OsmandPreference<String> USER_ACCESS_TOKEN = public final OsmandPreference<String> OSM_USER_ACCESS_TOKEN =
new StringPreference(this, "user_access_token", "").makeGlobal(); new StringPreference(this, "user_access_token", "").makeGlobal();
public final OsmandPreference<String> USER_ACCESS_TOKEN_SECRET = public final OsmandPreference<String> OSM_USER_ACCESS_TOKEN_SECRET =
new StringPreference(this, "user_access_token_secret", "").makeGlobal(); new StringPreference(this, "user_access_token_secret", "").makeGlobal();
public final OsmandPreference<String> OPR_ACCESS_TOKEN = public final OsmandPreference<String> OPR_ACCESS_TOKEN =
@ -1174,13 +1175,15 @@ public class OsmandSettings {
public final OsmandPreference<String> OPR_BLOCKCHAIN_NAME = public final OsmandPreference<String> OPR_BLOCKCHAIN_NAME =
new StringPreference(this, "opr_blockchain_name", "").makeGlobal(); new StringPreference(this, "opr_blockchain_name", "").makeGlobal();
public final OsmandPreference<Boolean> 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 // this value boolean is synchronized with settings_pref.xml preference offline POI/Bugs edition
public final OsmandPreference<Boolean> OFFLINE_EDITION = new BooleanPreference(this, "offline_osm_editing", true).makeGlobal().makeShared(); public final OsmandPreference<Boolean> OFFLINE_EDITION = new BooleanPreference(this, "offline_osm_editing", true).makeGlobal().makeShared();
public final OsmandPreference<Boolean> USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared(); public final OsmandPreference<Boolean> OSM_USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared();
public String getOsmUrl() { public String getOsmUrl() {
String osmUrl; String osmUrl;
if (USE_DEV_URL.get()) { if (OSM_USE_DEV_URL.get()) {
osmUrl = "https://master.apis.dev.openstreetmap.org/"; osmUrl = "https://master.apis.dev.openstreetmap.org/";
} else { } else {
osmUrl = "https://api.openstreetmap.org/"; osmUrl = "https://api.openstreetmap.org/";
@ -1188,6 +1191,10 @@ public class OsmandSettings {
return osmUrl; 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 // this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<DayNightMode> DAYNIGHT_MODE = public final CommonPreference<DayNightMode> DAYNIGHT_MODE =
new EnumStringPreference<DayNightMode>(this, "daynight_mode", DayNightMode.DAY, DayNightMode.values()); new EnumStringPreference<DayNightMode>(this, "daynight_mode", DayNightMode.DAY, DayNightMode.values());

View file

@ -124,7 +124,7 @@ public class ProfileSettingsItem extends OsmandSettingsItem {
if (Algorithms.isEmpty(modeBean.userProfileName)) { if (Algorithms.isEmpty(modeBean.userProfileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (appMode != null) { if (appMode != null) {
modeBean.userProfileName = app.getString(appMode.getNameKeyResource()); modeBean.userProfileName = appMode.toHumanString();
} }
} }
int number = 0; int number = 0;

View file

@ -6,7 +6,6 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -49,8 +48,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
userNameEditText = view.findViewById(R.id.name_edit_text); userNameEditText = view.findViewById(R.id.name_edit_text);
passwordEditText = view.findViewById(R.id.password_edit_text); passwordEditText = view.findViewById(R.id.password_edit_text);
String name = app.getSettings().USER_NAME.get(); String name = app.getSettings().OSM_USER_NAME.get();
String password = app.getSettings().USER_PASSWORD.get(); String password = app.getSettings().OSM_USER_PASSWORD.get();
if (savedInstanceState != null) { if (savedInstanceState != null) {
name = savedInstanceState.getString(USER_NAME_KEY, null); name = savedInstanceState.getString(USER_NAME_KEY, null);
@ -96,8 +95,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
app.getSettings().USER_NAME.set(userNameEditText.getText().toString()); app.getSettings().OSM_USER_NAME.set(userNameEditText.getText().toString());
app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString()); app.getSettings().OSM_USER_PASSWORD.set(passwordEditText.getText().toString());
Fragment targetFragment = getTargetFragment(); Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof ValidateOsmLoginListener) { if (targetFragment instanceof ValidateOsmLoginListener) {

View file

@ -61,6 +61,7 @@ import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.audionotes.MultimediaNotesFragment; import net.osmand.plus.audionotes.MultimediaNotesFragment;
import net.osmand.plus.development.DevelopmentSettingsFragment; import net.osmand.plus.development.DevelopmentSettingsFragment;
import net.osmand.plus.monitoring.MonitoringSettingsFragment; import net.osmand.plus.monitoring.MonitoringSettingsFragment;
import net.osmand.plus.openplacereviews.OprSettingsFragment;
import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.osmedit.OsmEditingFragment;
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment.AppModeChangedListener; 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), 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), 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), 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); DEVELOPMENT_SETTINGS(DevelopmentSettingsFragment.class.getName(), false, null, R.xml.development_settings, R.layout.global_preference_toolbar);
public final String fragmentName; public final String fragmentName;

View file

@ -34,6 +34,7 @@ import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -91,7 +92,11 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
String profileName = modeBean.userProfileName; String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) { if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
profileName = app.getString(appMode.getNameKeyResource()); if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = StringUtils.capitalize(modeBean.stringKey);
}
} }
itemHolder.title.setText(profileName); itemHolder.title.setText(profileName);
String routingProfile = ""; String routingProfile = "";

View file

@ -62,6 +62,7 @@ import net.osmand.util.Algorithms;
import net.osmand.view.ThreeStateCheckbox; import net.osmand.view.ThreeStateCheckbox;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -279,7 +280,11 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
String profileName = modeBean.userProfileName; String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) { if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
profileName = appMode.toHumanString(); if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = StringUtils.capitalize(modeBean.stringKey);
}
} }
builder.setTitle(profileName); builder.setTitle(profileName);

View file

@ -890,8 +890,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private void updateMenuState() { private void updateMenuState() {
if (menuType == TrackMenuType.OPTIONS) { if (menuType == TrackMenuType.OPTIONS) {
openMenuFullScreen(); openMenuFullScreen();
} else if (menuType == TrackMenuType.OVERVIEW) {
openMenuHeaderOnly();
} else { } else {
openMenuHalfScreen(); openMenuHalfScreen();
} }
@ -1130,7 +1128,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (mapActivity != null) { if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false); 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)) { if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
progress.dismiss(); 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 { try {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY);

View file

@ -1,10 +1,12 @@
package net.osmand.plus.wikipedia; package net.osmand.plus.wikipedia;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
@ -24,6 +26,8 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources; 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.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment;
@ -32,8 +36,9 @@ import net.osmand.plus.search.listitems.QuickSearchBannerListItem;
import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem; import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; 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.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.ObjectType;
import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -42,6 +47,7 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
@ -91,11 +97,24 @@ public class WikipediaPlugin extends OsmandPlugin {
this.mapActivity = activity; this.mapActivity = activity;
} }
@Override
public void mapActivityResumeOnTop(MapActivity activity) {
this.mapActivity = activity;
}
@Override @Override
public void mapActivityPause(MapActivity activity) { public void mapActivityPause(MapActivity activity) {
this.mapActivity = null; this.mapActivity = null;
} }
@Override
public boolean init(@NonNull OsmandApplication app, Activity activity) {
if (activity instanceof MapActivity) {
mapActivity = (MapActivity) activity;
}
return true;
}
@Override @Override
protected void registerLayerContextMenuActions(OsmandMapTileView mapView, protected void registerLayerContextMenuActions(OsmandMapTileView mapView,
ContextMenuAdapter adapter, ContextMenuAdapter adapter,
@ -435,4 +454,25 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
return false; return false;
} }
@Override
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params, @Nullable Map<String, String> additionalParams, @Nullable GetImageCardsListener listener) {
List<ImageCard> 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;
}
} }