From 0dcb35b8d37f5586d9c77816213fc5c2fc7c7dc4 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 1 Sep 2017 17:07:52 +0300 Subject: [PATCH] Add possibility to move marker to history; add small changes --- OsmAnd/res/layout/map_marker_item_new.xml | 8 ++++---- .../plus/mapmarkers/MapMarkersActiveFragment.java | 6 ++++++ .../plus/mapmarkers/MapMarkersDialogFragment.java | 6 ++++++ .../plus/mapmarkers/MapMarkersHistoryFragment.java | 11 ++++++++++- .../mapmarkers/adapters/MapMarkerItemViewHolder.java | 4 ++-- .../mapmarkers/adapters/MapMarkersActiveAdapter.java | 12 ++++++++++++ .../adapters/MapMarkersHistoryAdapter.java | 2 -- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 036c88f58e..7ae162e70d 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -102,12 +102,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" - android:layout_marginBottom="16dp" - android:layout_marginLeft="14dp" - android:layout_marginRight="14dp" - android:layout_marginTop="16dp" android:background="?attr/selectableItemBackground" android:focusableInTouchMode="true" + android:paddingBottom="16dp" + android:paddingLeft="14dp" + android:paddingRight="14dp" + android:paddingTop="16dp" tools:src="@drawable/ic_overflow_menu_white"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index e6cb7502e1..3b2fb3d96d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -121,6 +121,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL return null; } + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } + private void updateLocationUi() { final MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 0bdc11b5fb..99c05a9550 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -78,11 +78,17 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm switch (menuItem.getItemId()) { case R.id.action_active: ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); + if (viewPager.getCurrentItem() != 0) { + ((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter(); + } viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); return true; case R.id.action_history: ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); + if (viewPager.getCurrentItem() != 1) { + ((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter(); + } viewPager.setCurrentItem(1); optionsButton.setVisibility(View.GONE); return true; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index b84d42ba86..cb81e08396 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -14,6 +14,8 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; public class MapMarkersHistoryFragment extends Fragment { + MapMarkersHistoryAdapter adapter; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -21,8 +23,15 @@ public class MapMarkersHistoryFragment extends Fragment { recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final MapActivity mapActivity = (MapActivity) getActivity(); - recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication())); + adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); + recyclerView.setAdapter(adapter); return recyclerView; } + + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 8775a599f9..d3042e2090 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -17,7 +17,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { final TextView distance; final TextView point; final TextView description; - final ImageButton options; + final ImageButton optionsBtn; public MapMarkerItemViewHolder(View view) { super(view); @@ -28,6 +28,6 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { distance = (TextView) view.findViewById(R.id.map_marker_distance); point = (TextView) view.findViewById(R.id.map_marker_point_text_view); description = (TextView) view.findViewById(R.id.map_marker_description); - options = (ImageButton) view.findViewById(R.id.map_marker_options_button); + optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 8888476f7f..bf8e7d3f76 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -89,6 +89,18 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter