Merge remote-tracking branch 'origin/sasha_pasha_branch' into sasha_pasha_branch

This commit is contained in:
Alexander Sytnyk 2017-09-21 19:10:23 +03:00
commit f886b035c0
9 changed files with 225 additions and 71 deletions

View file

@ -20,40 +20,23 @@
app:contentInsetStart="54dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center_vertical">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="1"
android:gravity="center_vertical"
android:text="@string/map_markers"
android:textColor="@color/color_white"
osmand:typeface="@string/font_roboto_medium"
android:textSize="@dimen/dialog_header_text_size"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/order_by_mode_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
tools:text="Date added"
android:textColor="@color/white_80_transparent"
osmand:typeface="@string/font_roboto_medium"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
<ImageButton
android:id="@+id/options_button"
style="@style/Widget.AppCompat.ActionButton"

View file

@ -90,7 +90,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/date_added_row"
android:id="@+id/date_added_asc_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
@ -102,7 +102,7 @@
android:gravity="center_vertical">
<ImageView
android:id="@+id/date_added_icon"
android:id="@+id/date_added_asc_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
@ -110,11 +110,40 @@
tools:src="@drawable/ic_action_sort_by_date"/>
<TextView
android:id="@+id/date_added_text"
android:id="@+id/date_added_asc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/date_added"
tools:text="Date added (Ascendingly)"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:id="@+id/date_added_desc_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding"
android:gravity="center_vertical">
<ImageView
android:id="@+id/date_added_desc_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_by_date"/>
<TextView
android:id="@+id/date_added_desc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
tools:text="Date added (Descendingly)"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>

View file

@ -481,6 +481,21 @@ public class MapMarkersHelper {
}
}
public void addMarker(MapMarker marker, int position) {
if (marker != null) {
markersDbHelper.addMarker(marker);
if (marker.history) {
mapMarkersHistory.add(position, marker);
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
} else {
mapMarkers.add(position, marker);
checkAndFixActiveMarkersOrderIfNeeded();
}
addMarkerToGroup(marker);
refresh();
}
}
public void restoreMarkerFromHistory(MapMarker marker, int position) {
if (marker != null) {
markersDbHelper.restoreMapMarkerFromHistory(marker);

View file

@ -41,7 +41,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
final MapActivity mapActivity = (MapActivity) getActivity();
adapter = new MapMarkersActiveAdapter(mapActivity);
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(mapActivity, adapter));
touchHelper.attachToRecyclerView(recyclerView);
adapter.setAdapterListener(new MapMarkersActiveAdapterListener() {

View file

@ -42,7 +42,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private Snackbar snackbar;
private LockableViewPager viewPager;
private TextView orderByModeTitle;
private boolean lightTheme;
@ -100,7 +99,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
if (!lightTheme) {
toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color));
}
orderByModeTitle = toolbar.findViewById(R.id.order_by_mode_text);
setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get());
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
@ -141,7 +139,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
historyFragment.hideSnackbar();
groupsFragment.hideSnackbar();
}
orderByModeTitle.setVisibility(View.VISIBLE);
viewPager.setCurrentItem(0);
optionsButton.setVisibility(View.VISIBLE);
return true;
@ -152,7 +149,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
activeFragment.hideSnackbar();
historyFragment.hideSnackbar();
}
orderByModeTitle.setVisibility(View.GONE);
viewPager.setCurrentItem(1);
optionsButton.setVisibility(View.GONE);
return true;
@ -163,7 +159,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
groupsFragment.hideSnackbar();
activeFragment.hideSnackbar();
}
orderByModeTitle.setVisibility(View.GONE);
viewPager.setCurrentItem(2);
optionsButton.setVisibility(View.GONE);
return true;
@ -255,19 +250,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
}
private void setOrderByMode(MapMarkersOrderByMode orderByMode) {
String modeStr = "";
if (orderByMode.isDistanceDescending()) {
modeStr = getString(R.string.distance) + " (" + getString(R.string.descendingly) + ")";
} else if (orderByMode.isDistanceAscending()) {
modeStr = getString(R.string.distance) + " (" + getString(R.string.ascendingly) + ")";
} else if (orderByMode.isName()) {
modeStr = getString(R.string.shared_string_name);
} else if (orderByMode.isDateAddedDescending()) {
modeStr = getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")";
} else {
modeStr = getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")";
}
orderByModeTitle.setText(modeStr);
getMyApplication().getMapMarkersHelper().orderMarkers(orderByMode);
activeFragment.updateAdapter();
}

View file

@ -83,8 +83,9 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
boolean markerViewHolder = viewHolder instanceof MapMarkerItemViewHolder;
if (markerViewHolder) {
MapMarker marker = (MapMarker) adapter.getItem(viewHolder.getAdapterPosition());
int pos = viewHolder.getAdapterPosition();
if (markerViewHolder && pos != -1) {
MapMarker marker = (MapMarker) adapter.getItem(pos);
if (marker.history) {
return ItemTouchHelper.RIGHT;
} else {

View file

@ -58,12 +58,19 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment
ImageView nameIcon = (ImageView) mainView.findViewById(R.id.name_icon);
nameIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name));
ImageView dateAddedIcon = (ImageView) mainView.findViewById(R.id.date_added_icon);
dateAddedIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
ImageView dateAddedAscIcon = (ImageView) mainView.findViewById(R.id.date_added_asc_icon);
dateAddedAscIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
ImageView dateAddedDescIcon = (ImageView) mainView.findViewById(R.id.date_added_desc_icon);
dateAddedDescIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")");
((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")");
mainView.findViewById(R.id.distance_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.name_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.date_added_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
@ -136,21 +143,20 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment
MapMarkersOrderByMode modeToSet;
switch (view.getId()) {
case R.id.distance_row:
if (currentOrderByMode == MapMarkersOrderByMode.DISTANCE_DESC) {
modeToSet = MapMarkersOrderByMode.DISTANCE_ASC;
} else {
if (currentOrderByMode == MapMarkersOrderByMode.DISTANCE_ASC) {
modeToSet = MapMarkersOrderByMode.DISTANCE_DESC;
} else {
modeToSet = MapMarkersOrderByMode.DISTANCE_ASC;
}
break;
case R.id.name_row:
modeToSet = MapMarkersOrderByMode.NAME;
break;
case R.id.date_added_row:
if (currentOrderByMode == MapMarkersOrderByMode.DATE_ADDED_DESC) {
case R.id.date_added_asc_row:
modeToSet = MapMarkersOrderByMode.DATE_ADDED_ASC;
} else {
break;
case R.id.date_added_desc_row:
modeToSet = MapMarkersOrderByMode.DATE_ADDED_DESC;
}
break;
default:
modeToSet = currentOrderByMode;

View file

@ -4,6 +4,7 @@ import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -13,6 +14,7 @@ import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -220,6 +222,51 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
return true;
}
@Override
public void onItemSwiped(RecyclerView.ViewHolder holder, final int direction) {
final int pos = holder.getAdapterPosition();
final MapMarker marker = getItem(pos);
int snackbarStringRes;
if (direction == ItemTouchHelper.LEFT) {
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName);
if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
}
snackbarStringRes = R.string.marker_moved_to_history;
} else {
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker(marker);
snackbarStringRes = R.string.item_removed;
}
notifyItemRemoved(pos);
if (showDirectionEnabled && pos < 2 && getItemCount() > 1) {
notifyItemChanged(1);
} else if (pos == getItemCount()) {
notifyItemChanged(pos - 1);
}
snackbar = Snackbar.make(holder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (direction == ItemTouchHelper.LEFT) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
} else {
mapActivity.getMyApplication().getMapMarkersHelper().addMarker(marker, pos);
}
notifyItemInserted(pos);
if (showDirectionEnabled && pos < 2 && getItemCount() > 2) {
notifyItemChanged(2);
} else if (pos == getItemCount() - 1) {
notifyItemChanged(pos - 1);
}
}
});
View snackBarView = snackbar.getView();
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
snackbar.show();
}
@Override
public void onItemDismiss(RecyclerView.ViewHolder holder) {
listener.onDragEnded(holder);

View file

@ -1,14 +1,66 @@
package net.osmand.plus.mapmarkers.adapters;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback {
private final ItemTouchHelperAdapter adapter;
private MapActivity mapActivity;
public MapMarkersItemTouchHelperCallback(ItemTouchHelperAdapter adapter) {
private Paint backgroundPaint = new Paint();
private Paint iconPaint = new Paint();
private Paint textPaint = new Paint();
private float marginSides;
private Bitmap deleteBitmap;
private Bitmap resetBitmap;
private boolean iconHidden;
private boolean night;
private String delStr;
private String moveToHistoryStr;
private int moveToHistoryStrWidth;
private int textHeight;
public MapMarkersItemTouchHelperCallback(MapActivity mapActivity, ItemTouchHelperAdapter adapter) {
this.mapActivity = mapActivity;
this.adapter = adapter;
marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding);
deleteBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_delete_dark);
resetBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_reset_to_default_dark);
night = !mapActivity.getMyApplication().getSettings().isLightContent();
backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
backgroundPaint.setAntiAlias(true);
iconPaint.setAntiAlias(true);
iconPaint.setFilterBitmap(true);
iconPaint.setDither(true);
textPaint.setTextSize(mapActivity.getResources().getDimension(R.dimen.default_desc_text_size));
textPaint.setFakeBoldText(true);
textPaint.setAntiAlias(true);
delStr = mapActivity.getString(R.string.shared_string_delete).toUpperCase();
moveToHistoryStr = mapActivity.getString(R.string.move_to_history).toUpperCase();
Rect bounds = new Rect();
textPaint.getTextBounds(moveToHistoryStr, 0, moveToHistoryStr.length(), bounds);
moveToHistoryStrWidth = bounds.width();
textHeight = bounds.height();
}
@Override
@ -16,15 +68,11 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
return false;
}
@Override
public boolean isItemViewSwipeEnabled() {
return false;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
return makeMovementFlags(dragFlags, 0);
final int moveFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
return makeMovementFlags(dragFlags, moveFlags);
}
@Override
@ -33,13 +81,54 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
if (!iconHidden && isCurrentlyActive) {
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
iconHidden = true;
}
View itemView = viewHolder.itemView;
int colorIcon;
int colorText;
if (Math.abs(dX) > itemView.getWidth() / 2) {
colorIcon = R.color.map_widget_blue;
colorText = R.color.map_widget_blue;
} else {
colorIcon = night ? 0 : R.color.icon_color;
colorText = R.color.dashboard_subheader_text_light;
}
if (colorIcon != 0) {
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, colorIcon), PorterDuff.Mode.SRC_IN));
}
textPaint.setColor(ContextCompat.getColor(mapActivity, colorText));
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
if (dX > 0) {
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.getWidth(),
itemView.getTop() + textMarginTop + textHeight, textPaint);
} else {
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2;
c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(moveToHistoryStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - moveToHistoryStrWidth,
itemView.getTop() + textMarginTop + textHeight, textPaint);
}
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
adapter.onItemSwiped(viewHolder, i);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
iconHidden = false;
adapter.onItemDismiss(viewHolder);
}
@ -47,6 +136,8 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
boolean onItemMove(int from, int to);
void onItemSwiped(RecyclerView.ViewHolder holder, int direction);
void onItemDismiss(RecyclerView.ViewHolder holder);
}
}