Add the ability to delete points from the list; add small changes
This commit is contained in:
parent
40bfd45dd1
commit
cda30a2957
3 changed files with 46 additions and 10 deletions
|
@ -7,7 +7,6 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.IconsCache;
|
||||
|
@ -22,12 +21,17 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
|
|||
|
||||
private MapActivity mapActivity;
|
||||
private List<WptPt> points;
|
||||
private RemovePointListener listener;
|
||||
|
||||
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) {
|
||||
MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) {
|
||||
this.mapActivity = mapActivity;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public void setListener(RemovePointListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false);
|
||||
|
@ -53,7 +57,8 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
|
|||
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(mapActivity, "Remove: " + holder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
|
||||
points.remove(holder.getAdapterPosition());
|
||||
listener.onPointRemove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -70,7 +75,7 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
|
|||
final TextView descr;
|
||||
final ImageButton deleteBtn;
|
||||
|
||||
public Holder(View view) {
|
||||
Holder(View view) {
|
||||
super(view);
|
||||
icon = (ImageView) view.findViewById(R.id.measure_point_icon);
|
||||
title = (TextView) view.findViewById(R.id.measure_point_title);
|
||||
|
@ -78,4 +83,8 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
|
|||
deleteBtn = (ImageButton) view.findViewById(R.id.measure_point_remove_image_button);
|
||||
}
|
||||
}
|
||||
|
||||
interface RemovePointListener {
|
||||
void onPointRemove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
public static final String TAG = "MeasurementToolFragment";
|
||||
|
||||
private MeasurementToolBarController toolBarController;
|
||||
private MeasurementToolAdapter adapter;
|
||||
private TextView distanceTv;
|
||||
private TextView pointsTv;
|
||||
private String pointsSt;
|
||||
|
@ -111,10 +112,13 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (measurementLayer.undoPointOnClick()) {
|
||||
enable(undoBtn);
|
||||
} else {
|
||||
disable(undoBtn);
|
||||
disable(undoBtn, upDownBtn);
|
||||
downBtnOnClick(mainView, iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
enable(redoBtn);
|
||||
updateText();
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -127,8 +131,10 @@ public class MeasurementToolFragment extends Fragment {
|
|||
} else {
|
||||
disable(redoBtn);
|
||||
}
|
||||
enable(undoBtn);
|
||||
adapter.notifyDataSetChanged();
|
||||
enable(undoBtn, upDownBtn);
|
||||
updateText();
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -139,6 +145,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
enable(undoBtn, upDownBtn);
|
||||
disable(redoBtn);
|
||||
updateText();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -190,9 +197,24 @@ public class MeasurementToolFragment extends Fragment {
|
|||
mapActivity.showTopToolbar(toolBarController);
|
||||
}
|
||||
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
||||
adapter.setListener(new MeasurementToolAdapter.RemovePointListener() {
|
||||
@Override
|
||||
public void onPointRemove() {
|
||||
adapter.notifyDataSetChanged();
|
||||
measurementLayer.resetCachePoints();
|
||||
disable(redoBtn);
|
||||
updateText();
|
||||
mapActivity.refreshMap();
|
||||
if (measurementLayer.getPointsCount() < 1) {
|
||||
downBtnOnClick(mainView, iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
|
||||
disable(upDownBtn, undoBtn);
|
||||
}
|
||||
}
|
||||
});
|
||||
RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view);
|
||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rv.setAdapter(new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints()));
|
||||
rv.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -342,6 +364,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
exitMeasurementMode();
|
||||
adapter.setListener(null);
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
private Bitmap centerIconNight;
|
||||
private Bitmap pointIcon;
|
||||
private Paint bitmapPaint;
|
||||
private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("rulerLine");
|
||||
private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
|
||||
private Path path = new Path();
|
||||
private int marginX;
|
||||
private int marginY;
|
||||
|
@ -70,7 +70,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
return measurementPoints.size();
|
||||
}
|
||||
|
||||
public LinkedList<WptPt> getMeasurementPoints() {
|
||||
LinkedList<WptPt> getMeasurementPoints() {
|
||||
return measurementPoints;
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||
}
|
||||
|
||||
void resetCachePoints() {
|
||||
cacheMeasurementPoints = new LinkedList<>(measurementPoints);
|
||||
}
|
||||
|
||||
void addPointOnClick() {
|
||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
|
@ -154,7 +158,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
} else {
|
||||
measurementPoints.add(pt);
|
||||
}
|
||||
cacheMeasurementPoints = new LinkedList<>(measurementPoints);
|
||||
resetCachePoints();
|
||||
view.refreshMap();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue