Replace Use My Location card with location item

This commit is contained in:
Alexander Sytnyk 2017-09-28 14:54:20 +03:00
parent ee943cbf4f
commit 20a99ac9c6
5 changed files with 73 additions and 234 deletions

View file

@ -1,110 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="4dp"/>
<include layout="@layout/card_top_divider"/>
</LinearLayout>
<LinearLayout
android:id="@+id/background_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatImageView
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:scaleType="centerInside"
android:src="@drawable/map_pedestrian_location"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:minHeight="56dp"
android:orientation="vertical"
android:paddingBottom="12dp"
android:paddingTop="10dp">
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/my_location"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/add_location_as_first_point_descr"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="44dp"
android:layout_marginStart="44dp">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/use_location_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="@string/use_location"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/do_not_use_location_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="@string/shared_string_do_not_use"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
</LinearLayout>
</LinearLayout>
<include layout="@layout/card_bottom_divider"/>
</LinearLayout>

View file

@ -11,9 +11,6 @@
-->
<string name="fast_coordinates_input_descr">Choose oordinate format before start. YOu can always change it by tapping Options.</string>
<string name="fast_coordinates_input">Fast Coordinates input</string>
<string name="use_location">Use location</string>
<string name="add_location_as_first_point_descr">Add your location as first point to plan perfect route.</string>
<string name="my_location">My Location</string>
<string name="shared_string_finish">Finish</string>
<string name="plan_route">Plan route</string>
<string name="shared_string_sort">Sort</string>

View file

@ -225,7 +225,7 @@ public class MapMarkersHelper {
this.ctx = ctx;
settings = ctx.getSettings();
markersDbHelper = ctx.getMapMarkersDbHelper();
// startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
removeDisabledGroups();
loadMarkers();
createMapMarkersGroups();
@ -237,7 +237,7 @@ public class MapMarkersHelper {
public void setStartFromMyLocation(boolean startFromMyLocation) {
this.startFromMyLocation = startFromMyLocation;
// settings.ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
settings.ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
}
public void lookupAddressAll() {

View file

@ -196,9 +196,13 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
@Override
public void onItemClick(View view) {
int pos = markersRv.getChildAdapterPosition(view);
if (pos == 0) {
Toast.makeText(mapActivity, "location selected", Toast.LENGTH_SHORT).show();
} else {
MapMarker marker = adapter.getItem(pos);
selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;
marker.selected = !marker.selected;
}
adapter.notifyItemChanged(pos);
updateSelectButton();
showMarkersRouteOnMap();
@ -225,16 +229,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
}
}
@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));

View file

@ -22,15 +22,11 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder>
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<MapMarker> markers;
private boolean locationCardDisplayed = true;
private MapMarkersListAdapterListener listener;
private LatLon location;
@ -54,11 +50,7 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.Vie
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
if (viewType == USE_LOCATION_CARD_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.use_location_card, viewGroup, false);
return new UseLocationCardViewHolder(view);
} else if (viewType == MARKER_ITEM_TYPE) {
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
@ -67,89 +59,70 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.Vie
}
});
return new MapMarkerItemViewHolder(view);
} else {
throw new IllegalArgumentException("Unsupported view type");
}
}
@Override
public int getItemViewType(int position) {
if (locationCardDisplayed && position == 0) {
return USE_LOCATION_CARD_TYPE;
}
return MARKER_ITEM_TYPE;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int pos) {
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
MapMarker marker = pos == 0 ? null : getItem(pos);
if (holder instanceof UseLocationCardViewHolder) {
final UseLocationCardViewHolder locationCardHolder = (UseLocationCardViewHolder) holder;
locationCardHolder.useLocationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onUseLocationClick();
}
});
locationCardHolder.doNotUseLocationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onDoNotUseLocationClick();
}
});
} else if (holder instanceof MapMarkerItemViewHolder) {
MapMarker marker = getItem(pos);
final MapMarkerItemViewHolder itemHolder = (MapMarkerItemViewHolder) holder;
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);
int firstMarkerPos = locationCardDisplayed ? 1 : 0;
int firstMarkerPos = 1;
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);
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
holder.title.setText(pos == 0 ? mapActivity.getString(R.string.shared_string_my_location) : marker.getName(mapActivity));
holder.iconDirection.setVisibility(View.GONE);
holder.optionsBtn.setVisibility(View.GONE);
holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
holder.divider.setVisibility(pos == lastMarkerPos ? View.GONE : View.VISIBLE);
holder.checkBox.setVisibility(View.VISIBLE);
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(holder.itemView);
}
});
holder.bottomShadow.setVisibility(pos == lastMarkerPos ? View.VISIBLE : View.GONE);
holder.firstDescription.setVisibility((pos == firstMarkerPos || pos == lastMarkerPos) ? View.VISIBLE : View.GONE);
if (pos == firstMarkerPos) {
itemHolder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + "");
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + "");
} else if (pos == lastMarkerPos) {
itemHolder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + "");
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + "");
}
itemHolder.point.setVisibility(View.VISIBLE);
if (pos == 0) {
holder.topDivider.setVisibility(View.VISIBLE);
holder.flagIconLeftSpace.setVisibility(View.VISIBLE);
holder.icon.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.map_pedestrian_location));
holder.point.setVisibility(View.GONE);
holder.checkBox.setChecked(mapActivity.getMyApplication().getMapMarkersHelper().isStartFromMyLocation());
holder.iconReorder.setVisibility(View.GONE);
holder.description.setVisibility(View.GONE);
holder.distance.setVisibility(View.GONE);
} else {
holder.topDivider.setVisibility(View.GONE);
holder.flagIconLeftSpace.setVisibility(View.GONE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex)));
holder.point.setVisibility(View.VISIBLE);
holder.checkBox.setChecked(marker.selected);
itemHolder.iconReorder.setOnTouchListener(new View.OnTouchListener() {
holder.iconReorder.setVisibility(View.VISIBLE);
holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
listener.onDragStarted(itemHolder);
listener.onDragStarted(holder);
}
return false;
}
});
itemHolder.title.setText(marker.getName(mapActivity));
holder.description.setVisibility(View.VISIBLE);
holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
String descr;
if ((descr = marker.groupName) != null) {
if (descr.equals("")) {
@ -164,25 +137,26 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.Vie
String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
descr = month + " " + day;
}
itemHolder.description.setText(descr);
holder.description.setText(descr);
if (location != null) {
itemHolder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter
holder.distance.setVisibility(View.VISIBLE);
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());
itemHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
}
}
}
@Override
public int getItemCount() {
return locationCardDisplayed ? markers.size() + 1 : markers.size();
return markers.size() + 1;
}
public MapMarker getItem(int position) {
return markers.get(locationCardDisplayed ? position - 1 : position);
return markers.get(position - 1);
}
@Override
@ -192,10 +166,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.Vie
@Override
public boolean onItemMove(int from, int to) {
if (locationCardDisplayed && to == 0) {
if (to == 0) {
return false;
}
Collections.swap(markers, locationCardDisplayed ? from - 1 : from, locationCardDisplayed ? to - 1 : to);
Collections.swap(markers, from - 1, to - 1);
notifyItemMoved(from, to);
return true;
}
@ -217,21 +191,5 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<RecyclerView.Vie
void onDragStarted(RecyclerView.ViewHolder holder);
void onDragEnded(RecyclerView.ViewHolder holder);
void onUseLocationClick();
void onDoNotUseLocationClick();
}
private class UseLocationCardViewHolder extends RecyclerView.ViewHolder {
final View useLocationBtn;
final View doNotUseLocationBtn;
UseLocationCardViewHolder(View view) {
super(view);
useLocationBtn = view.findViewById(R.id.use_location_button);
doNotUseLocationBtn = view.findViewById(R.id.do_not_use_location_button);
}
}
}