From b813ba4df4e6bae42a249d948158ac0413d49bf9 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 26 Sep 2017 17:35:39 +0300 Subject: [PATCH] Add functionality to select/deselect all button --- .../src/net/osmand/plus/MapMarkersHelper.java | 8 +++++- .../plus/mapmarkers/PlanRouteFragment.java | 25 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index beb2735516..09fef6e6c1 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -551,12 +551,18 @@ public class MapMarkersHelper { return mapMarkersHistory; } - public void clearSelections() { + public void deselectAllActiveMarkers() { for (MapMarker m : mapMarkers) { m.selected = false; } } + public void selectAllActiveMarkers() { + for (MapMarker m : mapMarkers) { + m.selected = true; + } + } + public List getSelectedMarkers() { List list = new ArrayList<>(); for (MapMarker m : this.mapMarkers) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 68fcd37313..64d08cc370 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -50,6 +50,7 @@ public class PlanRouteFragment extends Fragment { private PlanRouteToolbarController toolbarController; private ApplicationMode appMode; private int previousMapPosition; + private int selectedCount = 0; private boolean nightMode; private boolean portrait; @@ -120,7 +121,16 @@ public class PlanRouteFragment extends Fragment { mainView.findViewById(R.id.select_all_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Toast.makeText(mapActivity, "Select all", Toast.LENGTH_SHORT).show(); + int activeMarkersCount = markersHelper.getMapMarkers().size(); + if (selectedCount == activeMarkersCount) { + markersHelper.deselectAllActiveMarkers(); + selectedCount = 0; + } else { + markersHelper.selectAllActiveMarkers(); + selectedCount = activeMarkersCount; + } + adapter.notifyDataSetChanged(); + updateSelectButton(); } }); @@ -167,8 +177,10 @@ public class PlanRouteFragment extends Fragment { public void onItemClick(View view) { int pos = markersRv.getChildAdapterPosition(view); MapMarker marker = adapter.getItem(pos); + selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1; marker.selected = !marker.selected; adapter.notifyItemChanged(pos); + updateSelectButton(); } @Override @@ -270,6 +282,7 @@ public class PlanRouteFragment extends Fragment { mapActivity.refreshMap(); updateText(); + updateSelectButton(); } } @@ -329,6 +342,14 @@ public class PlanRouteFragment extends Fragment { timeTv.setText("~ 45 min."); } + private void updateSelectButton() { + if (selectedCount == markersHelper.getMapMarkers().size()) { + ((TextView) mainView.findViewById(R.id.select_all_button)).setText(getString(R.string.shared_string_deselect_all)); + } else { + ((TextView) mainView.findViewById(R.id.select_all_button)).setText(getString(R.string.shared_string_select_all)); + } + } + private void mark(int status, int... widgets) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -427,7 +448,7 @@ public class PlanRouteFragment extends Fragment { if (markersListOpened) { hideMarkersList(); } - markersHelper.clearSelections(); + markersHelper.deselectAllActiveMarkers(); activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); }