Move newGpxData to context
This commit is contained in:
parent
d11043ea79
commit
f3319f6062
6 changed files with 55 additions and 29 deletions
|
@ -95,6 +95,7 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
|||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
||||
import net.osmand.plus.measurementtool.MeasurementEditingContext;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||
import net.osmand.plus.measurementtool.NewGpxData;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
|
@ -944,7 +945,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
NewGpxData newGpxData = (NewGpxData) toShow;
|
||||
QuadRect qr = newGpxData.getRect();
|
||||
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
|
||||
MeasurementToolFragment.showInstance(getSupportFragmentManager(), newGpxData);
|
||||
MeasurementEditingContext editingContext = new MeasurementEditingContext();
|
||||
editingContext.setNewGpxData(newGpxData);
|
||||
MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
|
||||
} else {
|
||||
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
|
||||
}
|
||||
|
|
|
@ -764,7 +764,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), null);
|
||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||
return true;
|
||||
}
|
||||
}).createItem());
|
||||
|
|
|
@ -35,6 +35,8 @@ public class MeasurementEditingContext {
|
|||
// cache should be deleted if after changed or snappedToRoadPoints
|
||||
private TrkSegment afterCacheForSnap;
|
||||
|
||||
private NewGpxData newGpxData;
|
||||
|
||||
private int selectedPointPosition = -1;
|
||||
private WptPt originalPointToMove;
|
||||
|
||||
|
@ -77,6 +79,14 @@ public class MeasurementEditingContext {
|
|||
this.inSnapToRoadMode = inSnapToRoadMode;
|
||||
}
|
||||
|
||||
public NewGpxData getNewGpxData() {
|
||||
return newGpxData;
|
||||
}
|
||||
|
||||
public void setNewGpxData(NewGpxData newGpxData) {
|
||||
this.newGpxData = newGpxData;
|
||||
}
|
||||
|
||||
public void setProgressListener(SnapToRoadProgressListener progressListener) {
|
||||
this.progressListener = progressListener;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
|||
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.NewGpxData.ActionType;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
|
@ -105,7 +106,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private boolean portrait;
|
||||
private boolean nightMode;
|
||||
private int previousMapPosition;
|
||||
private NewGpxData newGpxData;
|
||||
private boolean gpxPointsAdded;
|
||||
|
||||
private MeasurementEditingContext editingCtx = new MeasurementEditingContext();
|
||||
|
@ -115,8 +115,8 @@ public class MeasurementToolFragment extends Fragment {
|
|||
LINE
|
||||
}
|
||||
|
||||
public void setNewGpxData(NewGpxData newGpxData) {
|
||||
this.newGpxData = newGpxData;
|
||||
public void setEditingCtx(MeasurementEditingContext editingCtx) {
|
||||
this.editingCtx = editingCtx;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -156,7 +156,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
|
||||
if (selectedPointFragment != null) {
|
||||
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
|
||||
fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
|
||||
fragment.setListener(createSelectedPointFragmentListener());
|
||||
}
|
||||
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
|
||||
|
@ -207,9 +206,10 @@ public class MeasurementToolFragment extends Fragment {
|
|||
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
|
||||
|
||||
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
|
||||
if (newGpxData != null) {
|
||||
NewGpxData.ActionType actionType = newGpxData.getActionType();
|
||||
if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
|
||||
final NewGpxData newGpxData = editingCtx.getNewGpxData();
|
||||
if (editingCtx.getNewGpxData() != null) {
|
||||
ActionType actionType = newGpxData.getActionType();
|
||||
if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
|
||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
|
||||
} else {
|
||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
|
||||
|
@ -781,7 +781,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private void displayRoutePoints() {
|
||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
|
||||
GPXFile gpx = newGpxData.getGpxFile();
|
||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||
List<WptPt> points = gpx.getRoutePoints();
|
||||
if (measurementLayer != null) {
|
||||
editingCtx.addPoints(points);
|
||||
|
@ -793,7 +793,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private void displaySegmentPoints() {
|
||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
|
||||
TrkSegment segment = newGpxData.getTrkSegment();
|
||||
TrkSegment segment = editingCtx.getNewGpxData().getTrkSegment();
|
||||
List<WptPt> points = segment.points;
|
||||
if (measurementLayer != null) {
|
||||
editingCtx.addPoints(points);
|
||||
|
@ -804,7 +804,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
|
||||
private void openSelectedPointMenu(MapActivity mapActivity) {
|
||||
SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment();
|
||||
fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
|
||||
fragment.setListener(createSelectedPointFragmentListener());
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
|
@ -1049,10 +1048,10 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void addToGpx(MapActivity mapActivity) {
|
||||
GPXFile gpx = newGpxData.getGpxFile();
|
||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
||||
boolean showOnMap = selectedGpxFile != null;
|
||||
NewGpxData.ActionType actionType = newGpxData.getActionType();
|
||||
ActionType actionType = editingCtx.getNewGpxData().getActionType();
|
||||
saveExistingGpx(gpx, showOnMap, actionType, true);
|
||||
}
|
||||
|
||||
|
@ -1200,7 +1199,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
case EDIT_SEGMENT:
|
||||
TrkSegment segment = new TrkSegment();
|
||||
segment.points.addAll(points);
|
||||
gpx.replaceSegment(newGpxData.getTrkSegment(), segment);
|
||||
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -1390,8 +1389,8 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (editingCtx.isInSnapToRoadMode()) {
|
||||
disableSnapToRoadMode();
|
||||
}
|
||||
if (newGpxData != null) {
|
||||
GPXFile gpx = newGpxData.getGpxFile();
|
||||
if (editingCtx.getNewGpxData() != null) {
|
||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
|
||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
|
||||
newIntent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true);
|
||||
|
@ -1404,10 +1403,23 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager, NewGpxData newGpxData) {
|
||||
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) {
|
||||
try {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setEditingCtx(editingCtx);
|
||||
fragment.setRetainInstance(true);
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
||||
.commitAllowingStateLoss();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager) {
|
||||
try {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setNewGpxData(newGpxData);
|
||||
fragment.setRetainInstance(true);
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
||||
|
|
|
@ -185,12 +185,12 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
|
||||
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
|
||||
before.renders.clear();
|
||||
before.renders.add(new Renderable.StandardTrack(before.points, 17.2));
|
||||
before.renders.add(new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2));
|
||||
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||
|
||||
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
|
||||
after.renders.clear();
|
||||
after.renders.add(new Renderable.StandardTrack(after.points, 17.2));
|
||||
after.renders.add(new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2));
|
||||
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import net.osmand.plus.IconsCache;
|
|||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -37,16 +37,11 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
private SelectedPointFragmentListener listener;
|
||||
private boolean nightMode;
|
||||
private boolean portrait;
|
||||
private NewGpxData.ActionType actionType;
|
||||
|
||||
public void setListener(SelectedPointFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setActionType(NewGpxData.ActionType actionType) {
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -122,8 +117,14 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
if (!TextUtils.isEmpty(pointTitle)) {
|
||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle);
|
||||
} else {
|
||||
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
|
||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
||||
NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData();
|
||||
if (newGpxData != null) {
|
||||
ActionType actionType = measurementLayer.getEditingCtx().getNewGpxData().getActionType();
|
||||
if (actionType == ActionType.ADD_ROUTE_POINTS) {
|
||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
||||
} else {
|
||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||
}
|
||||
} else {
|
||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue