add CoordinateInputActionsBottomSheet

This commit is contained in:
Chumva 2018-06-15 14:24:09 +03:00
parent c1bd8b66f8
commit 0c2056f7c5
3 changed files with 124 additions and 21 deletions

View file

@ -0,0 +1,75 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.view.View;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
public class CoordinateInputActionsBottomSheet extends MenuBottomSheetDialogFragment {
public final static String TAG = "CoordinateInputActionsBottomSheet";
private CoordinateInputActionsListener listener;
public void setListener(CoordinateInputActionsListener listener) {
this.listener = listener;
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
Bundle args = getArguments();
if (args == null) {
return;
}
final int position = args.getInt(CoordinateInputAdapter.ADAPTER_POSITION);
items.add(new TitleItem(getString(R.string.shared_string_actions)));
BaseBottomSheetItem editItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_type_edit))
.setTitle(getString(R.string.shared_string_edit))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.editItem(position);
dismiss();
}
})
.create();
items.add(editItem);
BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_type_delete))
.setTitle(getString(R.string.shared_string_delete))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.removeItem(position);
dismiss();
}
})
.create();
items.add(deleteItem);
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_cancel;
}
interface CoordinateInputActionsListener {
void removeItem(int position);
void editItem(int position);
}
}

View file

@ -296,6 +296,25 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
enterEditingMode(adapter.getItem(pos));
}
});
adapter.setOnActionsClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerView.ViewHolder viewHolder = recyclerView.findContainingViewHolder(v);
if (viewHolder != null) {
int pos = viewHolder.getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) {
return;
}
Bundle args = new Bundle();
args.putInt(CoordinateInputAdapter.ADAPTER_POSITION, pos);
CoordinateInputActionsBottomSheet fragment = new CoordinateInputActionsBottomSheet();
fragment.setUsedOnMap(false);
fragment.setArguments(args);
fragment.setListener(createCoordinateInputActionsListener());
fragment.show(getChildFragmentManager(), CoordinateInputActionsBottomSheet.TAG);
}
}
});
setBackgroundColor(R.id.bottom_controls_container, lightTheme
? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg);
@ -884,6 +903,22 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
};
}
private CoordinateInputActionsBottomSheet.CoordinateInputActionsListener createCoordinateInputActionsListener() {
return new CoordinateInputActionsBottomSheet.CoordinateInputActionsListener() {
@Override
public void removeItem(int position) {
adapter.removeItem(position);
}
@Override
public void editItem(int position) {
enterEditingMode(adapter.getItem(position));
}
};
}
private void changeHand() {
dismissEditingMode();
((FrameLayout) mainView.findViewById(R.id.left_container)).removeViewAt(0);

View file

@ -22,6 +22,8 @@ import java.util.List;
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
public static final String ADAPTER_POSITION = "position";
private OsmandApplication app;
private List<MapMarker> mapMarkers;
@ -31,11 +33,16 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
private boolean nightTheme;
private View.OnClickListener listener;
private View.OnClickListener actionsListener;
public void setOnClickListener(View.OnClickListener listener) {
this.listener = listener;
}
public void setOnActionsClickListener(View.OnClickListener actionsListener) {
this.actionsListener = actionsListener;
}
public CoordinateInputAdapter(OsmandApplication app, List<MapMarker> mapMarkers) {
this.app = app;
this.mapMarkers = mapMarkers;
@ -61,23 +68,12 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
holder.mainLayout.setBackgroundColor(getResolvedColor(nightTheme ? R.color.ctx_menu_bg_dark : R.color.bg_color_light));
holder.title.setTextColor(getResolvedColor(nightTheme ? R.color.ctx_menu_title_color_dark : R.color.color_black));
holder.divider.setBackgroundColor(getResolvedColor(nightTheme ? R.color.route_info_divider_dark : R.color.dashboard_divider_light));
holder.optionsBtn.setBackgroundDrawable(getRemoveBtnBgSelector());
holder.optionsBtn.setImageDrawable(getColoredIcon(R.drawable.ic_action_remove_small, R.color.icon_color));
holder.optionsBtn.setImageDrawable(getColoredIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
holder.iconReorder.setVisibility(View.GONE);
holder.numberText.setVisibility(View.VISIBLE);
holder.numberText.setText(String.valueOf(position + 1));
holder.description.setVisibility(View.GONE);
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
mapMarkers.remove(getItem(position));
notifyDataSetChanged();
}
}
});
holder.optionsBtn.setOnClickListener(actionsListener);
boolean singleItem = getItemCount() == 1;
boolean fistItem = position == 0;
@ -105,14 +101,11 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
return mapMarkers.get(position);
}
private Drawable getRemoveBtnBgSelector() {
if (nightTheme) {
return AndroidUtils.createPressedStateListDrawable(
getColoredIcon(R.drawable.marker_circle_background_dark_n_with_inset, R.color.keyboard_item_control_dark_bg),
ContextCompat.getDrawable(app, R.drawable.marker_circle_background_p_with_inset)
);
public void removeItem(int position) {
if (position != RecyclerView.NO_POSITION) {
mapMarkers.remove(getItem(position));
notifyDataSetChanged();
}
return ContextCompat.getDrawable(app, R.drawable.marker_circle_background_light_with_inset);
}
private Drawable getColoredIcon(@DrawableRes int resId, @ColorRes int colorResId) {