From c3d88ab2316f5bbad177df17d7502b99abf7ac9d Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 6 Nov 2020 19:23:14 +0200 Subject: [PATCH 001/122] init --- OsmAnd/res/drawable/layout_bg.xml | 6 + OsmAnd/res/layout/send_osm_note_fragment.xml | 116 +++++++++++++++++ OsmAnd/res/layout/send_poi_fragment.xml | 117 +++++++++++++++++ OsmAnd/res/values/strings.xml | 1 + .../plus/osmedit/EditPOIMenuController.java | 14 +- .../SendOsmNoteBottomSheetFragment.java | 121 ++++++++++++++++++ .../dialogs/SendPoiBottomSheetFragment.java | 100 +++++++++++++++ 7 files changed, 473 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/res/drawable/layout_bg.xml create mode 100644 OsmAnd/res/layout/send_osm_note_fragment.xml create mode 100644 OsmAnd/res/layout/send_poi_fragment.xml create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java diff --git a/OsmAnd/res/drawable/layout_bg.xml b/OsmAnd/res/drawable/layout_bg.xml new file mode 100644 index 0000000000..a784ae5701 --- /dev/null +++ b/OsmAnd/res/drawable/layout_bg.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/OsmAnd/res/layout/send_osm_note_fragment.xml b/OsmAnd/res/layout/send_osm_note_fragment.xml new file mode 100644 index 0000000000..b6f4338751 --- /dev/null +++ b/OsmAnd/res/layout/send_osm_note_fragment.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/send_poi_fragment.xml b/OsmAnd/res/layout/send_poi_fragment.xml new file mode 100644 index 0000000000..692bd5dd5d --- /dev/null +++ b/OsmAnd/res/layout/send_poi_fragment.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index fc7a48c5bc..1df373bb3f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Closed changset Login Password Account diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 1d8a4e4aa6..237a503e1a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -15,6 +15,9 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmPoint.Action; +import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.render.RenderingIcons; @@ -48,11 +51,18 @@ public class EditPOIMenuController extends MenuController { OsmandApplication app = activity.getMyApplication(); OsmandSettings settings = app.getSettings(); OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); + OsmPoint point = getOsmPoint(); if (client.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - SimpleProgressDialogPoiUploader poiDialogUploader = new SimpleProgressDialogPoiUploader(activity); - poiDialogUploader.showProgressDialog(new OsmPoint[] {getOsmPoint()}, false, false); + if (point instanceof OpenstreetmapPoint) { + SendPoiBottomSheetFragment sendPoiBottomSheetFragment = + SendPoiBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); + sendPoiBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); + } else if ( point instanceof OsmNotesPoint) { + SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = + SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); + sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java new file mode 100644 index 0000000000..be0fe84ca4 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -0,0 +1,121 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.os.Bundle; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.SwitchCompat; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmPoint; +import net.osmand.plus.settings.backend.OsmandSettings; + +public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = "SendPoiBottomSheetFragment"; + public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; + public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; + private OsmPoint[] poi; + + protected OsmandSettings settings; + + public enum PoiUploaderType { + SIMPLE, + FRAGMENT + } + + protected OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); + final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); + final LinearLayout accountBlockView = (LinearLayout) sendOsmNoteView.findViewById(R.id.account_block); + final SwitchCompat uploadAnonymously = (SwitchCompat) sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); + final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name); + accountName.setText(userName); + accountBlockView.setVisibility(View.VISIBLE); + uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); + } + }); + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmNoteView) + .create(); + items.add(titleItem); + } + + public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { + SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + return fragment; + } + + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } + + @Override + protected void onRightBottomButtonClick() { + View view = getView(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + boolean hasPoiGroup = false; + assert poi != null; + for (OsmPoint p : poi) { + if (p.getGroup() == OsmPoint.Group.POI) { + hasPoiGroup = true; + break; + } + } + final boolean hasPOI = hasPoiGroup; + final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); + final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); + final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); + final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; + if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { + progressDialogPoiUploader = + new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + } else { + progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } + } + } + progressDialogPoiUploader.showProgressDialog(poi, + false, + !hasPOI && uploadAnonymously.isChecked()); + } + dismiss(); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java new file mode 100644 index 0000000000..17c29f5875 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -0,0 +1,100 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.SwitchCompat; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmPoint; + +public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = "SendPoiBottomSheetFragment"; + public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; + public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; + private OsmPoint[] poi; + + public enum PoiUploaderType { + SIMPLE, + FRAGMENT + } + + protected OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); + final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_poi_fragment, null); + final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name); + accountName.setText(userName); + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmNoteView) + .create(); + items.add(titleItem); + } + + public static SendPoiBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { + SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + return fragment; + } + + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } + + @Override + protected void onRightBottomButtonClick() { + View view = getView(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + final SwitchCompat closeChangeSetCheckBox = + (SwitchCompat) view.findViewById(R.id.close_change_set_checkbox); + final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); + final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); + final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; + if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { + progressDialogPoiUploader = + new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + } else { + progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } + } + } + progressDialogPoiUploader.showProgressDialog(poi, + closeChangeSetCheckBox.isChecked(), + false); + } + dismiss(); +} + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } + +} + From 7ba46570a017a583293fc8207e2f2fef0f842537 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Sat, 7 Nov 2020 15:39:50 +0200 Subject: [PATCH 002/122] Switch customize --- OsmAnd/res/drawable/layout_bg_dark.xml | 6 + OsmAnd/res/drawable/layout_bg_dark_solid.xml | 6 + OsmAnd/res/drawable/layout_bg_solid.xml | 6 + OsmAnd/res/layout/send_osm_note_fragment.xml | 18 +- OsmAnd/res/layout/send_poi_fragment.xml | 11 +- .../SendOsmNoteBottomSheetFragment.java | 185 +++++++++--------- .../dialogs/SendPoiBottomSheetFragment.java | 22 ++- 7 files changed, 154 insertions(+), 100 deletions(-) create mode 100644 OsmAnd/res/drawable/layout_bg_dark.xml create mode 100644 OsmAnd/res/drawable/layout_bg_dark_solid.xml create mode 100644 OsmAnd/res/drawable/layout_bg_solid.xml diff --git a/OsmAnd/res/drawable/layout_bg_dark.xml b/OsmAnd/res/drawable/layout_bg_dark.xml new file mode 100644 index 0000000000..f821ad3078 --- /dev/null +++ b/OsmAnd/res/drawable/layout_bg_dark.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/OsmAnd/res/drawable/layout_bg_dark_solid.xml b/OsmAnd/res/drawable/layout_bg_dark_solid.xml new file mode 100644 index 0000000000..59a1c38141 --- /dev/null +++ b/OsmAnd/res/drawable/layout_bg_dark_solid.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/layout_bg_solid.xml b/OsmAnd/res/drawable/layout_bg_solid.xml new file mode 100644 index 0000000000..0824ba1b7b --- /dev/null +++ b/OsmAnd/res/drawable/layout_bg_solid.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/send_osm_note_fragment.xml b/OsmAnd/res/layout/send_osm_note_fragment.xml index b6f4338751..4ce16dc2e8 100644 --- a/OsmAnd/res/layout/send_osm_note_fragment.xml +++ b/OsmAnd/res/layout/send_osm_note_fragment.xml @@ -21,8 +21,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" - android:textSize="@dimen/default_desc_text_size" - android:text = "@string/osm_notes" /> + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_medium" + android:text = "@string/osm_notes" + android:letterSpacing="@dimen/text_button_letter_spacing"/> + android:paddingBottom="@dimen/content_padding_small" + android:paddingTop="@dimen/content_padding_small" + android:text="@string/upload_anonymously" + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/default_list_text_size" + android:letterSpacing="@dimen/text_button_letter_spacing" + osmand:typeface="@string/font_roboto_regular"/> diff --git a/OsmAnd/res/layout/send_poi_fragment.xml b/OsmAnd/res/layout/send_poi_fragment.xml index 692bd5dd5d..dbc4766d52 100644 --- a/OsmAnd/res/layout/send_poi_fragment.xml +++ b/OsmAnd/res/layout/send_poi_fragment.xml @@ -22,7 +22,9 @@ android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:text="@string/upload_poi" - android:textSize="@dimen/default_desc_text_size" /> + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_medium" + android:letterSpacing="@dimen/text_button_letter_spacing"/> + android:paddingLeft="50dp" + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_regular" + android:letterSpacing="@dimen/text_button_letter_spacing"/> diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index be0fe84ca4..70f4846f0e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit.dialogs; +import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.CompoundButton; @@ -22,100 +23,108 @@ import net.osmand.plus.settings.backend.OsmandSettings; public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = "SendPoiBottomSheetFragment"; - public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; - public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; - private OsmPoint[] poi; + public static final String TAG = "SendPoiBottomSheetFragment"; + public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; + public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; + private OsmPoint[] poi; - protected OsmandSettings settings; + protected OsmandSettings settings; - public enum PoiUploaderType { - SIMPLE, - FRAGMENT - } + public enum PoiUploaderType { + SIMPLE, + FRAGMENT + } - protected OsmandApplication getMyApplication() { - return (OsmandApplication) getActivity().getApplication(); - } + protected OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } - @Override - public void createMenuItems(Bundle savedInstanceState) { - String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); - final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); - final LinearLayout accountBlockView = (LinearLayout) sendOsmNoteView.findViewById(R.id.account_block); - final SwitchCompat uploadAnonymously = (SwitchCompat) sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); - final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name); - accountName.setText(userName); - accountBlockView.setVisibility(View.VISIBLE); - uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); - } - }); - final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setCustomView(sendOsmNoteView) - .create(); - items.add(titleItem); - } + @Override + public void createMenuItems(Bundle savedInstanceState) { + final boolean isNightMode = !getMyApplication().getSettings().isLightContent(); + final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); + final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block); + final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); + final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); + String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); + accountName.setText(userName); + accountBlockView.setVisibility(View.VISIBLE); + uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + uploadAnonymously.setPadding(30, 0, 0, 0); + uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); + if (isNightMode) { + uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + } else { + uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + } + uploadAnonymously.setPadding(30, 0, 0, 0); + } + }); + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmNoteView) + .create(); + items.add(titleItem); + } - public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { - SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); - fragment.setArguments(bundle); - return fragment; - } + public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { + SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + return fragment; + } - @Override - protected UiUtilities.DialogButtonType getRightBottomButtonType() { - return (UiUtilities.DialogButtonType.PRIMARY); - } + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } - @Override - protected void onRightBottomButtonClick() { - View view = getView(); - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); - boolean hasPoiGroup = false; - assert poi != null; - for (OsmPoint p : poi) { - if (p.getGroup() == OsmPoint.Group.POI) { - hasPoiGroup = true; - break; - } - } - final boolean hasPOI = hasPoiGroup; - final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); - final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); - final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); - final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; - if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { - progressDialogPoiUploader = - new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); - } else { - progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); - } - if (progressDialogPoiUploader != null) { - String comment = messageEditText.getText().toString(); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; - } - } - } - progressDialogPoiUploader.showProgressDialog(poi, - false, - !hasPOI && uploadAnonymously.isChecked()); - } - dismiss(); - } - - @Override - protected int getRightBottomButtonTextId() { - return R.string.shared_string_upload; - } + @Override + protected void onRightBottomButtonClick() { + View view = getView(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + boolean hasPoiGroup = false; + assert poi != null; + for (OsmPoint p : poi) { + if (p.getGroup() == OsmPoint.Group.POI) { + hasPoiGroup = true; + break; + } + } + final boolean hasPOI = hasPoiGroup; + final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); + final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); + final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); + final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; + if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { + progressDialogPoiUploader = + new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + } else { + progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } + } + } + progressDialogPoiUploader.showProgressDialog(poi, + false, + !hasPOI && uploadAnonymously.isChecked()); + } + dismiss(); + } + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 17c29f5875..8270891c50 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.osmedit.dialogs; import android.os.Bundle; import android.view.View; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.TextView; @@ -35,12 +36,27 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { + final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final View sendOsmPoiView = View.inflate(getContext(), R.layout.send_poi_fragment, null); + final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); + final TextView accountName = (TextView) sendOsmPoiView.findViewById(R.id.user_name); String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); - final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_poi_fragment, null); - final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name); accountName.setText(userName); + closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + closeChangset.setPadding(30, 0, 0, 0); + closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isNightMode) { + closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + } else { + closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + } + closeChangset.setPadding(30, 0, 0, 0); + } + }); final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setCustomView(sendOsmNoteView) + .setCustomView(sendOsmPoiView) .create(); items.add(titleItem); } From a007e8efc5b953eb856a4675e1971f62462d924b Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Sun, 8 Nov 2020 00:50:23 +0200 Subject: [PATCH 003/122] save --- .../LoginBottomSheetFragment.java | 4 ++++ .../osmand/plus/osmedit/OsmEditsFragment.java | 14 ++++++++++-- .../SendOsmNoteBottomSheetFragment.java | 14 +++++++++--- .../dialogs/SendPoiBottomSheetFragment.java | 22 ++++++++++++++----- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index 44547815ce..83e8bc1d13 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -92,6 +92,10 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { } } + private boolean isValidToken() { + return authorizationAdapter.isValidToken(); + } + @Override protected DialogButtonType getRightBottomButtonType() { return (DialogButtonType.SECONDARY); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 0a4cc5d7ff..f0abe4eb03 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -43,6 +43,8 @@ import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -626,17 +628,25 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return (OsmandApplication) getActivity().getApplication(); } + private void uploadItems(final OsmPoint[] items) { FragmentActivity activity = getActivity(); if (activity != null) { OsmandApplication app = getMyApplication(); OsmandSettings settings = app.getSettings(); + boolean isPoi = getOsmEditsByGroup(Group.POI) instanceof OpenstreetmapPoint; OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); if (authorizationAdapter.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) - .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); + if (isPoi) { + SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = + SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); + sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); + } else { + SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = + SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); + sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 70f4846f0e..f5a618e5af 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,7 +1,7 @@ package net.osmand.plus.osmedit.dialogs; -import android.content.Context; import android.os.Bundle; +import android.view.ContextThemeWrapper; import android.view.View; import android.widget.CompoundButton; import android.widget.EditText; @@ -20,6 +20,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.util.Algorithms; public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { @@ -39,14 +40,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen return (OsmandApplication) getActivity().getApplication(); } + private boolean isLoginOAuth() { + return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + } + @Override public void createMenuItems(Bundle savedInstanceState) { final boolean isNightMode = !getMyApplication().getSettings().isLightContent(); - final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); + final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_osm_note_fragment, null); final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block); final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); - String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); + settings = getMyApplication().getSettings(); + String userNameOAuth = settings.USER_DISPLAY_NAME.get(); + String userNameOpenID = settings.USER_NAME.get(); + String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); accountBlockView.setVisibility(View.VISIBLE); uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 8270891c50..fd9655ebb8 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.osmedit.dialogs; import android.os.Bundle; +import android.view.ContextThemeWrapper; import android.view.View; import android.widget.CompoundButton; import android.widget.EditText; @@ -17,6 +18,8 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmPoint; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.util.Algorithms; public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @@ -25,6 +28,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; + protected OsmandSettings settings; + public enum PoiUploaderType { SIMPLE, FRAGMENT @@ -34,13 +39,20 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { return (OsmandApplication) getActivity().getApplication(); } + private boolean isLoginOAuth() { + return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + } + @Override public void createMenuItems(Bundle savedInstanceState) { final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final View sendOsmPoiView = View.inflate(getContext(), R.layout.send_poi_fragment, null); + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_poi_fragment, null); final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); - final TextView accountName = (TextView) sendOsmPoiView.findViewById(R.id.user_name); - String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); + final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); + settings = getMyApplication().getSettings(); + String userNameOAuth = settings.USER_DISPLAY_NAME.get(); + String userNameOpenID = settings.USER_NAME.get(); + String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); closeChangset.setPadding(30, 0, 0, 0); @@ -80,8 +92,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { View view = getView(); poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); final SwitchCompat closeChangeSetCheckBox = - (SwitchCompat) view.findViewById(R.id.close_change_set_checkbox); - final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); + view.findViewById(R.id.close_change_set_checkbox); + final EditText messageEditText = view.findViewById(R.id.message_field); final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { From bcafe632c324e556449365426bdbdab2886e3ad8 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 9 Nov 2020 19:12:31 +0200 Subject: [PATCH 004/122] Add BugBottomSheetDialog --- OsmAnd/res/layout/track_name_edit_text.xml | 3 +- OsmAnd/res/values/strings.xml | 2 + .../net/osmand/plus/osmedit/OsmBugsLayer.java | 33 ++++--- .../osmedit/dialogs/BugBottomSheetDialog.java | 96 +++++++++++++++++++ 4 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java diff --git a/OsmAnd/res/layout/track_name_edit_text.xml b/OsmAnd/res/layout/track_name_edit_text.xml index 545b7c42a0..6ab03cd632 100644 --- a/OsmAnd/res/layout/track_name_edit_text.xml +++ b/OsmAnd/res/layout/track_name_edit_text.xml @@ -23,7 +23,8 @@ + android:layout_height="wrap_content" + android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" /> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1df373bb3f..5b17b98a81 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Comment OSM Note + Close OSM Note Closed changset Login Password diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index da6dd2bdd3..a2254ed310 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -25,6 +25,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.base.PointImageDrawable; +import net.osmand.plus.osmedit.dialogs.BugBottomSheetDialog; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -67,7 +68,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } public OsmBugsUtil getOsmbugsUtil(OpenStreetNote bug) { - OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); + OsmandSettings settings = activity.getMyApplication().getSettings(); if ((bug != null && bug.isLocal()) || settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { return local; @@ -413,30 +414,38 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider private void showBugDialog(final OsmNotesPoint point) { String text = point.getText(); - createBugDialog(true, text, R.string.osn_modify_dialog_title, null, null, point); + createBugDialog(true, text, R.string.context_menu_item_modify_note, R.string.osn_modify_dialog_title, + null, null, point); } private void showBugDialog(final OpenStreetNote bug, final Action action, String text) { - int title; + int posButtonTextId; + int titleTextId; if (action == Action.DELETE) { - title = R.string.osn_close_dialog_title; + posButtonTextId = R.string.osn_close_dialog_title; + titleTextId = R.string.osm_edit_close_note; } else if (action == Action.MODIFY) { - title = R.string.osn_comment_dialog_title; + posButtonTextId = R.string.osn_comment_dialog_title; + titleTextId = R.string.osm_edit_comment_note; } else if (action == Action.REOPEN) { - title = R.string.osn_reopen_dialog_title; + posButtonTextId = R.string.osn_reopen_dialog_title; + titleTextId = R.string.osn_reopen_dialog_title; } else { - title = R.string.osn_add_dialog_title; + posButtonTextId = R.string.osn_add_dialog_title; + titleTextId = R.string.context_menu_item_open_note; } OsmBugsUtil util = getOsmbugsUtil(bug); final boolean offline = util instanceof OsmBugsLocalUtil; - createBugDialog(offline, text, title, action, bug, null); + createBugDialog(offline, text, titleTextId, posButtonTextId, action, bug, null); } - private void createBugDialog(final boolean offline, String text, int posButtonTitleRes, final Action action, final OpenStreetNote bug, final OsmNotesPoint point) { - @SuppressLint("InflateParams") - final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null); + private void createBugDialog(final boolean offline, String text, int titleTextId, int posButtonTextId, + final Action action, final OpenStreetNote bug, final OsmNotesPoint point) { + BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), offline, text, titleTextId, + posButtonTextId, action, bug, null); + @SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null); if (offline) { view.findViewById(R.id.user_name_field).setVisibility(View.GONE); view.findViewById(R.id.userNameEditTextLabel).setVisibility(View.GONE); @@ -455,7 +464,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.shared_string_commit); builder.setView(view); - builder.setPositiveButton(posButtonTitleRes, new DialogInterface.OnClickListener() { + builder.setPositiveButton(posButtonTextId, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String text = offline ? getMessageText(view) : getTextAndUpdateUserPwd(view); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java new file mode 100644 index 0000000000..f809ed494e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java @@ -0,0 +1,96 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.content.res.ColorStateList; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + +import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.osmedit.OsmBugsLayer; +import net.osmand.plus.osmedit.OsmNotesPoint; +import net.osmand.plus.osmedit.OsmPoint; + +import org.apache.commons.logging.Log; + +public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { + + public static final String TAG = BugBottomSheetDialog.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(BugBottomSheetDialog.class); + + boolean offline; + String text; + int titleTextId; + int posButtonTextId; + OsmPoint.Action action; + OsmBugsLayer.OpenStreetNote bug; + OsmNotesPoint point; + private TextInputLayout textBox; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + + items.add(new TitleItem(getString(titleTextId))); + + View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode), + R.layout.track_name_edit_text, null); + textBox = osmNoteView.findViewById(R.id.name_text_box); + int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light; + textBox.setBoxBackgroundColorResource(highlightColorId); + textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); + ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat + .getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)); + textBox.setDefaultHintTextColor(colorStateList); + TextInputEditText noteText = osmNoteView.findViewById(R.id.name_edit_text); + noteText.setText(text); + + BaseBottomSheetItem editOsmNote = new BaseBottomSheetItem.Builder() + .setCustomView(osmNoteView) + .create(); + items.add(editOsmNote); + + items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + } + + @Override + protected int getRightBottomButtonTextId() { + return posButtonTextId; + } + + public static void showInstance(@NonNull FragmentManager fm, final boolean offline, + String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action, + final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point) { + try { + if (!fm.isStateSaved()) { + BugBottomSheetDialog fragment = new BugBottomSheetDialog(); + fragment.offline = offline; + fragment.text = text; + fragment.titleTextId = titleTextId; + fragment.posButtonTextId = posButtonTextId; + fragment.action = action; + fragment.bug = bug; + fragment.point = point; + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } +} From a33b703cf72507d4103d76339eeceb874d127774 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 10 Nov 2020 20:28:42 +0200 Subject: [PATCH 005/122] Refactoring async task --- .../plus/osmedit/HandleOsmNoteAsyncTask.java | 54 ++++++ .../net/osmand/plus/osmedit/OsmBugsLayer.java | 167 ++++++++---------- .../osmand/plus/osmedit/OsmEditingPlugin.java | 9 +- .../osmedit/dialogs/BugBottomSheetDialog.java | 35 +++- .../SendOsmNoteBottomSheetFragment.java | 11 +- 5 files changed, 164 insertions(+), 112 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/HandleOsmNoteAsyncTask.java diff --git a/OsmAnd/src/net/osmand/plus/osmedit/HandleOsmNoteAsyncTask.java b/OsmAnd/src/net/osmand/plus/osmedit/HandleOsmNoteAsyncTask.java new file mode 100644 index 0000000000..0a2a55191d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/HandleOsmNoteAsyncTask.java @@ -0,0 +1,54 @@ +package net.osmand.plus.osmedit; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class HandleOsmNoteAsyncTask extends AsyncTask { + private OsmBugsUtil osmbugsUtil; + private final OsmBugsUtil local; + private final OsmBugsLayer.OpenStreetNote bug; + private final OsmNotesPoint point; + private final String text; + private final OsmPoint.Action action; + private final HandleBugListener handleBugListener; + + public HandleOsmNoteAsyncTask(@NonNull OsmBugsUtil osmbugsUtil, @NonNull OsmBugsUtil local, + @Nullable OsmBugsLayer.OpenStreetNote bug, @Nullable OsmNotesPoint point, + String text, OsmPoint.Action action, + @Nullable HandleBugListener handleBugListener) { + this.osmbugsUtil = osmbugsUtil; + this.local = local; + this.bug = bug; + this.point = point; + this.text = text; + this.action = action; + this.handleBugListener = handleBugListener; + } + + @Override + protected OsmBugsUtil.OsmBugResult doInBackground(Void... params) { + if (bug != null) { + OsmNotesPoint pnt = new OsmNotesPoint(); + pnt.setId(bug.getId()); + pnt.setLatitude(bug.getLatitude()); + pnt.setLongitude(bug.getLongitude()); + return osmbugsUtil.commit(pnt, text, action); + } else if (point != null) { + osmbugsUtil = local; + return osmbugsUtil.modify(point, text); + } + return null; + } + + protected void onPostExecute(OsmBugsUtil.OsmBugResult obj) { + handleBugListener.onOsmBugHandled(obj, action, bug, point, text); + } + + public interface HandleBugListener { + + void onOsmBugHandled(OsmBugsUtil.OsmBugResult obj, OsmPoint.Action action, OsmBugsLayer.OpenStreetNote bug, + OsmNotesPoint point, String text); + } +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index a2254ed310..821f7fd8ca 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -4,7 +4,6 @@ import android.annotation.SuppressLint; import android.content.DialogInterface; import android.graphics.Canvas; import android.graphics.PointF; -import android.os.AsyncTask; import android.util.Xml; import android.view.LayoutInflater; import android.view.View; @@ -29,7 +28,6 @@ import net.osmand.plus.osmedit.dialogs.BugBottomSheetDialog; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.OsmandMapLayer; @@ -48,6 +46,8 @@ import java.net.URLConnection; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.osmedit.OsmBugsUtil.*; + public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider { private static final Log log = PlatformUtil.getLog(OsmBugsLayer.class); @@ -246,7 +246,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider return text; } - protected List loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) { final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; @@ -311,89 +310,16 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider return bugs; } - private void asyncActionTask(final OpenStreetNote bug, final OsmNotesPoint point, final String text, final Action action) { - AsyncTask task = new AsyncTask() { - private OsmBugsUtil osmbugsUtil; - - @Override - protected OsmBugResult doInBackground(Void... params) { - if (bug != null) { - osmbugsUtil = getOsmbugsUtil(bug); - OsmNotesPoint pnt = new OsmNotesPoint(); - pnt.setId(bug.getId()); - pnt.setLatitude(bug.getLatitude()); - pnt.setLongitude(bug.getLongitude()); - return osmbugsUtil.commit(pnt, text, action); - } else if (point != null) { - osmbugsUtil = local; - return osmbugsUtil.modify(point, text); - } - return null; - } - - protected void onPostExecute(OsmBugResult obj) { - if (activity == null || activity.isFinishing() || activity.isActivityDestroyed()) { - return; - } - if (obj != null && obj.warning == null) { - if (local == osmbugsUtil) { - Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show(); - if (obj.local != null) { - PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText()); - activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local); - } - } else { - if (action == Action.REOPEN) { - Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); - } else if (action == Action.MODIFY) { - Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show(); - } else if (action == Action.DELETE) { - Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show(); - } else if (action == Action.CREATE) { - Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); - } - - } - clearCache(); - } else { - int r = R.string.osb_comment_dialog_error; - if (action == Action.REOPEN) { - r = R.string.osn_add_dialog_error; - reopenBug(bug, text); - } else if (action == Action.DELETE) { - r = R.string.osn_close_dialog_error; - closeBug(bug, text); - } else if (action == Action.CREATE) { - r = R.string.osn_add_dialog_error; - openBug(bug.getLatitude(), bug.getLongitude(), text); - } else if (action == null) { - r = R.string.osn_modify_dialog_error; - modifyBug(point); - } else { - commentBug(bug, text); - } - Toast.makeText(activity, activity.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show(); - } - } - }; - executeTaskInBackground(task); - } - - - public void openBug(final double latitude, final double longitude, String message) { - OpenStreetNote bug = new OpenStreetNote(); - bug.setLatitude(latitude); - bug.setLongitude(longitude); - showBugDialog(bug, Action.CREATE, message); - } - public void openBug(final double latitude, final double longitude, String message, boolean autofill) { OpenStreetNote bug = new OpenStreetNote(); bug.setLatitude(latitude); bug.setLongitude(longitude); - - if (autofill) asyncActionTask(bug, null, message, Action.CREATE); - else showBugDialog(bug, Action.CREATE, message); + if (autofill) { + executeTaskInBackground(new HandleOsmNoteAsyncTask(getOsmbugsUtil(bug), local, bug, null, message, + Action.CREATE, getHandleBugListener())); + } else { + showBugDialog(bug, Action.CREATE, message); + } } public void closeBug(final OpenStreetNote bug, String txt) { @@ -443,8 +369,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider private void createBugDialog(final boolean offline, String text, int titleTextId, int posButtonTextId, final Action action, final OpenStreetNote bug, final OsmNotesPoint point) { - BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), offline, text, titleTextId, - posButtonTextId, action, bug, null); + if (offline) { + activity.getContextMenu().close(); + BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text, + titleTextId, posButtonTextId, action, bug, point, getHandleBugListener()); + return; + } @SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null); if (offline) { view.findViewById(R.id.user_name_field).setVisibility(View.GONE); @@ -453,7 +383,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider view.findViewById(R.id.passwordEditTextLabel).setVisibility(View.GONE); } else { ((EditText) view.findViewById(R.id.user_name_field)).setText(getUserName()); - ((EditText) view.findViewById(R.id.password_field)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get()); + ((EditText) view.findViewById(R.id.password_field)).setText( + activity.getMyApplication().getSettings().USER_PASSWORD.get()); } if (!Algorithms.isEmpty(text)) { ((EditText) view.findViewById(R.id.message_field)).setText(text); @@ -469,17 +400,71 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider public void onClick(DialogInterface dialog, int which) { String text = offline ? getMessageText(view) : getTextAndUpdateUserPwd(view); activity.getContextMenu().close(); - if (bug != null) { - asyncActionTask(bug, null, text, action); - } else if (point != null) { - asyncActionTask(null, point, text, null); - } + handleBug(text, bug, action, point); } }); builder.setNegativeButton(R.string.shared_string_cancel, null); builder.create().show(); } + private void handleBug(String text, OpenStreetNote bug, Action action, OsmNotesPoint point) { + if (bug != null || point != null) { + executeTaskInBackground(new HandleOsmNoteAsyncTask(getOsmbugsUtil(bug), local, bug, point, text, action, + getHandleBugListener())); + } + } + + HandleOsmNoteAsyncTask.HandleBugListener getHandleBugListener() { + return new HandleOsmNoteAsyncTask.HandleBugListener() { + @Override + public void onOsmBugHandled(OsmBugResult obj, Action action, OpenStreetNote bug, + OsmNotesPoint point, String text) { + if (activity == null || activity.isFinishing()) { + return; + } + if (obj != null && obj.warning == null) { + if (local == getOsmbugsUtil(bug)) { + Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show(); + if (obj.local != null) { + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText()); + activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), + pd, obj.local); + } + } else { + if (action == Action.REOPEN) { + Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); + } else if (action == Action.MODIFY) { + Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show(); + } else if (action == Action.DELETE) { + Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show(); + } else if (action == Action.CREATE) { + Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); + } + } + clearCache(); + } else { + int r = R.string.osb_comment_dialog_error; + if (action == Action.REOPEN) { + r = R.string.osn_add_dialog_error; + reopenBug(bug, text); + } else if (action == Action.DELETE) { + r = R.string.osn_close_dialog_error; + closeBug(bug, text); + } else if (action == Action.CREATE) { + r = R.string.osn_add_dialog_error; + openBug(bug.getLatitude(), bug.getLongitude(), text, false); + } else if (action == null) { + r = R.string.osn_modify_dialog_error; + modifyBug(point); + } else { + commentBug(bug, text); + } + Toast.makeText(activity, activity.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show(); + } + } + }; + } + private String getUserName() { return ((OsmandApplication) activity.getApplication()).getSettings().USER_NAME.get(); } @@ -503,8 +488,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } } - - @Override public PointDescription getObjectName(Object o) { if (o instanceof OpenStreetNote) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 71da65bf20..3d670818d9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -229,7 +229,7 @@ public class OsmEditingPlugin extends OsmandPlugin { editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG); } else if (resId == R.string.context_menu_item_open_note) { - openOsmNote(mapActivity, latitude, longitude); + openOsmNote(mapActivity, latitude, longitude, "", false); } else if (resId == R.string.context_menu_item_modify_note) { modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj); } else if (resId == R.string.poi_context_menu_modify) { @@ -300,13 +300,6 @@ public class OsmEditingPlugin extends OsmandPlugin { } } - public void openOsmNote(MapActivity mapActivity, double latitude, double longitude) { - if (osmBugsLayer == null) { - registerLayers(mapActivity); - } - osmBugsLayer.openBug(latitude, longitude, ""); - } - public void openOsmNote(MapActivity mapActivity, double latitude, double longitude, String message, boolean autofill) { if (osmBugsLayer == null) { registerLayers(mapActivity); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java index f809ed494e..c56a4ea1b6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java @@ -1,6 +1,7 @@ package net.osmand.plus.osmedit.dialogs; import android.content.res.ColorStateList; +import android.os.AsyncTask; import android.os.Bundle; import android.view.View; @@ -20,7 +21,9 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.osmedit.HandleOsmNoteAsyncTask; import net.osmand.plus.osmedit.OsmBugsLayer; +import net.osmand.plus.osmedit.OsmBugsUtil; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; @@ -31,14 +34,16 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { public static final String TAG = BugBottomSheetDialog.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(BugBottomSheetDialog.class); - boolean offline; + OsmBugsUtil osmBugsUtil; + OsmBugsUtil local; String text; int titleTextId; int posButtonTextId; OsmPoint.Action action; OsmBugsLayer.OpenStreetNote bug; OsmNotesPoint point; - private TextInputLayout textBox; + HandleOsmNoteAsyncTask.HandleBugListener handleBugListener; + private TextInputEditText noteText; @Override public void createMenuItems(Bundle savedInstanceState) { @@ -51,14 +56,14 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.track_name_edit_text, null); - textBox = osmNoteView.findViewById(R.id.name_text_box); + TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box); int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light; textBox.setBoxBackgroundColorResource(highlightColorId); textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat .getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)); textBox.setDefaultHintTextColor(colorStateList); - TextInputEditText noteText = osmNoteView.findViewById(R.id.name_edit_text); + noteText = osmNoteView.findViewById(R.id.name_edit_text); noteText.setText(text); BaseBottomSheetItem editOsmNote = new BaseBottomSheetItem.Builder() @@ -74,19 +79,35 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { return posButtonTextId; } - public static void showInstance(@NonNull FragmentManager fm, final boolean offline, + @Override + protected void onRightBottomButtonClick() { + new HandleOsmNoteAsyncTask(osmBugsUtil, local, bug, point, noteText.getText().toString(), action, + handleBugListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dismiss(); + } + + @Override + protected int getBgColorId() { + return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light; + } + + public static void showInstance(@NonNull FragmentManager fm, OsmBugsUtil osmBugsUtil, OsmBugsUtil local, String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action, - final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point) { + final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point, + HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) { try { if (!fm.isStateSaved()) { BugBottomSheetDialog fragment = new BugBottomSheetDialog(); - fragment.offline = offline; + fragment.setRetainInstance(true); + fragment.osmBugsUtil = osmBugsUtil; + fragment.local = local; fragment.text = text; fragment.titleTextId = titleTextId; fragment.posButtonTextId = posButtonTextId; fragment.action = action; fragment.bug = bug; fragment.point = point; + fragment.handleBugListener = handleBugListener; fragment.show(fm, TAG); } } catch (RuntimeException e) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index f5a618e5af..2f7868a8e5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -22,9 +22,11 @@ import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.util.Algorithms; +import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; + public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = "SendPoiBottomSheetFragment"; + public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName(); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; @@ -107,12 +109,11 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); - final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; + final ProgressDialogPoiUploader progressDialogPoiUploader; if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { - progressDialogPoiUploader = - new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); } else { - progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); + progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); } if (progressDialogPoiUploader != null) { String comment = messageEditText.getText().toString(); From 0aafc4ce84653a98f7c4c55a844239ae842f31ff Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 11 Nov 2020 17:27:45 +0200 Subject: [PATCH 006/122] opr login added --- .../drawable/ic_img_logo_openplacereview.xml | 36 +++++++ OsmAnd/res/drawable/ic_sample.xml | 13 +++ OsmAnd/res/layout/fragment_opr_login.xml | 92 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 5 + .../plus/mapcontextmenu/MenuBuilder.java | 97 ++++++++++++------- .../openplacereviews/OprStartFragment.java | 19 ++++ 6 files changed, 225 insertions(+), 37 deletions(-) create mode 100644 OsmAnd/res/drawable/ic_img_logo_openplacereview.xml create mode 100644 OsmAnd/res/drawable/ic_sample.xml create mode 100644 OsmAnd/res/layout/fragment_opr_login.xml create mode 100644 OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java diff --git a/OsmAnd/res/drawable/ic_img_logo_openplacereview.xml b/OsmAnd/res/drawable/ic_img_logo_openplacereview.xml new file mode 100644 index 0000000000..3ef860a90c --- /dev/null +++ b/OsmAnd/res/drawable/ic_img_logo_openplacereview.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + diff --git a/OsmAnd/res/drawable/ic_sample.xml b/OsmAnd/res/drawable/ic_sample.xml new file mode 100644 index 0000000000..9612304bcf --- /dev/null +++ b/OsmAnd/res/drawable/ic_sample.xml @@ -0,0 +1,13 @@ + + + + diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml new file mode 100644 index 0000000000..656da83538 --- /dev/null +++ b/OsmAnd/res/layout/fragment_opr_login.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index dc262a8b1b..67e7b46abf 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,11 @@ Thx - Hardy --> + I already have an account + Create new account + Photos are provided by open data project OpenPlaceReviews.org. In order to upload your photos you need to sign up on website. + Register on\nOpenPlaceReviews.org + Add photo OsmAnd Live subscription is on hold OsmAnd Live subscription has been paused OsmAnd Live subscription has been expired diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index e18beeeb01..0a3543394d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.net.Uri; @@ -21,30 +22,19 @@ import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - +import android.widget.*; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; - import net.osmand.AndroidUtils; -import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; -import net.osmand.osm.PoiCategory; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; +import net.osmand.plus.*; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; @@ -53,6 +43,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; +import net.osmand.plus.openplacereviews.OprStartFragment; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.transport.TransportStopRoute; @@ -63,13 +54,7 @@ import net.osmand.plus.widgets.tools.ClickableSpanTouchListener; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; @@ -77,7 +62,7 @@ public class MenuBuilder { public static final float SHADOW_HEIGHT_TOP_DP = 17f; public static final int TITLE_LIMIT = 60; - protected static final String[] arrowChars = new String[]{"=>"," - "}; + protected static final String[] arrowChars = new String[] {"=>", " - "}; protected MapActivity mapActivity; protected MapContextMenu mapContextMenu; @@ -254,7 +239,7 @@ public class MenuBuilder { protected boolean needBuildPlainMenuItems() { return true; } - + protected boolean needBuildCoordinatesRow() { return true; } @@ -282,7 +267,7 @@ public class MenuBuilder { protected void buildNearestWikiRow(View view) { if (processNearestWiki() && nearestWiki.size() > 0) { - buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size()+")", 0, + buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", 0, true, getCollapsableWikiView(view.getContext(), true), false, 0, false, null, false); } @@ -296,7 +281,14 @@ public class MenuBuilder { boolean needUpdateOnly = onlinePhotoCardsRow != null && onlinePhotoCardsRow.getMenuBuilder() == this; onlinePhotoCardsRow = new CardsRowBuilder(this, view, false); onlinePhotoCardsRow.build(); - CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(), this, + LinearLayout parent = new LinearLayout(view.getContext()); + parent.setLayoutParams( + new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + parent.setOrientation(LinearLayout.VERTICAL); + parent.addView(onlinePhotoCardsRow.getContentView()); + parent.addView(createAddPhotoButton(view.getContext())); + CollapsableView collapsableView = new CollapsableView(parent, this, app.getSettings().ONLINE_PHOTOS_ROW_COLLAPSED); collapsableView.setCollapseExpandListener(new CollapseExpandListener() { @Override @@ -316,15 +308,46 @@ public class MenuBuilder { } } + private View createAddPhotoButton(Context context) { + TextView b = new TextView(context); + b.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + mapActivity.getSupportFragmentManager().beginTransaction() + .add(R.id.fragmentContainer, new OprStartFragment(), "OPR_REGISTER_FRAGMENT") + .addToBackStack(null).commit(); + } + }); + b.setTypeface(FontCache.getRobotoRegular(context)); + Drawable d = ContextCompat.getDrawable(context, R.drawable.ic_sample); + b.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); + LinearLayout.LayoutParams params = new + LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + int dp16 = AndroidUtils.dpToPx(context, 16f); + int dp8 = AndroidUtils.dpToPx(context, 8f); + params.setMargins(dp16, 0, dp16, dp16); + b.setPadding(dp8, dp8, dp16, dp8); + b.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); + b.setLayoutParams(params); + b.setCompoundDrawablePadding(dp8); + b.setGravity(Gravity.CENTER_VERTICAL); + b.setTypeface(null, Typeface.BOLD); + b.setText(context.getResources().getString(R.string.shared_string_add_photo)); + b.setBackgroundResource(R.drawable.btn_border_light); + b.setTextColor(ContextCompat.getColor(context,R.color.preference_category_title)); + return b; + } + private void buildCoordinatesRow(View view) { Map locationData = PointDescription.getLocationData(mapActivity, latLon.getLatitude(), latLon.getLongitude(), true); String title = locationData.get(PointDescription.LOCATION_LIST_HEADER); locationData.remove(PointDescription.LOCATION_LIST_HEADER); CollapsableView cv = getLocationCollapsableView(locationData); buildRow(view, R.drawable.ic_action_get_my_location, null, title, 0, true, cv, false, 1, - false, null, false); + false, null, false); } - + private void startLoadingImages() { if (onlinePhotoCardsRow == null) { return; @@ -379,7 +402,7 @@ public class MenuBuilder { } } - protected void buildDescription(View view){ + protected void buildDescription(View view) { } protected void buildAfter(View view) { @@ -395,8 +418,8 @@ public class MenuBuilder { } public View buildRow(View view, int iconId, String buttonText, String text, int textColor, - boolean collapsable, final CollapsableView collapsableView, - boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) { + boolean collapsable, final CollapsableView collapsableView, + boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) { return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, text, textColor, null, collapsable, collapsableView, needLinks, textLinesLimit, isUrl, onClickListener, matchWidthDivider); } @@ -480,7 +503,7 @@ public class MenuBuilder { textPrefixView.setLayoutParams(llTextParams); textPrefixView.setTypeface(FontCache.getRobotoRegular(view.getContext())); textPrefixView.setTextSize(12); - textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark)); + textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark)); textPrefixView.setMinLines(1); textPrefixView.setMaxLines(1); textPrefixView.setText(textPrefix); @@ -526,7 +549,7 @@ public class MenuBuilder { textViewSecondary.setLayoutParams(llTextSecondaryParams); textViewSecondary.setTypeface(FontCache.getRobotoRegular(view.getContext())); textViewSecondary.setTextSize(14); - textViewSecondary.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark)); + textViewSecondary.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark)); textViewSecondary.setText(secondaryText); llText.addView(textViewSecondary); } @@ -581,7 +604,7 @@ public class MenuBuilder { } if (collapsableView.getContentView().getParent() != null) { ((ViewGroup) collapsableView.getContentView().getParent()) - .removeView(collapsableView.getContentView()); + .removeView(collapsableView.getContentView()); } baseView.addView(collapsableView.getContentView()); } @@ -682,7 +705,7 @@ public class MenuBuilder { ssb.append("UTM: "); } else if (line.getKey() == OsmAndFormatter.MGRS_FORMAT) { ssb.append("MGRS: "); - } else if (line.getKey() == OsmAndFormatter.OLC_FORMAT){ + } else if (line.getKey() == OsmAndFormatter.OLC_FORMAT) { ssb.append("OLC: "); } ssb.setSpan(new ForegroundColorSpan(app.getResources().getColor(R.color.text_color_secondary_light)), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); @@ -747,8 +770,8 @@ public class MenuBuilder { } public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl, - boolean collapsable, CollapsableView collapsableView, - OnClickListener onClickListener) { + boolean collapsable, CollapsableView collapsableView, + OnClickListener onClickListener) { plainMenuItems.add(new PlainMenuItem(iconId, null, text, needLinks, isUrl, collapsable, collapsableView, onClickListener)); } @@ -970,7 +993,7 @@ public class MenuBuilder { button.setTypeface(FontCache.getRobotoRegular(context)); int bg; if (selected) { - bg = light ? R.drawable.context_menu_controller_bg_light_selected: R.drawable.context_menu_controller_bg_dark_selected; + bg = light ? R.drawable.context_menu_controller_bg_light_selected : R.drawable.context_menu_controller_bg_dark_selected; } else if (showAll) { bg = light ? R.drawable.context_menu_controller_bg_light_show_all : R.drawable.context_menu_controller_bg_dark_show_all; } else { @@ -1027,7 +1050,7 @@ public class MenuBuilder { private List getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) { return wikiPoiFilter.searchAmenities(rect.top, rect.left, - rect.bottom, rect.right, -1, null); + rect.bottom, rect.right, -1, null); } @SuppressWarnings("unchecked") diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java new file mode 100644 index 0000000000..98d4a83815 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java @@ -0,0 +1,19 @@ +package net.osmand.plus.openplacereviews; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import net.osmand.plus.R; +import net.osmand.plus.base.BaseOsmAndFragment; + +public class OprStartFragment extends BaseOsmAndFragment { + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.fragment_opr_login, container, false); + return v; + } +} From 221d28567f84b3f496727bd65c5b90bc50c82787 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 11 Nov 2020 17:35:32 +0200 Subject: [PATCH 007/122] opr login changed --- OsmAnd/res/layout/fragment_opr_login.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml index 656da83538..8352d5444f 100644 --- a/OsmAnd/res/layout/fragment_opr_login.xml +++ b/OsmAnd/res/layout/fragment_opr_login.xml @@ -17,6 +17,7 @@ android:layout_height="match_parent" android:layout_gravity="start" android:contentDescription="@string/shared_string_back" + app:tint="@color/color_black" app:srcCompat="@drawable/ic_arrow_back"/> @@ -55,6 +56,7 @@ android:textColorLink="@color/icon_color_active_light" android:layout_marginRight="16dp" android:autoLink="all" + android:text="@string/register_on_openplacereviews_desc"/> Date: Wed, 11 Nov 2020 23:55:20 +0200 Subject: [PATCH 008/122] Refactoring Upload OSM note fragment --- OsmAnd/res/drawable/layout_bg.xml | 2 +- OsmAnd/res/layout/send_osm_note_fragment.xml | 175 +++++++++++------- OsmAnd/res/layout/send_poi_fragment.xml | 9 +- OsmAnd/res/values/strings.xml | 1 + .../LoginBottomSheetFragment.java | 5 +- .../plus/osmedit/EditPOIMenuController.java | 29 ++- .../plus/osmedit/OsmEditingFragment.java | 2 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 15 +- .../SendOsmNoteBottomSheetFragment.java | 127 ++++++++++--- .../dialogs/SendPoiBottomSheetFragment.java | 47 +++-- 10 files changed, 271 insertions(+), 141 deletions(-) diff --git a/OsmAnd/res/drawable/layout_bg.xml b/OsmAnd/res/drawable/layout_bg.xml index a784ae5701..214e67e852 100644 --- a/OsmAnd/res/drawable/layout_bg.xml +++ b/OsmAnd/res/drawable/layout_bg.xml @@ -1,6 +1,6 @@ - + diff --git a/OsmAnd/res/layout/send_osm_note_fragment.xml b/OsmAnd/res/layout/send_osm_note_fragment.xml index 4ce16dc2e8..6cc897ee89 100644 --- a/OsmAnd/res/layout/send_osm_note_fragment.xml +++ b/OsmAnd/res/layout/send_osm_note_fragment.xml @@ -2,7 +2,6 @@ @@ -12,111 +11,159 @@ android:orientation="vertical" android:paddingStart="@dimen/content_padding" android:paddingLeft="@dimen/content_padding" - android:paddingTop="@dimen/bottom_sheet_content_margin" android:paddingEnd="@dimen/content_padding" android:paddingRight="@dimen/content_padding"> - - - + osmand:typeface="@string/font_roboto_regular" /> - - + android:orientation="vertical"> - + + android:layout_marginTop="@dimen/content_padding_half" + android:minHeight="@dimen/context_menu_buttons_bottom_height"> - + - + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:paddingStart="@dimen/content_padding" + android:paddingEnd="@dimen/content_padding"> + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/send_poi_fragment.xml b/OsmAnd/res/layout/send_poi_fragment.xml index dbc4766d52..8a7809ffbd 100644 --- a/OsmAnd/res/layout/send_poi_fragment.xml +++ b/OsmAnd/res/layout/send_poi_fragment.xml @@ -41,18 +41,19 @@ android:imeOptions="actionDone" /> - + android:letterSpacing="@dimen/text_button_letter_spacing" /> @@ -62,7 +63,7 @@ android:background="?attr/dashboard_divider" /> + You can log in using the safe OAuth method or use your login and password. Comment OSM Note Close OSM Note Closed changset diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index 83e8bc1d13..acf0e4579f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -18,9 +18,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import org.apache.commons.logging.Log; @@ -29,11 +27,12 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.concurrent.ExecutionException; +import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; + public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = LoginBottomSheetFragment.class.getSimpleName(); private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class); - private static final String OSM_LOGIN_DATA = "osm_login_data"; private OsmOAuthAuthorizationAdapter authorizationAdapter; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 237a503e1a..4732b36fe1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -17,8 +17,6 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.settings.backend.OsmandSettings; @@ -48,23 +46,24 @@ public class EditPOIMenuController extends MenuController { public void buttonPressed() { MapActivity activity = getMapActivity(); if (plugin != null && activity != null) { + OsmPoint point = getOsmPoint(); OsmandApplication app = activity.getMyApplication(); OsmandSettings settings = app.getSettings(); OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); - OsmPoint point = getOsmPoint(); - if (client.isValidToken() + boolean isLogin = client.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) - && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - if (point instanceof OpenstreetmapPoint) { - SendPoiBottomSheetFragment sendPoiBottomSheetFragment = - SendPoiBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); - sendPoiBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); - } else if ( point instanceof OsmNotesPoint) { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} - } else { - LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); + && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); + + if (point instanceof OpenstreetmapPoint) { + if (isLogin) { + SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), + new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); + } else { + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); + } + } else if (point instanceof OsmNotesPoint) { + SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), + new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 3435ad1561..581e42152d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -40,7 +40,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer private static final String OSM_LOGOUT = "osm_logout"; private static final String OPEN_OSM_EDITS = "open_osm_edits"; - private static final String OSM_LOGIN_DATA = "osm_login_data"; + public static final String OSM_LOGIN_DATA = "osm_login_data"; private static final String OSM_EDITING_INFO = "osm_editing_info"; private OsmOAuthAuthorizationAdapter authorizationAdapter; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index f0abe4eb03..90ff1952b2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -43,8 +43,6 @@ import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -623,30 +621,21 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return info; } - public OsmandApplication getMyApplication() { return (OsmandApplication) getActivity().getApplication(); } - private void uploadItems(final OsmPoint[] items) { FragmentActivity activity = getActivity(); if (activity != null) { OsmandApplication app = getMyApplication(); OsmandSettings settings = app.getSettings(); - boolean isPoi = getOsmEditsByGroup(Group.POI) instanceof OpenstreetmapPoint; OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); if (authorizationAdapter.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - if (isPoi) { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); - } else { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} + SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) + .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 2f7868a8e5..69b299c28c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit.dialogs; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.View; @@ -10,26 +11,41 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.FragmentManager; +import com.google.android.material.textfield.TextInputLayout; + +import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; +import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + +import static net.osmand.plus.UiUtilities.setupDialogButton; +import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; + private boolean isLogin; protected OsmandSettings settings; @@ -48,55 +64,107 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen @Override public void createMenuItems(Bundle savedInstanceState) { - final boolean isNightMode = !getMyApplication().getSettings().isLightContent(); - final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_osm_note_fragment, null); - final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block); + isLogin = isLogin(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + OsmandApplication app = getMyApplication(); + + items.add(new TitleItem(getString(R.string.upload_osm_note))); + + final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_osm_note_fragment, null); + + TextView noteText = sendOsmNoteView.findViewById(R.id.note_text); + noteText.setText(((OsmNotesPoint) poi[0]).getText()); + TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint); + noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); + final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_container); + final LinearLayout signInView = sendOsmNoteView.findViewById(R.id.sign_in_container); final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); - settings = getMyApplication().getSettings(); + + settings = app.getSettings(); String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOpenID = settings.USER_NAME.get(); String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); - accountBlockView.setVisibility(View.VISIBLE); - uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); - uploadAnonymously.setPadding(30, 0, 0, 0); + View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button); + setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY, + R.drawable.ic_action_openstreetmap_logo); + signInButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + } + }); + View loginButton = sendOsmNoteView.findViewById(R.id.login_button); + setupButton(loginButton, R.string.use_login_password, DialogButtonType.SECONDARY, -1); + loginButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, getTargetFragment(), + usedOnMap, null); + } + }); + accountBlockView.setVisibility(!isLogin ? View.GONE : View.VISIBLE); + signInView.setVisibility(isLogin ? View.GONE : View.VISIBLE); + uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0); uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); - if (isNightMode) { - uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE); + signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE); + if (nightMode) { + uploadAnonymously.setBackgroundResource( + isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); } else { - uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + uploadAnonymously.setBackgroundResource( + isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); } - uploadAnonymously.setPadding(30, 0, 0, 0); + uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0); } }); - final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() .setCustomView(sendOsmNoteView) .create(); - items.add(titleItem); + items.add(bottomSheetItem); } - public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { - SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); - fragment.setArguments(bundle); - return fragment; + private void setupButton(View buttonView, int buttonTextId, DialogButtonType buttonType, int drawableId) { + Drawable icon = null; + if (drawableId != -1) { + icon = getMyApplication().getUIUtilities().getIcon(drawableId, R.color.popup_text_color); + } + TextView buttonText = buttonView.findViewById(R.id.button_text); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(buttonText, icon, null, null, null); + setupDialogButton(nightMode, buttonView, buttonType, buttonTextId); + } + + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, + @NonNull PoiUploaderType uploaderType) { + try { + if (!fm.isStateSaved()) { + SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } } @Override - protected UiUtilities.DialogButtonType getRightBottomButtonType() { - return (UiUtilities.DialogButtonType.PRIMARY); + protected DialogButtonType getRightBottomButtonType() { + return (DialogButtonType.PRIMARY); } @Override protected void onRightBottomButtonClick() { View view = getView(); - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); boolean hasPoiGroup = false; assert poi != null; for (OsmPoint p : poi) { @@ -136,4 +204,13 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen protected int getRightBottomButtonTextId() { return R.string.shared_string_upload; } + + private boolean isLogin() { + OsmandApplication app = getMyApplication(); + OsmandSettings settings = app.getSettings(); + OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); + return client.isValidToken() + || !Algorithms.isEmpty(settings.USER_NAME.get()) + && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index fd9655ebb8..7b20db7b66 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -9,7 +9,9 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.FragmentManager; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -21,9 +23,12 @@ import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = "SendPoiBottomSheetFragment"; + public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; @@ -45,26 +50,31 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { - final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_poi_fragment, null); + OsmandApplication app = getMyApplication(); + final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls(); + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_poi_fragment, null); final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); - settings = getMyApplication().getSettings(); + settings = app.getSettings(); String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOpenID = settings.USER_NAME.get(); String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); - closeChangset.setPadding(30, 0, 0, 0); + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isNightMode) { - closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + closeChangset.setBackgroundResource( + isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); } else { - closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + closeChangset.setBackgroundResource( + isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); } - closeChangset.setPadding(30, 0, 0, 0); + closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); } }); final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() @@ -73,14 +83,21 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } - public static SendPoiBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { - SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); - fragment.setArguments(bundle); - return fragment; + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, + @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { + try { + if (!fm.isStateSaved()) { + SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); } + } @Override protected UiUtilities.DialogButtonType getRightBottomButtonType() { From 1a9e5b13c0348f79c4232dd079055dab3c2c2504 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 12 Nov 2020 15:42:46 +0200 Subject: [PATCH 009/122] opr start page --- OsmAnd/AndroidManifest.xml | 1 + OsmAnd/build.gradle | 2 + OsmAnd/res/layout/activity_opr_webview.xml | 34 +++++++ OsmAnd/res/layout/fragment_opr_login.xml | 5 +- .../openplacereviews/OPRWebviewActivity.java | 94 +++++++++++++++++++ .../openplacereviews/OprStartFragment.java | 25 +++++ 6 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/res/layout/activity_opr_webview.xml create mode 100644 OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 54442ccbf2..85235f8647 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -66,6 +66,7 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml index 8352d5444f..5decb55147 100644 --- a/OsmAnd/res/layout/fragment_opr_login.xml +++ b/OsmAnd/res/layout/fragment_opr_login.xml @@ -8,7 +8,8 @@ + android:layout_height="56dp" + android:layout_marginTop="24dp"> findViewById(R.id.toolbar)); + if (b != null) { + String title = b.getString(KEY_TITLE, ""); + this.findViewById(R.id.toolbar_text).setText(title); + } + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.ic_arrow_back); + upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP); + getSupportActionBar().setHomeAsUpIndicator(upArrow); + webView = (WebView) findViewById(R.id.printDialogWebview); + webView.getSettings().setJavaScriptEnabled(true); + WebView.setWebContentsDebuggingEnabled(true); + if (b != null){ + if (b.getBoolean(KEY_LOGIN)){ + webView.loadUrl(loginUrl); + } + else { + webView.loadUrl(registerUrl); + } + } + } + + @Override + public boolean onSupportNavigateUp() { + onBackPressed(); + return true; + } + + public static String getPrivateKeyFromCookie() { + return returnCookieByKey("opr-token"); + } + + public static String getUsernameFromCookie() { + return returnCookieByKey("opr-nickname"); + } + + private static String returnCookieByKey(String key) { + String CookieValue = null; + CookieManager cookieManager = CookieManager.getInstance(); + String cookies = cookieManager.getCookie(cookieUrl); + if (cookies == null || cookies.isEmpty()) { + return ""; + } + String[] temp = cookies.split(";"); + for (String ar1 : temp) { + if (ar1.contains(key)) { + String[] temp1 = ar1.split("="); + CookieValue = temp1[1]; + break; + } + } + return CookieValue; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java index 98d4a83815..b4f66b1c65 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OprStartFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.openplacereviews; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -14,6 +15,30 @@ public class OprStartFragment extends BaseOsmAndFragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_opr_login, container, false); + v.findViewById(R.id.register_opr_create_account).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent i = new Intent(requireContext(),OPRWebviewActivity.class); + i.putExtra(OPRWebviewActivity.KEY_TITLE,getString(R.string.register_opr_create_new_account)); + i.putExtra(OPRWebviewActivity.KEY_LOGIN,false); + startActivity(i); + } + }); + v.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + getActivity().getSupportFragmentManager().popBackStack(); + } + }); + v.findViewById(R.id.register_opr_have_account).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent i = new Intent(requireContext(),OPRWebviewActivity.class); + i.putExtra(OPRWebviewActivity.KEY_TITLE,getString(R.string.user_login)); + i.putExtra(OPRWebviewActivity.KEY_LOGIN,true); + startActivity(i); + } + }); return v; } } From 291bed500b0a50dffa3c765d4452d212cedeb077 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 12 Nov 2020 16:43:33 +0200 Subject: [PATCH 010/122] Add OsmOAuthHelper --- .../src/net/osmand/plus/AppInitializer.java | 5 +- .../net/osmand/plus/OsmandApplication.java | 14 +++- .../net/osmand/plus/helpers/IntentHelper.java | 19 +++-- .../LoginBottomSheetFragment.java | 82 ++++++------------- .../plus/osmedit/OsmEditingFragment.java | 11 +-- .../SendOsmNoteBottomSheetFragment.java | 66 ++++++++++----- .../plus/osmedit/oauth/OsmOAuthHelper.java | 63 ++++++++++++++ 7 files changed, 167 insertions(+), 93 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 58690a9a3b..226d8b65db 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -43,6 +43,7 @@ import net.osmand.plus.liveupdates.LiveUpdatesHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; +import net.osmand.plus.osmedit.oauth.OsmOAuthHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.render.MapRenderRepositories; @@ -457,7 +458,7 @@ public class AppInitializer implements IProgress { app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class); app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); - app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class); + app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class); app.travelDbHelper = new TravelDbHelper(app); if (app.getSettings().SELECTED_TRAVEL_BOOK.get() != null) { app.travelDbHelper.initTravelBooks(); @@ -466,7 +467,7 @@ public class AppInitializer implements IProgress { app.lockHelper = startupInit(new LockHelper(app), LockHelper.class); app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class); app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class); - + app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class); initOpeningHoursParser(); } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index b57d94dc3a..e5a2fa3ca6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -43,7 +43,6 @@ import net.osmand.osm.MapPoiTypes; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.access.AccessibilityMode; -import net.osmand.plus.helpers.DayNightHelper; import net.osmand.plus.activities.ExitActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; @@ -57,13 +56,15 @@ import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadService; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.AvoidSpecificRoads; -import net.osmand.plus.helpers.enums.DrivingRegion; +import net.osmand.plus.helpers.DayNightHelper; import net.osmand.plus.helpers.LockHelper; -import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.WaypointHelper; +import net.osmand.plus.helpers.enums.DrivingRegion; +import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; +import net.osmand.plus.osmedit.oauth.OsmOAuthHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.render.RendererRegistry; @@ -154,6 +155,7 @@ public class OsmandApplication extends MultiDexApplication { SettingsHelper settingsHelper; GpxDbHelper gpxDbHelper; QuickActionRegistry quickActionRegistry; + OsmOAuthHelper osmOAuthHelper; private Resources localizedResources; @@ -368,8 +370,12 @@ public class OsmandApplication extends MultiDexApplication { return settingsHelper; } + public OsmOAuthHelper getOsmOAuthHelper() { + return osmOAuthHelper; + } + public synchronized DownloadIndexesThread getDownloadThread() { - if(downloadIndexesThread == null) { + if (downloadIndexesThread == null) { downloadIndexesThread = new DownloadIndexesThread(this); } return downloadIndexesThread; diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 9e5aaa5254..7f19cc004d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -4,6 +4,8 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import androidx.fragment.app.Fragment; + import net.osmand.AndroidNetworkUtils; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; @@ -19,7 +21,6 @@ import net.osmand.plus.activities.PluginsFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment; -import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; @@ -35,6 +36,8 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*; + public class IntentHelper { private static final Log LOG = PlatformUtil.getLog(IntentHelper.class); @@ -293,13 +296,15 @@ public class IntentHelper { if (intent != null && intent.getData() != null) { Uri uri = intent.getData(); if (uri.toString().startsWith("osmand-oauth")) { - LoginBottomSheetFragment fragment = mapActivity.getLoginBottomSheetFragment(); - if (fragment != null) { - String oauthVerifier = uri.getQueryParameter("oauth_verifier"); - fragment.authorize(oauthVerifier); - mapActivity.setIntent(null); - return true; + String oauthVerifier = uri.getQueryParameter("oauth_verifier"); + app.getOsmOAuthHelper().authorize(oauthVerifier); + for (Fragment fragment : mapActivity.getSupportFragmentManager().getFragments()) { + if (fragment instanceof OsmAuthorizationListener) { + ((OsmAuthorizationListener) fragment).authorizationCompleted(); + } } + mapActivity.setIntent(null); + return true; } } return false; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index acf0e4579f..680c0f6497 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -18,30 +18,32 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; +import net.osmand.plus.osmedit.oauth.OsmOAuthHelper; import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import org.apache.commons.logging.Log; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; +import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*; -public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { +public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment implements OsmAuthorizationListener { public static final String TAG = LoginBottomSheetFragment.class.getSimpleName(); - private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class); + private static final Log LOG = PlatformUtil.getLog(LoginBottomSheetFragment.class); - private OsmOAuthAuthorizationAdapter authorizationAdapter; + private OsmOAuthHelper osmOAuthHelper; - @Override - public void createMenuItems(Bundle savedInstanceState) { - OsmandApplication app = requiredMyApplication(); - authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); - items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create()); - } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + OsmandApplication app = requiredMyApplication(); + osmOAuthHelper = app.getOsmOAuthHelper(); + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create()); + } @Override protected int getDismissButtonTextId() { @@ -87,59 +89,29 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { protected void onThirdBottomButtonClick() { View view = getView(); if (view != null) { - authorizationAdapter.startOAuth((ViewGroup) view); + osmOAuthHelper.startOAuth((ViewGroup) view); } } - private boolean isValidToken() { - return authorizationAdapter.isValidToken(); - } - @Override protected DialogButtonType getRightBottomButtonType() { return (DialogButtonType.SECONDARY); } public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) { - if (!fragmentManager.isStateSaved()) { - LoginBottomSheetFragment fragment = new LoginBottomSheetFragment(); - fragment.setTargetFragment(targetFragment, 0); - fragment.show(fragmentManager, TAG); + try { + if (!fragmentManager.isStateSaved()) { + LoginBottomSheetFragment fragment = new LoginBottomSheetFragment(); + fragment.setTargetFragment(targetFragment, 0); + fragment.show(fragmentManager, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); } } - public void authorize(String oauthVerifier) { - if (authorizationAdapter != null) { - authorizationAdapter.authorize(oauthVerifier); - updateUserName(); - } - Fragment target = getTargetFragment(); - if (target instanceof OsmAuthorizationListener) { - ((OsmAuthorizationListener) target).authorizationCompleted(); - } + @Override + public void authorizationCompleted() { dismiss(); } - - private void updateUserName() { - OsmandApplication app = getMyApplication(); - if (app != null) { - String userName = ""; - try { - userName = authorizationAdapter.getUserName(); - } catch (InterruptedException e) { - log.error(e); - } catch (ExecutionException e) { - log.error(e); - } catch (IOException e) { - log.error(e); - } catch (XmlPullParserException e) { - log.error(e); - } - app.getSettings().USER_DISPLAY_NAME.set(userName); - } - } - - public interface OsmAuthorizationListener { - void authorizationCompleted(); - } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 581e42152d..4608d0f166 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -19,9 +19,9 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; -import net.osmand.plus.measurementtool.LoginBottomSheetFragment.OsmAuthorizationListener; import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; +import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.OnPreferenceChanged; @@ -34,7 +34,8 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; -public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, OsmAuthorizationListener { +public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, + OsmAuthorizationListener { private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class); @@ -48,7 +49,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); } @Override @@ -176,7 +177,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer settings.USER_ACCESS_TOKEN_SECRET.resetToDefault(); authorizationAdapter.resetToken(); - authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); } else { settings.USER_NAME.resetToDefault(); settings.USER_PASSWORD.resetToDefault(); @@ -195,7 +196,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer @Override public void authorizationCompleted() { - authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); updateAllSettings(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 69b299c28c..cd789a7832 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.View; +import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; @@ -28,6 +29,7 @@ import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; +import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import net.osmand.util.Algorithms; @@ -36,18 +38,23 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.UiUtilities.setupDialogButton; import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; +import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.*; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; -public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { +public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment implements ValidateOsmLoginListener, + OsmAuthorizationListener { public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; - private boolean isLogin; protected OsmandSettings settings; + private TextView accountName; + private LinearLayout accountBlockView; + private LinearLayout signInView; + private SwitchCompat uploadAnonymously; public enum PoiUploaderType { SIMPLE, @@ -64,7 +71,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen @Override public void createMenuItems(Bundle savedInstanceState) { - isLogin = isLogin(); poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); OsmandApplication app = getMyApplication(); @@ -77,23 +83,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen noteText.setText(((OsmNotesPoint) poi[0]).getText()); TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint); noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); - final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_container); - final LinearLayout signInView = sendOsmNoteView.findViewById(R.id.sign_in_container); - final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); - final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); + accountBlockView = sendOsmNoteView.findViewById(R.id.account_container); + signInView = sendOsmNoteView.findViewById(R.id.sign_in_container); + uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); + accountName = sendOsmNoteView.findViewById(R.id.user_name); settings = app.getSettings(); - String userNameOAuth = settings.USER_DISPLAY_NAME.get(); - String userNameOpenID = settings.USER_NAME.get(); - String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; - accountName.setText(userName); + updateAccountName(); View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button); setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY, R.drawable.ic_action_openstreetmap_logo); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - + OsmandApplication app = requiredMyApplication(); + app.getOsmOAuthHelper().startOAuth((ViewGroup) v); } }); View loginButton = sendOsmNoteView.findViewById(R.id.login_button); @@ -101,20 +105,18 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, getTargetFragment(), - usedOnMap, null); + OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, + SendOsmNoteBottomSheetFragment.this, usedOnMap, null); } }); - accountBlockView.setVisibility(!isLogin ? View.GONE : View.VISIBLE); - signInView.setVisibility(isLogin ? View.GONE : View.VISIBLE); + updateSignIn(uploadAnonymously.isChecked()); uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0); uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE); - signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE); + updateSignIn(isChecked); if (nightMode) { uploadAnonymously.setBackgroundResource( isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); @@ -131,6 +133,20 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen items.add(bottomSheetItem); } + private void updateAccountName() { + String userNameOAuth = settings.USER_DISPLAY_NAME.get(); + String userNameOpenID = settings.USER_NAME.get(); + String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; + accountName.setText(userName); + updateSignIn(uploadAnonymously.isChecked()); + } + + private void updateSignIn(boolean isChecked) { + boolean isLogin = isLogin(); + accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE); + signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE); + } + private void setupButton(View buttonView, int buttonTextId, DialogButtonType buttonType, int drawableId) { Drawable icon = null; if (drawableId != -1) { @@ -205,11 +221,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen return R.string.shared_string_upload; } + @Override + public void authorizationCompleted() { + updateAccountName(); + } + + @Override + public void loginValidationFinished(String warning) { + updateAccountName(); + } + private boolean isLogin() { OsmandApplication app = getMyApplication(); OsmandSettings settings = app.getSettings(); - OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); - return client.isValidToken() + OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); + return adapter.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java new file mode 100644 index 0000000000..62d8aa83fb --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java @@ -0,0 +1,63 @@ +package net.osmand.plus.osmedit.oauth; + +import android.view.ViewGroup; + +import androidx.annotation.NonNull; + +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; + +import org.apache.commons.logging.Log; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public class OsmOAuthHelper { + + private static final Log log = PlatformUtil.getLog(OsmOAuthHelper.class); + + private final OsmandApplication app; + + private final OsmOAuthAuthorizationAdapter authorizationAdapter; + + public OsmOAuthHelper(@NonNull OsmandApplication app) { + this.app = app; + authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + } + + public void startOAuth(ViewGroup view) { + authorizationAdapter.startOAuth(view); + } + + public void authorize(String oauthVerifier) { + authorizationAdapter.authorize(oauthVerifier); + updateUserName(); + } + + public OsmOAuthAuthorizationAdapter getAuthorizationAdapter() { + return authorizationAdapter; + } + + private void updateUserName() { + if (app != null) { + String userName = ""; + try { + userName = authorizationAdapter.getUserName(); + } catch (InterruptedException e) { + log.error(e); + } catch (ExecutionException e) { + log.error(e); + } catch (IOException e) { + log.error(e); + } catch (XmlPullParserException e) { + log.error(e); + } + app.getSettings().USER_DISPLAY_NAME.set(userName); + } + } + + public interface OsmAuthorizationListener { + void authorizationCompleted(); + } +} \ No newline at end of file From 3b44211bf4900f5546b9f1b983894bf51d1c688b Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 12 Nov 2020 18:35:41 +0200 Subject: [PATCH 011/122] webview closing --- .../openplacereviews/OPRWebviewActivity.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java index 180abda83d..48fc356a25 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java @@ -1,15 +1,13 @@ package net.osmand.plus.openplacereviews; -import android.content.Context; import android.graphics.PorterDuff; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.view.View; import android.webkit.CookieManager; +import android.webkit.WebResourceRequest; import android.webkit.WebView; -import android.widget.ImageView; +import android.webkit.WebViewClient; import android.widget.TextView; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; @@ -26,8 +24,10 @@ public class OPRWebviewActivity extends OsmandActionBarActivity { private static final String cookieUrl = BuildConfig.OPR_BASE_URL + "profile"; private static final String loginUrl = BuildConfig.OPR_BASE_URL + "login"; private static final String registerUrl = BuildConfig.OPR_BASE_URL + "signup"; + private static final String finishUrl = cookieUrl; public static String KEY_TITLE = "TITLE_KEY"; private final Log log = PlatformUtil.getLog(OPRWebviewActivity.class); + private boolean isRegister = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -43,13 +43,14 @@ public class OPRWebviewActivity extends OsmandActionBarActivity { upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP); getSupportActionBar().setHomeAsUpIndicator(upArrow); webView = (WebView) findViewById(R.id.printDialogWebview); + webView.setWebViewClient(new CloseOnSuccessWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); WebView.setWebContentsDebuggingEnabled(true); - if (b != null){ - if (b.getBoolean(KEY_LOGIN)){ + if (b != null) { + isRegister = b.getBoolean(KEY_LOGIN); + if (isRegister) { webView.loadUrl(loginUrl); - } - else { + } else { webView.loadUrl(registerUrl); } } @@ -87,8 +88,13 @@ public class OPRWebviewActivity extends OsmandActionBarActivity { return CookieValue; } - @Override - protected void onDestroy() { - super.onDestroy(); + public class CloseOnSuccessWebViewClient extends WebViewClient { + @Override + public void onPageFinished(WebView view, String url) { + if (url.contains(finishUrl) && !isRegister) { + finish(); + } + super.onPageFinished(view, url); + } } } \ No newline at end of file From 1472127ae2b414726be6856b1369a1f4b1a856fe Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 13 Nov 2020 10:35:20 +0200 Subject: [PATCH 012/122] Call new SendPoiBottomSheetFragment from My Places osm edits --- .../plus/osmedit/EditPOIMenuController.java | 4 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 31 ++- .../SendOsmNoteBottomSheetFragment.java | 69 ++----- .../dialogs/SendPoiBottomSheetFragment.java | 191 +++++++++++++----- 4 files changed, 182 insertions(+), 113 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 4732b36fe1..02ab1f93fd 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -57,13 +57,13 @@ public class EditPOIMenuController extends MenuController { if (point instanceof OpenstreetmapPoint) { if (isLogin) { SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), - new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); + new OsmPoint[]{getOsmPoint()}); } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); } } else if (point instanceof OsmNotesPoint) { SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), - new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); + new OsmPoint[]{getOsmPoint()}); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 90ff1952b2..5310f27b66 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -43,6 +43,8 @@ import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -625,23 +627,38 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return (OsmandApplication) getActivity().getApplication(); } - private void uploadItems(final OsmPoint[] items) { + private void uploadItems(final OsmPoint[] points) { FragmentActivity activity = getActivity(); if (activity != null) { OsmandApplication app = getMyApplication(); OsmandSettings settings = app.getSettings(); - OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); - if (authorizationAdapter.isValidToken() + OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); + boolean isLogin = authorizationAdapter.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) - && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) - .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); + && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); + if (hasPoiGroup(points)) { + if (isLogin) { + SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points); + } else { + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); + } } else { - LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); + SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points); } } } + boolean hasPoiGroup(OsmPoint[] points) { + boolean hasPoiGroup = false; + for (OsmPoint p : points) { + if (p.getGroup() == OsmPoint.Group.POI) { + hasPoiGroup = true; + break; + } + } + return hasPoiGroup; + } + public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) { ProgressDialogFragment dialog = ProgressDialogFragment.createInstance( R.string.uploading, diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index cd789a7832..12b678b10a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -6,7 +6,6 @@ import android.view.ContextThemeWrapper; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; @@ -25,7 +24,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; -import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; @@ -47,7 +45,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; - public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; protected OsmandSettings settings; @@ -56,23 +53,18 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen private LinearLayout signInView; private SwitchCompat uploadAnonymously; - public enum PoiUploaderType { - SIMPLE, - FRAGMENT - } - - protected OsmandApplication getMyApplication() { - return (OsmandApplication) getActivity().getApplication(); - } - private boolean isLoginOAuth() { - return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); } @Override public void createMenuItems(Bundle savedInstanceState) { - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + settings = app.getSettings(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); items.add(new TitleItem(getString(R.string.upload_osm_note))); @@ -87,8 +79,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen signInView = sendOsmNoteView.findViewById(R.id.sign_in_container); uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); accountName = sendOsmNoteView.findViewById(R.id.user_name); - - settings = app.getSettings(); updateAccountName(); View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button); setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY, @@ -105,8 +95,11 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, - SendOsmNoteBottomSheetFragment.this, usedOnMap, null); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, + SendOsmNoteBottomSheetFragment.this, usedOnMap, null); + } } }); updateSignIn(uploadAnonymously.isChecked()); @@ -157,14 +150,12 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen setupDialogButton(nightMode, buttonView, buttonType, buttonTextId); } - public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, - @NonNull PoiUploaderType uploaderType) { + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) { try { if (!fm.isStateSaved()) { SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); fragment.setArguments(bundle); fragment.show(fm, TAG); } @@ -180,39 +171,9 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen @Override protected void onRightBottomButtonClick() { - View view = getView(); - boolean hasPoiGroup = false; - assert poi != null; - for (OsmPoint p : poi) { - if (p.getGroup() == OsmPoint.Group.POI) { - hasPoiGroup = true; - break; - } - } - final boolean hasPOI = hasPoiGroup; - final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); - final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); - final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); - final ProgressDialogPoiUploader progressDialogPoiUploader; - if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { - progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); - } else { - progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); - } - if (progressDialogPoiUploader != null) { - String comment = messageEditText.getText().toString(); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; - } - } - } - progressDialogPoiUploader.showProgressDialog(poi, - false, - !hasPOI && uploadAnonymously.isChecked()); - } + ProgressDialogPoiUploader progressDialogPoiUploader; + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked()); dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 7b20db7b66..cdee365354 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -12,6 +12,8 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.FragmentManager; import net.osmand.PlatformUtil; +import net.osmand.osm.PoiType; +import net.osmand.osm.edit.Entity; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -25,56 +27,60 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; +import java.util.HashMap; +import java.util.Map; + +import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; + public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; - public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; - protected OsmandSettings settings; + private SwitchCompat closeChangeSet; + private EditText messageEditText; - public enum PoiUploaderType { - SIMPLE, - FRAGMENT - } - protected OsmandApplication getMyApplication() { - return (OsmandApplication) getActivity().getApplication(); - } - - private boolean isLoginOAuth() { - return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + private boolean isLoginOAuth(OsmandSettings settings) { + return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); } @Override public void createMenuItems(Bundle savedInstanceState) { OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls(); final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_poi_fragment, null); - final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); + closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); + messageEditText = sendOsmPoiView.findViewById(R.id.message_field); + String defaultChangeSet = createDefaultChangeSet(app); + messageEditText.setText(defaultChangeSet); final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); - settings = app.getSettings(); + OsmandSettings settings = app.getSettings(); String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOpenID = settings.USER_NAME.get(); - String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; + String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID; accountName.setText(userName); - closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); - closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); - closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isNightMode) { - closeChangset.setBackgroundResource( + closeChangeSet.setBackgroundResource( isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); } else { - closeChangset.setBackgroundResource( + closeChangeSet.setBackgroundResource( isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); } - closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); + closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); } }); final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() @@ -83,14 +89,12 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } - public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, - @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) { try { if (!fm.isStateSaved()) { SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); fragment.setArguments(bundle); fragment.show(fm, TAG); } @@ -106,40 +110,127 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override protected void onRightBottomButtonClick() { - View view = getView(); - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); - final SwitchCompat closeChangeSetCheckBox = - view.findViewById(R.id.close_change_set_checkbox); - final EditText messageEditText = view.findViewById(R.id.message_field); - final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); - final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; - if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { - progressDialogPoiUploader = - new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); - } else { - progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); - } - if (progressDialogPoiUploader != null) { - String comment = messageEditText.getText().toString(); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; - } + final ProgressDialogPoiUploader progressDialogPoiUploader; + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); + + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; } } - progressDialogPoiUploader.showProgressDialog(poi, - closeChangeSetCheckBox.isChecked(), - false); } - dismiss(); -} + progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false); + dismiss(); + } @Override protected int getRightBottomButtonTextId() { return R.string.shared_string_upload; } + private String createDefaultChangeSet(OsmandApplication app) { + Map allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true); + if (allTranslatedSubTypes == null) { + return ""; + } + Map addGroup = new HashMap<>(); + Map editGroup = new HashMap<>(); + Map deleteGroup = new HashMap<>(); + Map reopenGroup = new HashMap<>(); + String comment = ""; + for (OsmPoint p : poi) { + if (p.getGroup() == OsmPoint.Group.POI) { + OsmPoint.Action action = p.getAction(); + String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG); + if (type == null) { + continue; + } + PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim()); + if (localizedPoiType != null) { + type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' ')); + } + if (action == OsmPoint.Action.CREATE) { + if (!addGroup.containsKey(type)) { + addGroup.put(type, 1); + } else { + addGroup.put(type, addGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.MODIFY) { + if (!editGroup.containsKey(type)) { + editGroup.put(type, 1); + } else { + editGroup.put(type, editGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.DELETE) { + if (!deleteGroup.containsKey(type)) { + deleteGroup.put(type, 1); + } else { + deleteGroup.put(type, deleteGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.REOPEN) { + if (!reopenGroup.containsKey(type)) { + reopenGroup.put(type, 1); + } else { + reopenGroup.put(type, reopenGroup.get(type) + 1); + } + } + } + } + int modifiedItemsOutOfLimit = 0; + for (int i = 0; i < 4; i++) { + String action; + Map group; + switch (i) { + case 0: + action = getString(R.string.default_changeset_add); + group = addGroup; + break; + case 1: + action = getString(R.string.default_changeset_edit); + group = editGroup; + break; + case 2: + action = getString(R.string.default_changeset_delete); + group = deleteGroup; + break; + case 3: + action = getString(R.string.default_changeset_reopen); + group = reopenGroup; + break; + default: + action = ""; + group = new HashMap<>(); + } + + if (!group.isEmpty()) { + int pos = 0; + for (Map.Entry entry : group.entrySet()) { + String type = entry.getKey(); + int quantity = entry.getValue(); + if (comment.length() > 200) { + modifiedItemsOutOfLimit += quantity; + } else { + if (pos == 0) { + comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ") + .concat(quantity == 1 ? "" : quantity + " ").concat(type); + } else { + comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type); + } + } + pos++; + } + } + } + if (modifiedItemsOutOfLimit != 0) { + comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ") + .concat(getString(R.string.items_modified)).concat("."); + } else if (!comment.equals("")) { + comment = comment.concat("."); + } + return comment; + } } From 275cc58e8a518bd4d52d5641493ed9d04e437c13 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 13 Nov 2020 13:06:26 +0200 Subject: [PATCH 013/122] small changes --- OsmAnd/res/layout/fragment_opr_login.xml | 2 +- .../openplacereviews/OPRWebviewActivity.java | 9 ++-- .../openplacereviews/OprStartFragment.java | 43 ++++++++++++++++--- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/layout/fragment_opr_login.xml b/OsmAnd/res/layout/fragment_opr_login.xml index 5decb55147..9cfb97a1e3 100644 --- a/OsmAnd/res/layout/fragment_opr_login.xml +++ b/OsmAnd/res/layout/fragment_opr_login.xml @@ -3,6 +3,7 @@ android:background="@color/color_white" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" + android:clickable="true" android:layout_width="match_parent" android:layout_height="match_parent"> @@ -57,7 +58,6 @@ android:textColor="@color/color_black" android:textColorLink="@color/icon_color_active_light" android:layout_marginRight="16dp" - android:autoLink="all" android:text="@string/register_on_openplacereviews_desc"/> findViewById(R.id.start_opr_description).setText(ss); + v.findViewById(R.id.start_opr_description).setMovementMethod(LinkMovementMethod.getInstance()); + } + + + private class URLSpanNoUnderline extends URLSpan { + public URLSpanNoUnderline(String url) { + super(url); + } + + @Override + public void updateDrawState(TextPaint ds) { + super.updateDrawState(ds); + ds.setUnderlineText(false); + } + } + } From ce648cb1db3be649107d335ebf86f663bd9c864d Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 13 Nov 2020 13:13:38 +0200 Subject: [PATCH 014/122] style issues fix --- OsmAnd/res/layout/activity_opr_webview.xml | 1 - OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/activity_opr_webview.xml b/OsmAnd/res/layout/activity_opr_webview.xml index e337e83c41..9d3f28c67a 100644 --- a/OsmAnd/res/layout/activity_opr_webview.xml +++ b/OsmAnd/res/layout/activity_opr_webview.xml @@ -1,6 +1,5 @@ Date: Fri, 13 Nov 2020 14:03:54 +0200 Subject: [PATCH 015/122] Fix appearance --- OsmAnd/res/layout/send_gpx_fragment.xml | 19 ++++++++++++------- .../dialogs/SendGpxBottomSheetFragment.java | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/send_gpx_fragment.xml b/OsmAnd/res/layout/send_gpx_fragment.xml index 333030a190..7981ad801f 100644 --- a/OsmAnd/res/layout/send_gpx_fragment.xml +++ b/OsmAnd/res/layout/send_gpx_fragment.xml @@ -41,7 +41,9 @@ android:id="@+id/message_field" android:layout_width="match_parent" android:layout_height="wrap_content" - android:imeOptions="actionDone" /> + android:imeOptions="actionDone" + android:background = "#E5E5E5" + android:paddingTop = "@dimen/empty_state_image_margin_bottom"/> + android:text="osmand" + android:background = "#E5E5E5" + android:paddingTop = "@dimen/empty_state_image_margin_bottom"/> @@ -86,7 +90,7 @@ android:paddingBottom="@dimen/context_menu_first_line_top_margin" android:text="@string/gpx_visibility_txt" android:textColor="?android:textColorPrimary" - android:textSize="@dimen/default_desc_text_size" + android:textSize="@dimen/default_list_text_size" osmand:typeface="@string/font_roboto_regular" /> diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index c47f757a92..35c6a6ec69 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -71,6 +71,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { String fileName = gpxInfos[0].getFileName(); messageField.setText(Algorithms.getFileNameWithoutExtension(fileName)); + messageField.setSelection(messageField.getText().length()); final TextView visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name); final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description); From 2531c6110838e88952359ab2356ac2987e5b7e02 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 13 Nov 2020 14:20:08 +0200 Subject: [PATCH 016/122] Account block --- OsmAnd/res/layout/send_gpx_fragment.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/send_gpx_fragment.xml b/OsmAnd/res/layout/send_gpx_fragment.xml index 7981ad801f..c689b53086 100644 --- a/OsmAnd/res/layout/send_gpx_fragment.xml +++ b/OsmAnd/res/layout/send_gpx_fragment.xml @@ -180,7 +180,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" - android:letterSpacing="@dimen/text_button_letter_spacing" + android:letterSpacing="@dimen/description_letter_spacing" + android:lineSpacingExtra="@dimen/map_widget_text_small_bottom_margin" android:singleLine="true" android:text="@string/login_account" android:textColor="?android:textColorSecondary" @@ -191,10 +192,11 @@ android:id="@+id/user_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:letterSpacing="@dimen/description_letter_spacing" + android:letterSpacing="@dimen/text_button_letter_spacing" + android:lineSpacingExtra="5dp" android:maxLines="4" android:textColor="?android:textColorPrimary" - android:textSize="@dimen/default_list_text_size" + android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_regular" /> From 130469d8114b9aa33273522694347127baf93ced Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 13 Nov 2020 16:08:42 +0200 Subject: [PATCH 017/122] Color Material --- OsmAnd/res/layout/send_gpx_fragment.xml | 7 +++---- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/colors.xml | 2 ++ OsmAnd/res/values/styles.xml | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/send_gpx_fragment.xml b/OsmAnd/res/layout/send_gpx_fragment.xml index c689b53086..5f66120778 100644 --- a/OsmAnd/res/layout/send_gpx_fragment.xml +++ b/OsmAnd/res/layout/send_gpx_fragment.xml @@ -40,9 +40,9 @@ @@ -62,9 +62,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:imeOptions="actionDone" - android:text="osmand" - android:background = "#E5E5E5" - android:paddingTop = "@dimen/empty_state_image_margin_bottom"/> + android:background = "?attr/background_field" + android:text="osmand" /> diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 8e8c8aee32..3ef63acbbd 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -138,6 +138,7 @@ + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 1b1e9bde50..ccb1b4f54f 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -477,5 +477,7 @@ #80D28521 #80000000 #4DCCCCCC + #14000000 + #0DFFFFFF \ No newline at end of file diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index d96c5fa196..75c5530c95 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -245,6 +245,7 @@ @drawable/radio_button_center_light @style/CheckboxStyle @style/RadioButtonStyle + @color/background_field_light