From dc2233e261127c676d6d1b55cf0cd5cefb00f0ea Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 27 Sep 2017 15:13:08 +0300 Subject: [PATCH 1/3] Add UseLocationCard to markers list; add small fixes --- OsmAnd/res/layout/map_marker_item_new.xml | 16 +- OsmAnd/res/layout/use_location_card.xml | 17 +- .../plus/mapmarkers/PlanRouteFragment.java | 14 +- .../adapters/MapMarkersListAdapter.java | 199 ++++++++++-------- 4 files changed, 156 insertions(+), 90 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 98c29f7025..96c4cff626 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -7,11 +7,21 @@ android:descendantFocusability="blocksDescendants" android:orientation="vertical"> - + tools:visibility="visible"> + + + + + + - + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index e571d25b4a..c7b7b3c709 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -27,6 +27,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -161,7 +162,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene toolbarController.setOnBackButtonClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - quit(false); + if (quit(false)) { + MapMarkersDialogFragment.showInstance(mapActivity); + } } }); mapActivity.showTopToolbar(toolbarController); @@ -201,7 +204,14 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); - adapter.notifyDataSetChanged(); + mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); + mapActivity.refreshMap(); + try { + adapter.notifyDataSetChanged(); + } catch (Exception e) { + // to avoid crash because of: + // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling + } } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index 0648d29be4..8963cba67c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java @@ -22,11 +22,15 @@ import java.util.Date; import java.util.List; import java.util.Locale; -public class MapMarkersListAdapter extends RecyclerView.Adapter +public class MapMarkersListAdapter extends RecyclerView.Adapter implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { + private static final int USE_LOCATION_CARD_TYPE = 1; + private static final int MARKER_ITEM_TYPE = 2; + private MapActivity mapActivity; private List markers; + private boolean locationCardDisplayed = true; private MapMarkersListAdapterListener listener; private LatLon location; @@ -50,107 +54,121 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter 1) { - month = Character.toUpperCase(month.charAt(0)) + month.substring(1); - } - String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date); - descr = month + " " + day; - } - holder.description.setText(descr); - if (location != null) { - holder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter - ? R.color.color_distance : R.color.color_myloc_distance)); - float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(), - marker.getLatitude(), marker.getLongitude()); - holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + itemHolder.point.setVisibility(View.VISIBLE); + + itemHolder.iconReorder.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent event) { + if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { + listener.onDragStarted(itemHolder); + } + return false; + } + }); + + itemHolder.title.setText(marker.getName(mapActivity)); + + String descr; + if ((descr = marker.groupName) != null) { + if (descr.equals("")) { + descr = mapActivity.getString(R.string.shared_string_favorites); + } + } else { + Date date = new Date(marker.creationDate); + String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date); + if (month.length() > 1) { + month = Character.toUpperCase(month.charAt(0)) + month.substring(1); + } + String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date); + descr = month + " " + day; + } + itemHolder.description.setText(descr); + + if (location != null) { + itemHolder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter + ? R.color.color_distance : R.color.color_myloc_distance)); + float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(), + marker.getLatitude(), marker.getLongitude()); + itemHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + } } } @Override public int getItemCount() { - return markers.size(); + return locationCardDisplayed ? markers.size() + 1 : markers.size(); } public MapMarker getItem(int position) { - return markers.get(position); + return markers.get(locationCardDisplayed ? position - 1 : position); } @Override @@ -160,7 +178,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter Date: Wed, 27 Sep 2017 17:14:50 +0300 Subject: [PATCH 2/3] Hide quick actions button in Plan Route mode; open markers list by default; fix small bug --- .../plus/mapmarkers/PlanRouteFragment.java | 20 +++++++++++++++++++ .../MapMarkersItemTouchHelperCallback.java | 6 ++++-- .../plus/views/MapQuickActionLayer.java | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index c7b7b3c709..eb82305124 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapmarkers; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; @@ -14,6 +15,7 @@ import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -221,6 +223,24 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene markersRv.setLayoutManager(new LinearLayoutManager(getContext())); markersRv.setAdapter(adapter); + if (portrait) { + showMarkersList(); + } else { + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + showMarkersList(); + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + } + return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java index f8829b793c..32f08e9e0d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java @@ -132,8 +132,10 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback @Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); - ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE); - iconHidden = false; + if (iconHidden) { + ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE); + iconHidden = false; + } adapter.onItemDismiss(viewHolder); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index f5129c680a..f08e20539a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -41,6 +41,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe private final ContextMenuLayer contextMenuLayer; private final MeasurementToolLayer measurementToolLayer; + private final MapMarkersLayer mapMarkersLayer; private ImageView contextMarker; private final MapActivity mapActivity; private final OsmandApplication app; @@ -66,6 +67,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe settings = activity.getMyApplication().getSettings(); quickActionRegistry = activity.getMapLayers().getQuickActionRegistry(); measurementToolLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); + mapMarkersLayer = mapActivity.getMapLayers().getMapMarkersLayer(); } @@ -323,6 +325,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInGpxDetailsMode() || measurementToolLayer.isInMeasurementMode() || + mapMarkersLayer.isInPlanRouteMode() || mapActivity.getContextMenu().isVisible() && !mapActivity.getContextMenu().findMenuFragment().get().isRemoving() || mapActivity.getContextMenu().isVisible() && mapActivity.getContextMenu().findMenuFragment().get().isAdded() || mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isAdded() || From ae01e250a92ad6a3337d3995140135f86ba24c54 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 27 Sep 2017 18:07:03 +0300 Subject: [PATCH 3/3] Add on click listeners --- OsmAnd/res/layout/use_location_card.xml | 12 +++++------ .../plus/mapmarkers/PlanRouteFragment.java | 10 ++++++++++ .../adapters/MapMarkersListAdapter.java | 20 ++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/use_location_card.xml b/OsmAnd/res/layout/use_location_card.xml index 4a54f97736..2401f4df67 100644 --- a/OsmAnd/res/layout/use_location_card.xml +++ b/OsmAnd/res/layout/use_location_card.xml @@ -69,8 +69,8 @@ + android:layout_marginLeft="44dp" + android:layout_marginStart="44dp">