Add the ability to delete points from the list; add small changes

This commit is contained in:
Alexander Sytnyk 2017-08-07 13:05:11 +03:00
parent 40bfd45dd1
commit cda30a2957
3 changed files with 46 additions and 10 deletions

View file

@ -7,7 +7,6 @@ import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
@ -22,12 +21,17 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
private MapActivity mapActivity; private MapActivity mapActivity;
private List<WptPt> points; private List<WptPt> points;
private RemovePointListener listener;
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) { MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.points = points; this.points = points;
} }
public void setListener(RemovePointListener listener) {
this.listener = listener;
}
@Override @Override
public Holder onCreateViewHolder(ViewGroup viewGroup, int i) { public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false); 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() { holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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 TextView descr;
final ImageButton deleteBtn; final ImageButton deleteBtn;
public Holder(View view) { Holder(View view) {
super(view); super(view);
icon = (ImageView) view.findViewById(R.id.measure_point_icon); icon = (ImageView) view.findViewById(R.id.measure_point_icon);
title = (TextView) view.findViewById(R.id.measure_point_title); 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); deleteBtn = (ImageButton) view.findViewById(R.id.measure_point_remove_image_button);
} }
} }
interface RemovePointListener {
void onPointRemove();
}
} }

View file

@ -55,6 +55,7 @@ public class MeasurementToolFragment extends Fragment {
public static final String TAG = "MeasurementToolFragment"; public static final String TAG = "MeasurementToolFragment";
private MeasurementToolBarController toolBarController; private MeasurementToolBarController toolBarController;
private MeasurementToolAdapter adapter;
private TextView distanceTv; private TextView distanceTv;
private TextView pointsTv; private TextView pointsTv;
private String pointsSt; private String pointsSt;
@ -111,10 +112,13 @@ public class MeasurementToolFragment extends Fragment {
if (measurementLayer.undoPointOnClick()) { if (measurementLayer.undoPointOnClick()) {
enable(undoBtn); enable(undoBtn);
} else { } else {
disable(undoBtn); disable(undoBtn, upDownBtn);
downBtnOnClick(mainView, iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
} }
adapter.notifyDataSetChanged();
enable(redoBtn); enable(redoBtn);
updateText(); updateText();
mapActivity.refreshMap();
} }
}); });
@ -127,8 +131,10 @@ public class MeasurementToolFragment extends Fragment {
} else { } else {
disable(redoBtn); disable(redoBtn);
} }
enable(undoBtn); adapter.notifyDataSetChanged();
enable(undoBtn, upDownBtn);
updateText(); updateText();
mapActivity.refreshMap();
} }
}); });
@ -139,6 +145,7 @@ public class MeasurementToolFragment extends Fragment {
enable(undoBtn, upDownBtn); enable(undoBtn, upDownBtn);
disable(redoBtn); disable(redoBtn);
updateText(); updateText();
adapter.notifyDataSetChanged();
} }
}); });
@ -190,9 +197,24 @@ public class MeasurementToolFragment extends Fragment {
mapActivity.showTopToolbar(toolBarController); 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); RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getContext())); rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setAdapter(new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints())); rv.setAdapter(adapter);
return view; return view;
} }
@ -342,6 +364,7 @@ public class MeasurementToolFragment extends Fragment {
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
exitMeasurementMode(); exitMeasurementMode();
adapter.setListener(null);
} }
private MapActivity getMapActivity() { private MapActivity getMapActivity() {

View file

@ -34,7 +34,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private Bitmap centerIconNight; private Bitmap centerIconNight;
private Bitmap pointIcon; private Bitmap pointIcon;
private Paint bitmapPaint; private Paint bitmapPaint;
private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("rulerLine"); private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private Path path = new Path(); private Path path = new Path();
private int marginX; private int marginX;
private int marginY; private int marginY;
@ -70,7 +70,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return measurementPoints.size(); return measurementPoints.size();
} }
public LinkedList<WptPt> getMeasurementPoints() { LinkedList<WptPt> getMeasurementPoints() {
return measurementPoints; return measurementPoints;
} }
@ -141,6 +141,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
canvas.rotate(tb.getRotate(), center.x, center.y); canvas.rotate(tb.getRotate(), center.x, center.y);
} }
void resetCachePoints() {
cacheMeasurementPoints = new LinkedList<>(measurementPoints);
}
void addPointOnClick() { void addPointOnClick() {
RotatedTileBox tb = view.getCurrentRotatedTileBox(); RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY()); LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
@ -154,7 +158,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} else { } else {
measurementPoints.add(pt); measurementPoints.add(pt);
} }
cacheMeasurementPoints = new LinkedList<>(measurementPoints); resetCachePoints();
view.refreshMap(); view.refreshMap();
} }