Select item on check box click; move map to item on item click
This commit is contained in:
parent
2c978ca55e
commit
493547edc1
5 changed files with 69 additions and 16 deletions
|
@ -149,17 +149,23 @@
|
|||
tools:background="@drawable/marker_circle_background_dark_with_inset"
|
||||
tools:src="@drawable/ic_action_marker_passed"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/map_marker_check_box"
|
||||
<FrameLayout
|
||||
android:id="@+id/check_box_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@null"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/map_marker_check_box"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
|
|
|
@ -41,6 +41,7 @@ public class MarkersPlanRouteContext {
|
|||
private boolean progressBarVisible;
|
||||
private boolean fragmentVisible;
|
||||
private boolean markersListOpened;
|
||||
private boolean adjustMapOnStart = true;
|
||||
|
||||
Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
|
||||
return snappedToRoadPoints;
|
||||
|
@ -90,6 +91,14 @@ public class MarkersPlanRouteContext {
|
|||
this.markersListOpened = markersListOpened;
|
||||
}
|
||||
|
||||
public boolean isAdjustMapOnStart() {
|
||||
return adjustMapOnStart;
|
||||
}
|
||||
|
||||
public void setAdjustMapOnStart(boolean adjustMapOnStart) {
|
||||
this.adjustMapOnStart = adjustMapOnStart;
|
||||
}
|
||||
|
||||
public MarkersPlanRouteContext(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
|
||||
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
|
||||
|
||||
public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
|
||||
|
||||
|
@ -268,7 +269,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
private int toPosition;
|
||||
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
public void onCheckBoxClick(View view) {
|
||||
int pos = markersRv.getChildAdapterPosition(view);
|
||||
if (pos == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
|
@ -288,6 +289,22 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
planRouteContext.recreateSnapTrkSegment(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(View v) {
|
||||
int pos = markersRv.getChildAdapterPosition(v);
|
||||
if (pos == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
Object item = adapter.getItem(pos);
|
||||
if (item instanceof Location) {
|
||||
Location loc = (Location) item;
|
||||
moveMapToPosition(loc.getLatitude(), loc.getLongitude());
|
||||
} else if (item instanceof MapMarker) {
|
||||
MapMarker marker = (MapMarker) item;
|
||||
moveMapToPosition(marker.getLatitude(), marker.getLongitude());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragStarted(RecyclerView.ViewHolder holder) {
|
||||
fromPosition = holder.getAdapterPosition();
|
||||
|
@ -398,6 +415,18 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
|
||||
}
|
||||
|
||||
private void moveMapToPosition(double lat, double lon) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
OsmandMapTileView view = mapActivity.getMapView();
|
||||
view.getAnimatedDraggingThread().startMoving(lat, lon, view.getZoom(), true);
|
||||
if (planRouteContext.isMarkersListOpened()) {
|
||||
planRouteContext.setAdjustMapOnStart(false);
|
||||
showHideMarkersList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SnapToRoadFragmentListener createSnapToRoadFragmentListener() {
|
||||
return new SnapToRoadFragmentListener() {
|
||||
@Override
|
||||
|
@ -581,12 +610,11 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
|
||||
OsmandMapTileView tileView = mapActivity.getMapView();
|
||||
previousMapPosition = tileView.getMapPosition();
|
||||
if (!portrait) {
|
||||
tileView.setMapPosition(LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
|
||||
}
|
||||
tileView.setMapPosition(portrait ? MIDDLE_TOP_CONSTANT : LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
|
||||
|
||||
selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount();
|
||||
planRouteContext.recreateSnapTrkSegment(true);
|
||||
planRouteContext.recreateSnapTrkSegment(planRouteContext.isAdjustMapOnStart());
|
||||
planRouteContext.setAdjustMapOnStart(true);
|
||||
mapActivity.refreshMap();
|
||||
updateSelectButton();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
final View rightPointSpace;
|
||||
final TextView description;
|
||||
public final ImageButton optionsBtn;
|
||||
final View checkBoxContainer;
|
||||
final CheckBox checkBox;
|
||||
final View divider;
|
||||
final View bottomShadow;
|
||||
|
@ -45,6 +46,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
rightPointSpace = view.findViewById(R.id.map_marker_right_point_space);
|
||||
description = (TextView) view.findViewById(R.id.map_marker_description);
|
||||
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
|
||||
checkBoxContainer = view.findViewById(R.id.check_box_container);
|
||||
checkBox = (CheckBox) view.findViewById(R.id.map_marker_check_box);
|
||||
divider = view.findViewById(R.id.divider);
|
||||
bottomShadow = view.findViewById(R.id.bottom_shadow);
|
||||
|
|
|
@ -106,7 +106,13 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
|
|||
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
listener.onItemClick(holder.itemView);
|
||||
listener.onCheckBoxClick(holder.itemView);
|
||||
}
|
||||
});
|
||||
holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
holder.checkBox.performClick();
|
||||
}
|
||||
});
|
||||
holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
|
||||
|
@ -339,6 +345,8 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
|
|||
|
||||
public interface MapMarkersListAdapterListener {
|
||||
|
||||
void onCheckBoxClick(View view);
|
||||
|
||||
void onItemClick(View view);
|
||||
|
||||
void onDragStarted(RecyclerView.ViewHolder holder);
|
||||
|
|
Loading…
Reference in a new issue