Make history marker menu work

This commit is contained in:
PavelRatushnyi 2017-09-09 16:24:55 +03:00
parent 9f3cde1b9a
commit 2bb38e3122
2 changed files with 52 additions and 5 deletions

View file

@ -23,6 +23,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo
public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment";
public static final String MARKER_POSITION = "marker_position";
public static final String MARKER_NAME = "marker_name";
public static final String MARKER_COLOR_INDEX = "marker_color_index";
public static final String MARKER_VISITED_DATE = "marker_visited_date";
@ -48,12 +49,32 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo
Bundle arguments = getArguments();
if (arguments != null) {
String markerName = arguments.getString(MARKER_NAME, "");
int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX, 0);
long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE, 0);
final int pos = arguments.getInt(MARKER_POSITION);
String markerName = arguments.getString(MARKER_NAME);
int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX);
long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE);
((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName);
((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex)));
((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(markerVisitedDate));
mainView.findViewById(R.id.make_active_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onMakeMarkerActive(pos);
}
dismiss();
}
});
mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onDeleteMarker(pos);
}
dismiss();
}
});
}
((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark));
@ -118,6 +139,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo
}
interface HistoryMarkerMenuFragmentListener {
void onMakeMarkerActive(int pos);
void onDeleteMarker(int pos);
}
}

View file

@ -32,10 +32,15 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
app = getMyApplication();
final MapActivity mapActivity = (MapActivity) getActivity();
Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
if (historyMarkerMenuFragment != null) {
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
}
final RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final MapActivity mapActivity = (MapActivity) getActivity();
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
@ -47,10 +52,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
MapMarker marker = (MapMarker) item;
HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
Bundle arguments = new Bundle();
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
fragment.setArguments(arguments);
fragment.setListener(createHistoryMarkerMenuListener());
fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
}
}
@ -62,6 +69,24 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
return recyclerView;
}
private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() {
return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() {
@Override
public void onMakeMarkerActive(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
adapter.notifyItemRemoved(pos);
}
}
@Override
public void onDeleteMarker(int pos) {
}
};
}
@Override
public void onDestroy() {
app.getMapMarkersHelper().removeListener(this);