Merge branch 'master' into buttom-sheet-fix

# Conflicts:
#	OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java
#	OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java
This commit is contained in:
androiddevkkotlin 2020-12-06 11:06:57 +02:00
commit a7f2dd44d8
24 changed files with 691 additions and 722 deletions

View file

@ -477,7 +477,8 @@
<color name="switch_button_active_stroke_dark">#80D28521</color>
<color name="empty_hint_bg">#80000000</color>
<color name="input_layout_bg_color">#4DCCCCCC</color>
<color name="text_input_background_light">#14000000</color>
<color name="text_input_background_dark">#0DFFFFFF</color>
<color name="text_input_background_light">#4DCCCCCC</color>
<color name="text_input_background_dark">#1AFFFFFF</color>
<color name="mtrl_textinput_default_box_stroke_color">#67727272</color>
</resources>

View file

@ -11,6 +11,10 @@
Thx - Hardy
-->
<string name="plan_route_add_new_segment">Add new segment</string>
<string name="plan_route_split_after">Split after</string>
<string name="plan_route_split_before">Split before</string>
<string name="plan_route_join_segments">Join segments</string>
<string name="app_mode_light_aircraft">Light aircraft</string>
<string name="elevation_data">You can use Elevation data for consideration of Ascent / Descent for your trip</string>
<string name="ltr_or_rtl_combine_via_star">%1$s * %2$s</string>

View file

@ -94,7 +94,7 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment impl
if (!(getActivity() instanceof MapActivity) && fragment instanceof OsmAuthorizationListener) {
osmOAuthHelper.addListener((OsmAuthorizationListener) fragment);
}
osmOAuthHelper.startOAuth((ViewGroup) view);
osmOAuthHelper.startOAuth((ViewGroup) view, nightMode);
}
}

View file

@ -296,31 +296,6 @@ public class MeasurementEditingContext {
return !newData && hasDefaultPointsOnly && getPoints().size() > 2;
}
public boolean isSelectionNeedApproximation() {
boolean hasDefaultPointsOnly = false;
boolean newData = isNewData();
if (!newData && selectedPointPosition != -1) {
WptPt selectedPoint = getPoints().get(selectedPointPosition);
List<TrkSegment> segments = getBeforeSegments();
List<WptPt> points = null;
for (TrkSegment segment : segments) {
if (segment.points.contains(selectedPoint)) {
points = segment.points;
}
}
if (!Algorithms.isEmpty(points)) {
hasDefaultPointsOnly = true;
for (WptPt point : points) {
if (point.hasProfile()) {
hasDefaultPointsOnly = false;
break;
}
}
}
}
return !newData && hasDefaultPointsOnly && getPoints().size() > 2;
}
public void clearSnappedToRoadPoints() {
roadSegmentData.clear();
}
@ -430,6 +405,11 @@ public class MeasurementEditingContext {
if (position > 0 && position <= points.size()) {
WptPt prevPt = points.get(position - 1);
if (prevPt.isGap()) {
if (position == points.size() && getAfterPoints().size() == 0) {
if (appMode != MeasurementEditingContext.DEFAULT_APP_MODE) {
point.setProfileType(appMode.getStringKey());
}
} else {
point.setGap();
if (position > 1) {
WptPt pt = points.get(position - 2);
@ -439,6 +419,7 @@ public class MeasurementEditingContext {
prevPt.removeProfileType();
}
}
}
} else if (prevPt.hasProfile()) {
point.setProfileType(prevPt.getProfileType());
}
@ -540,6 +521,45 @@ public class MeasurementEditingContext {
clearAfterSegments();
}
public void splitPoints(int selectedPointPosition, boolean after) {
int pointIndex = after ? selectedPointPosition : selectedPointPosition - 1;
if (pointIndex >= 0 && pointIndex < before.points.size()) {
WptPt point = before.points.get(pointIndex);
WptPt newPoint = new WptPt();
newPoint.lat = point.lat;
newPoint.lon = point.lon;
newPoint.copyExtensions(point);
newPoint.setGap();
before.points.remove(pointIndex);
before.points.add(pointIndex, newPoint);
updateSegmentsForSnap(false);
}
}
public void joinPoints(int selectedPointPosition) {
WptPt gapPoint = null;
int gapIndex = -1;
if (isFirstPointSelected(selectedPointPosition, false)) {
if (selectedPointPosition - 1 >= 0) {
gapPoint = before.points.get(selectedPointPosition - 1);
gapIndex = selectedPointPosition - 1;
}
} else if (isLastPointSelected(selectedPointPosition, false)) {
gapPoint = before.points.get(selectedPointPosition);
gapIndex = selectedPointPosition;
}
if (gapPoint != null) {
WptPt newPoint = new WptPt();
newPoint.lat = gapPoint.lat;
newPoint.lon = gapPoint.lon;
newPoint.copyExtensions(gapPoint);
newPoint.removeProfileType();
before.points.remove(gapIndex);
before.points.add(gapIndex, newPoint);
updateSegmentsForSnap(false);
}
}
public void clearSegments() {
clearBeforeSegments();
clearAfterSegments();
@ -560,15 +580,43 @@ public class MeasurementEditingContext {
}
}
public boolean isFirstPointSelected() {
return isBorderPointSelected(true);
public boolean canSplit(boolean after) {
WptPt selectedPoint = getPoints().get(selectedPointPosition);
List<TrkSegment> segments = getBeforeSegments();
for (TrkSegment segment : segments) {
int i = segment.points.indexOf(selectedPoint);
if (i != -1) {
return after ? i < segment.points.size() - 2 : i > 1;
}
}
return false;
}
public boolean isLastPointSelected() {
return isBorderPointSelected(false);
public boolean isFirstPointSelected(boolean outer) {
return isFirstPointSelected(selectedPointPosition, outer);
}
private boolean isBorderPointSelected(boolean first) {
public boolean isFirstPointSelected(int selectedPointPosition, boolean outer) {
if (outer) {
return selectedPointPosition == 0;
} else {
return isBorderPointSelected(selectedPointPosition, true);
}
}
public boolean isLastPointSelected(boolean outer) {
return isLastPointSelected(selectedPointPosition, outer);
}
public boolean isLastPointSelected(int selectedPointPosition, boolean outer) {
if (outer) {
return selectedPointPosition == getPoints().size() - 1;
} else {
return isBorderPointSelected(selectedPointPosition, false);
}
}
private boolean isBorderPointSelected(int selectedPointPosition, boolean first) {
WptPt selectedPoint = getPoints().get(selectedPointPosition);
List<TrkSegment> segments = getBeforeSegments();
int count = 0;

View file

@ -64,10 +64,12 @@ import net.osmand.plus.measurementtool.command.ApplyGpxApproximationCommand;
import net.osmand.plus.measurementtool.command.ChangeRouteModeCommand;
import net.osmand.plus.measurementtool.command.ChangeRouteModeCommand.ChangeRouteType;
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
import net.osmand.plus.measurementtool.command.JoinPointsCommand;
import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
import net.osmand.plus.measurementtool.command.SplitPointsCommand;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
@ -76,8 +78,8 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
import net.osmand.plus.widgets.MultiStateToggleButton;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import net.osmand.util.Algorithms;
@ -1012,6 +1014,39 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
trimRoute(AFTER);
}
@Override
public void onSplitPointsAfter() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new SplitPointsCommand(measurementLayer, true));
collapseInfoViewIfExpanded();
editingCtx.setSelectedPointPosition(-1);
updateUndoRedoButton(false, redoBtn);
updateUndoRedoButton(true, undoBtn);
updateDistancePointsText();
}
@Override
public void onSplitPointsBefore() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new SplitPointsCommand(measurementLayer, false));
collapseInfoViewIfExpanded();
editingCtx.setSelectedPointPosition(-1);
updateUndoRedoButton(false, redoBtn);
updateUndoRedoButton(true, undoBtn);
updateDistancePointsText();
}
@Override
public void onJoinPoints() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new JoinPointsCommand(measurementLayer));
collapseInfoViewIfExpanded();
editingCtx.setSelectedPointPosition(-1);
updateUndoRedoButton(false, redoBtn);
updateUndoRedoButton(true, undoBtn);
updateDistancePointsText();
}
private void trimRoute(ClearCommandMode before) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, before));

View file

@ -328,7 +328,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
hasPointsBefore = true;
WptPt pt = segment.points.get(segment.points.size() - 1);
hasGapBefore = pt.isGap();
if (!pt.isGap() || !editingCtx.isInAddPointBeforeMode()) {
if (!pt.isGap() || (editingCtx.isInAddPointMode() && !editingCtx.isInAddPointBeforeMode())) {
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
tx.add(locX);
@ -345,7 +345,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
tx.add((float) tb.getCenterPixelX());
ty.add((float) tb.getCenterPixelY());
}
if (!hasGapBefore || editingCtx.isInAddPointBeforeMode()) {
if (!hasGapBefore || (editingCtx.isInAddPointMode() && editingCtx.isInAddPointBeforeMode())) {
WptPt pt = segment.points.get(0);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);

View file

@ -133,7 +133,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
dismiss();
}
})
.setDisabled(editingCtx.isFirstPointSelected())
.setDisabled(editingCtx.isFirstPointSelected(false))
.create();
items.add(trimRouteBefore);
@ -152,10 +152,93 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
dismiss();
}
})
.setDisabled(editingCtx.isLastPointSelected())
.setDisabled(editingCtx.isLastPointSelected(false))
.create();
items.add(trimRouteAfter);
if (editingCtx.isFirstPointSelected(true)) {
// skip
} else if (editingCtx.isLastPointSelected(true)) {
items.add(new OptionsDividerItem(getContext()));
// new segment
BaseBottomSheetItem addNewSegment = new BottomSheetItemWithDescription.Builder()
//.setIcon(getContentIcon(R.drawable.ic_action_trim_right))
.setTitle(getString(R.string.plan_route_add_new_segment))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof SelectedPointFragmentListener) {
((SelectedPointFragmentListener) targetFragment).onSplitPointsAfter();
}
dismiss();
}
})
.create();
items.add(addNewSegment);
} else if (editingCtx.isFirstPointSelected(false) || editingCtx.isLastPointSelected(false)) {
items.add(new OptionsDividerItem(getContext()));
// join
BaseBottomSheetItem joinSegments = new BottomSheetItemWithDescription.Builder()
//.setIcon(getContentIcon(R.drawable.ic_action_trim_right))
.setTitle(getString(R.string.plan_route_join_segments))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof SelectedPointFragmentListener) {
((SelectedPointFragmentListener) targetFragment).onJoinPoints();
}
dismiss();
}
})
.create();
items.add(joinSegments);
} else {
items.add(new OptionsDividerItem(getContext()));
// split
BaseBottomSheetItem splitAfter = new BottomSheetItemWithDescription.Builder()
//.setIcon(getContentIcon(R.drawable.ic_action_trim_right))
.setTitle(getString(R.string.plan_route_split_after))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof SelectedPointFragmentListener) {
((SelectedPointFragmentListener) targetFragment).onSplitPointsAfter();
}
dismiss();
}
})
.setDisabled(!editingCtx.canSplit(true))
.create();
items.add(splitAfter);
BaseBottomSheetItem splitBefore = new BottomSheetItemWithDescription.Builder()
//.setIcon(getContentIcon(R.drawable.ic_action_trim_right))
.setTitle(getString(R.string.plan_route_split_before))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof SelectedPointFragmentListener) {
((SelectedPointFragmentListener) targetFragment).onSplitPointsBefore();
}
dismiss();
}
})
.setDisabled(!editingCtx.canSplit(false))
.create();
items.add(splitBefore);
}
items.add(new OptionsDividerItem(getContext()));
BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescription.Builder()
@ -172,7 +255,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
dismiss();
}
})
.setDisabled(editingCtx.isFirstPointSelected() || editingCtx.isSelectionNeedApproximation())
.setDisabled(editingCtx.isFirstPointSelected(false) || editingCtx.isApproximationNeeded())
.create();
items.add(changeRouteTypeBefore);
@ -190,7 +273,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
dismiss();
}
})
.setDisabled(editingCtx.isLastPointSelected() || editingCtx.isSelectionNeedApproximation())
.setDisabled(editingCtx.isLastPointSelected(false) || editingCtx.isApproximationNeeded())
.create();
items.add(changeRouteTypeAfter);
@ -352,6 +435,12 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
void onTrimRouteAfter();
void onSplitPointsAfter();
void onSplitPointsBefore();
void onJoinPoints();
void onChangeRouteTypeBefore();
void onChangeRouteTypeAfter();

View file

@ -0,0 +1,58 @@
package net.osmand.plus.measurementtool.command;
import android.util.Pair;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementEditingContext.RoadSegmentData;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class JoinPointsCommand extends MeasurementModeCommand {
private List<WptPt> points;
private Map<Pair<WptPt, WptPt>, RoadSegmentData> roadSegmentData;
private int pointPosition;
public JoinPointsCommand(MeasurementToolLayer measurementLayer) {
super(measurementLayer);
}
@Override
public boolean execute() {
pointPosition = getEditingCtx().getSelectedPointPosition();
executeCommand();
return true;
}
private void executeCommand() {
MeasurementEditingContext ctx = getEditingCtx();
List<WptPt> pts = ctx.getPoints();
points = new ArrayList<>(pts);
roadSegmentData = ctx.getRoadSegmentData();
ctx.joinPoints(pointPosition);
refreshMap();
}
@Override
public void undo() {
MeasurementEditingContext ctx = getEditingCtx();
ctx.clearSegments();
ctx.setRoadSegmentData(roadSegmentData);
ctx.addPoints(points);
refreshMap();
}
@Override
public void redo() {
executeCommand();
}
@Override
public MeasurementCommandType getType() {
return MeasurementCommandType.JOIN_POINTS;
}
}

View file

@ -41,6 +41,8 @@ public abstract class MeasurementModeCommand implements Command {
SNAP_TO_ROAD,
CHANGE_ROUTE_MODE,
APPROXIMATE_POINTS,
REVERSE_POINTS
REVERSE_POINTS,
SPLIT_POINTS,
JOIN_POINTS
}
}

View file

@ -0,0 +1,60 @@
package net.osmand.plus.measurementtool.command;
import android.util.Pair;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementEditingContext.RoadSegmentData;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SplitPointsCommand extends MeasurementModeCommand {
private boolean after;
private List<WptPt> points;
private Map<Pair<WptPt, WptPt>, RoadSegmentData> roadSegmentData;
private int pointPosition;
public SplitPointsCommand(MeasurementToolLayer measurementLayer, boolean after) {
super(measurementLayer);
this.after = after;
}
@Override
public boolean execute() {
pointPosition = getEditingCtx().getSelectedPointPosition();
executeCommand();
return true;
}
private void executeCommand() {
MeasurementEditingContext ctx = getEditingCtx();
List<WptPt> pts = ctx.getPoints();
points = new ArrayList<>(pts);
roadSegmentData = ctx.getRoadSegmentData();
ctx.splitPoints(pointPosition, after);
refreshMap();
}
@Override
public void undo() {
MeasurementEditingContext ctx = getEditingCtx();
ctx.clearSegments();
ctx.setRoadSegmentData(roadSegmentData);
ctx.addPoints(points);
refreshMap();
}
@Override
public void redo() {
executeCommand();
}
@Override
public MeasurementCommandType getType() {
return MeasurementCommandType.SPLIT_POINTS;
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.osmedit;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -12,8 +11,6 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -22,19 +19,23 @@ import net.osmand.plus.dashboard.DashBaseFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
/**
* Created by Denis
* on 20.01.2015.
*/
public class DashOsmEditsFragment extends DashBaseFragment
implements SendPoiDialogFragment.ProgressDialogPoiUploader {
implements ProgressDialogPoiUploader, OsmAuthorizationListener {
public static final String TAG = "DASH_OSM_EDITS_FRAGMENT";
public static final int TITLE_ID = R.string.osm_settings;
@ -51,6 +52,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
new DashFragmentData(TAG, DashOsmEditsFragment.class, SHOULD_SHOW_FUNCTION, 130, ROW_NUMBER_TAG);
OsmEditingPlugin plugin;
private OsmPoint selectedPoint;
@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -72,7 +74,6 @@ public class DashOsmEditsFragment extends DashBaseFragment
return view;
}
@Override
public void onOpenDash() {
if (plugin == null) {
@ -114,10 +115,15 @@ public class DashOsmEditsFragment extends DashBaseFragment
@Override
public void onClick(View v) {
if (point.getGroup() == OsmPoint.Group.POI) {
SendPoiDialogFragment.createInstance(new OsmPoint[] {point}, PoiUploaderType.FRAGMENT)
.show(getChildFragmentManager(), "SendPoiDialogFragment");
selectedPoint = point;
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{point});
} else {
uploadItem(point);
LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(),
DashOsmEditsFragment.this);
}
} else {
SendOsmNoteBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{point});
}
}
});
@ -141,18 +147,9 @@ public class DashOsmEditsFragment extends DashBaseFragment
}
}
// TODO: 9/7/15 Redesign osm notes.
private void uploadItem(final OsmPoint point) {
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setMessage(getString(R.string.local_osm_changes_upload_all_confirm, 1));
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showProgressDialog(new OsmPoint[] {point}, false, false);
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
public void authorizationCompleted() {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{selectedPoint});
}
@Override
@ -215,5 +212,4 @@ public class DashOsmEditsFragment extends DashBaseFragment
}
}
}
}

View file

@ -35,11 +35,11 @@ public class HandleOsmNoteAsyncTask extends AsyncTask<Void, Void, OsmBugResult>
@Override
protected 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);
OsmNotesPoint point = new OsmNotesPoint();
point.setId(bug.getId());
point.setLatitude(bug.getLatitude());
point.setLongitude(bug.getLongitude());
return osmbugsUtil.commit(point, text, action);
} else if (point != null) {
osmbugsUtil = local;
return osmbugsUtil.modify(point, text);

View file

@ -1,19 +1,14 @@
package net.osmand.plus.osmedit;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.data.LatLon;
@ -25,6 +20,7 @@ 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.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -32,7 +28,6 @@ import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
@ -362,43 +357,18 @@ 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) {
@SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
final Action action, final OpenStreetNote bug, OsmNotesPoint point) {
if (offline) {
activity.getContextMenu().close();
BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text,
titleTextId, posButtonTextId, action, bug, point, getHandleBugListener());
return;
} else {
((EditText) view.findViewById(R.id.user_name_field)).setText(getUserName());
((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);
}
view.findViewById(R.id.message_field).requestFocus();
AndroidUtils.softKeyboardDelayed(activity, view.findViewById(R.id.message_field));
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.shared_string_commit);
builder.setView(view);
builder.setPositiveButton(posButtonTextId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String text = offline ? getMessageText(view) : getTextAndUpdateUserPwd(view);
activity.getContextMenu().close();
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()));
OsmNotesPoint notesPoint = new OsmNotesPoint();
notesPoint.setAction(action);
notesPoint.setId(bug.getId());
notesPoint.setLatitude(bug.getLatitude());
notesPoint.setLongitude(bug.getLongitude());
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), new OsmPoint[]{notesPoint});
}
}
@ -453,19 +423,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
};
}
private String getUserName() {
return ((OsmandApplication) activity.getApplication()).getSettings().USER_NAME.get();
}
private String getTextAndUpdateUserPwd(final View view) {
String text = getMessageText(view);
String author = ((EditText) view.findViewById(R.id.user_name_field)).getText().toString();
String pwd = ((EditText) view.findViewById(R.id.password_field)).getText().toString();
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_NAME.set(author);
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_PASSWORD.set(pwd);
return text;
}
private String getMessageText(final View view) {
return ((EditText) view.findViewById(R.id.message_field)).getText().toString();
}

View file

@ -58,10 +58,9 @@ import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmen
import net.osmand.plus.osmedit.OpenstreetmapLocalUtil.OnNodeCommittedListener;
import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener;
import net.osmand.plus.osmedit.OsmPoint.Group;
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
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.util.Algorithms;
@ -633,14 +632,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial
private void uploadItems(final OsmPoint[] points) {
FragmentActivity activity = getActivity();
if (activity != null) {
OsmandApplication app = getMyApplication();
OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
boolean isLogged = authorizationAdapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
if (hasPoiGroup(points)) {
if (isLogged) {
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), points);
} else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);

View file

@ -28,10 +28,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -74,13 +72,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
OsmPoint point = loadErrorsMap.keySet().iterator().next();
String message = loadErrorsMap.get(point);
if (message.equals(activity.getString(R.string.auth_failed))) {
SendPoiDialogFragment dialogFragment;
if (activity instanceof MapActivity) {
dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.SIMPLE);
} else {
dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.FRAGMENT);
}
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
} else {
DialogFragment dialogFragment =
UploadingErrorDialogFragment.getInstance(message, point);

View file

@ -65,8 +65,6 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
R.layout.open_osm_note_text, null);
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
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));
@ -116,11 +114,6 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
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,

View file

@ -0,0 +1,7 @@
package net.osmand.plus.osmedit.dialogs;
import net.osmand.plus.osmedit.OsmPoint;
public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously);
}

View file

@ -1,17 +1,14 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.Activity;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -31,6 +28,7 @@ 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.DashOsmEditsFragment;
import net.osmand.plus.osmedit.OsmNotesPoint;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
@ -45,9 +43,7 @@ import static net.osmand.plus.UiUtilities.setupDialogButton;
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener;
import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
import static net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment.OPENSTREETMAP_POINT;
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment implements ValidateOsmLoginListener,
OsmAuthorizationListener {
@ -62,10 +58,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
private LinearLayout signInView;
private SwitchCompat uploadAnonymously;
private OsmandApplication app;
private int contentHeightPrevious = 0;
private int buttonsHeight;
private int shadowHeight;
private ScrollView scrollView;
private EditText noteText;
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
@ -84,9 +77,8 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_osm_note_fragment, null);
sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
EditText noteText = sendOsmNoteView.findViewById(R.id.note_text);
noteText = sendOsmNoteView.findViewById(R.id.note_text);
noteText.setText(((OsmNotesPoint) poi[0]).getText());
noteText.setSelection(noteText.getText().length());
TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint);
@ -106,7 +98,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
if (fragment instanceof OsmAuthorizationListener) {
app.getOsmOAuthHelper().addListener((OsmAuthorizationListener) fragment);
}
app.getOsmOAuthHelper().startOAuth((ViewGroup) v);
app.getOsmOAuthHelper().startOAuth((ViewGroup) getView(), nightMode);
}
});
View loginButton = sendOsmNoteView.findViewById(R.id.login_button);
@ -156,28 +148,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
items.add(bottomSheetItem);
}
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
showTopShadow = viewHeight + shadowHeight < contentHeight;
scrollView.requestLayout();
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
}
}
};
}
private void updateAccountName() {
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
@ -226,11 +196,16 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
ProgressDialogPoiUploader progressDialogPoiUploader = null;
Activity activity = getActivity();
if (activity instanceof MapActivity) {
if (getParentFragment() instanceof DashOsmEditsFragment) {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
} else {
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity);
}
} else if (getParentFragment() instanceof ProgressDialogPoiUploader) {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
}
if (progressDialogPoiUploader != null) {
((OsmNotesPoint) poi[0]).setText(noteText.getText().toString());
progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked());
}
dismiss();

View file

@ -1,15 +1,12 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -37,19 +34,13 @@ import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
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";
private OsmPoint[] poi;
private int contentHeightPrevious = 0;
private int buttonsHeight;
private int shadowHeight;
private ScrollView scrollView;
private SwitchCompat closeChangeSet;
private EditText messageEditText;
@ -69,7 +60,6 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_poi_fragment, null);
sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
String defaultChangeSet = createDefaultChangeSet(app);
@ -114,28 +104,6 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
items.add(titleItem);
}
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
showTopShadow = viewHeight + shadowHeight < contentHeight;
scrollView.requestLayout();
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
}
}
};
}
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
try {
if (!fm.isStateSaved()) {

View file

@ -1,280 +0,0 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.DialogFragment;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmEditsUploadListener;
import net.osmand.plus.osmedit.OsmEditsUploadListenerHelper;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.UploadOpenstreetmapPointAsyncTask;
import net.osmand.util.Algorithms;
import java.util.HashMap;
import java.util.Map;
public class SendPoiDialogFragment extends DialogFragment {
public static final String TAG = "SendPoiDialogFragment";
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
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
final PoiUploaderType poiUploaderType = PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, PoiUploaderType.SIMPLE.name()));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
final EditText userNameEditText = (EditText) view.findViewById(R.id.user_name_field);
final EditText passwordEditText = (EditText) view.findViewById(R.id.password_field);
final View messageLabel = view.findViewById(R.id.message_label);
final View userNameLabel = view.findViewById(R.id.osm_user_name_label);
final View passwordLabel = view.findViewById(R.id.osm_user_password_label);
final CheckBox closeChangeSetCheckBox =
(CheckBox) view.findViewById(R.id.close_change_set_checkbox);
final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication())
.getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
boolean hasPoiGroup = false;
assert poi != null;
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
hasPoiGroup = true;
break;
}
}
String defaultChangeSet = createDefaultChangeSet();
messageEditText.setText(defaultChangeSet);
final boolean hasPOI = hasPoiGroup;
messageLabel.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
messageEditText.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.isEmpty());
view.findViewById(R.id.osm_note_header).setVisibility(hasPOI ? View.GONE : View.VISIBLE);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
userNameLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
userNameEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
}
});
final ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
progressDialogPoiUploader =
new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
} else {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
}
builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note)
.setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (progressDialogPoiUploader != null) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
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(),
!hasPOI && uploadAnonymously.isChecked());
}
}
})
.setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
public static SendPoiDialogFragment createInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) {
SendPoiDialogFragment fragment = new SendPoiDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points);
bundle.putString(POI_UPLOADER_TYPE, uploaderType.name());
fragment.setArguments(bundle);
return fragment;
}
private String createDefaultChangeSet() {
Map<String, PoiType> allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true);
if (allTranslatedSubTypes == null) {
return "";
}
Map<String, Integer> addGroup = new HashMap<>();
Map<String, Integer> editGroup = new HashMap<>();
Map<String, Integer> deleteGroup = new HashMap<>();
Map<String, Integer> 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<String, Integer> 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<String, Integer> 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.isEmpty()){
comment = comment.concat(".");
}
return comment;
}
public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously);
}
public static class SimpleProgressDialogPoiUploader implements ProgressDialogPoiUploader {
private MapActivity mapActivity;
public SimpleProgressDialogPoiUploader(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,
R.string.local_openstreetmap_uploading,
ProgressDialog.STYLE_HORIZONTAL);
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity,
mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
mapActivity.getContextMenu().close();
OsmBugsLayer l = mapActivity.getMapView().getLayerByClass(OsmBugsLayer.class);
if(l != null) {
l.clearCache();
mapActivity.refreshMap();
}
}
};
dialog.show(mapActivity.getSupportFragmentManager(), ProgressDialogFragment.TAG);
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points);
}
}
}

View file

@ -0,0 +1,52 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmEditsUploadListener;
import net.osmand.plus.osmedit.OsmEditsUploadListenerHelper;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.UploadOpenstreetmapPointAsyncTask;
import java.util.Map;
public class SimpleProgressDialogPoiUploader implements ProgressDialogPoiUploader {
private MapActivity mapActivity;
public SimpleProgressDialogPoiUploader(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,
R.string.local_openstreetmap_uploading,
ProgressDialog.STYLE_HORIZONTAL);
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity,
mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
mapActivity.getContextMenu().close();
OsmBugsLayer l = mapActivity.getMapView().getLayerByClass(OsmBugsLayer.class);
if (l != null) {
l.clearCache();
mapActivity.refreshMap();
}
}
};
dialog.show(mapActivity.getSupportFragmentManager(), ProgressDialogFragment.TAG);
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points);
}
}

View file

@ -1,12 +1,19 @@
package net.osmand.plus.osmedit.oauth;
import android.content.Context;
import android.content.Intent;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import com.github.scribejava.core.builder.api.DefaultApi10a;
import com.github.scribejava.core.model.OAuth1AccessToken;
@ -20,6 +27,7 @@ import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
@ -79,8 +87,8 @@ public class OsmOAuthAuthorizationAdapter {
}
}
public void startOAuth(final ViewGroup rootLayout) {
new StartOAuthAsyncTask(rootLayout).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
public void startOAuth(final ViewGroup rootLayout, boolean nightMode) {
new StartOAuthAsyncTask(rootLayout, nightMode).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
private void saveToken() {
@ -89,11 +97,10 @@ public class OsmOAuthAuthorizationAdapter {
app.getSettings().USER_ACCESS_TOKEN_SECRET.set(accessToken.getTokenSecret());
}
private void loadWebView(ViewGroup root, String url) {
WebView webView = new WebView(root.getContext());
webView.requestFocus(View.FOCUS_DOWN);
webView.loadUrl(url);
root.addView(webView);
private void loadWebView(ViewGroup root, boolean nightMode, String url) {
Uri uri = Uri.parse(url);
Context context = root.getContext();
WikipediaDialogFragment.showFullArticle(context, uri, nightMode);
}
public void performGetRequest(String url, OAuthAsyncRequestCallback<Response> callback) {
@ -117,9 +124,11 @@ public class OsmOAuthAuthorizationAdapter {
private class StartOAuthAsyncTask extends AsyncTask<Void, Void, OAuth1RequestToken> {
private final ViewGroup rootLayout;
boolean nightMode;
public StartOAuthAsyncTask(ViewGroup rootLayout) {
public StartOAuthAsyncTask(ViewGroup rootLayout, boolean nightMode) {
this.rootLayout = rootLayout;
this.nightMode = nightMode;
}
@Override
@ -129,7 +138,7 @@ public class OsmOAuthAuthorizationAdapter {
@Override
protected void onPostExecute(@NonNull OAuth1RequestToken requestToken) {
loadWebView(rootLayout, client.getService().getAuthorizationUrl(requestToken));
loadWebView(rootLayout, nightMode, client.getService().getAuthorizationUrl(requestToken));
}
}

View file

@ -28,9 +28,8 @@ public class OsmOAuthHelper {
listeners.add(listener);
}
public OsmOAuthAuthorizationAdapter updateAdapter(){
public void updateAdapter() {
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
return authorizationAdapter;
}
public void removeListener(OsmAuthorizationListener listener) {
@ -41,8 +40,8 @@ public class OsmOAuthHelper {
return authorizationAdapter;
}
public void startOAuth(@NonNull ViewGroup view) {
authorizationAdapter.startOAuth(view);
public void startOAuth(@NonNull ViewGroup view, boolean nightMode) {
authorizationAdapter.startOAuth(view, nightMode);
}
public void authorize(@NonNull String oauthVerifier) {
@ -76,6 +75,10 @@ public class OsmOAuthHelper {
return authorizationAdapter.isValidToken();
}
public boolean isLogged() {
return isValidToken() || isLoginExists();
}
public interface OsmAuthorizationListener {
void authorizationCompleted();
}

View file

@ -703,9 +703,16 @@ public class ContextMenuLayer extends OsmandMapLayer {
RenderingContext rc = maps.getVisibleRenderingContext();
RenderedObject[] renderedObjects = null;
if (rc != null && rc.zoom == tileBox.getZoom()) {
double sinRotate = Math.sin(Math.toRadians(rc.rotate - tileBox.getRotate()));
double cosRotate = Math.cos(Math.toRadians(rc.rotate - tileBox.getRotate()));
float x = tileBox.getPixXFrom31((int) (rc.leftX * rc.tileDivisor), (int) (rc.topY * rc.tileDivisor));
float y = tileBox.getPixYFrom31((int) (rc.leftX * rc.tileDivisor), (int) (rc.topY * rc.tileDivisor));
renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, (int) (point.x - x), (int) (point.y - y));
float dx = point.x - x;
float dy = point.y - y;
int coordX = (int) (dx * cosRotate - dy * sinRotate);
int coordY = (int) (dy * cosRotate + dx * sinRotate);
renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, coordX, coordY);
}
if (renderedObjects != null) {
int TILE_SIZE = 256;