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"> + + + + + + - + + + + + + + + android:layout_marginLeft="44dp" + android:layout_marginStart="44dp"> + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index e571d25b4a..518fc5c1ec 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; @@ -27,6 +29,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 +164,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,9 +206,26 @@ 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 + } } } + + @Override + public void onUseLocationClick() { + Toast.makeText(mapActivity, "use location", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onDoNotUseLocationClick() { + Toast.makeText(mapActivity, "do not use location", Toast.LENGTH_SHORT).show(); + } }); boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600; markersRv.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108)); @@ -211,6 +233,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/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index 0648d29be4..17bdbc117b 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,135 @@ 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); + itemHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex))); + itemHolder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder)); + itemHolder.iconDirection.setVisibility(View.GONE); + itemHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light)); + itemHolder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black)); + itemHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light)); + itemHolder.optionsBtn.setVisibility(View.GONE); + itemHolder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color)); + itemHolder.checkBox.setVisibility(View.VISIBLE); + itemHolder.checkBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onItemClick(itemHolder.itemView); + } + }); + itemHolder.checkBox.setChecked(marker.selected); - 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())); + int firstMarkerPos = locationCardDisplayed ? 1 : 0; + int lastMarkerPos = getItemCount() - 1; + + itemHolder.topDivider.setVisibility(pos == firstMarkerPos ? View.VISIBLE : View.GONE); + itemHolder.firstDescription.setVisibility((pos == firstMarkerPos || pos == lastMarkerPos) ? View.VISIBLE : View.GONE); + itemHolder.bottomShadow.setVisibility(pos == lastMarkerPos ? View.VISIBLE : View.GONE); + itemHolder.divider.setVisibility(pos == lastMarkerPos ? View.GONE : View.VISIBLE); + + if (pos == firstMarkerPos) { + itemHolder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + " • "); + } else if (pos == lastMarkerPos) { + itemHolder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + " • "); + } + + 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 +192,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter