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 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_NAME = "marker_name";
public static final String MARKER_COLOR_INDEX = "marker_color_index"; public static final String MARKER_COLOR_INDEX = "marker_color_index";
public static final String MARKER_VISITED_DATE = "marker_visited_date"; public static final String MARKER_VISITED_DATE = "marker_visited_date";
@ -48,12 +49,32 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo
Bundle arguments = getArguments(); Bundle arguments = getArguments();
if (arguments != null) { if (arguments != null) {
String markerName = arguments.getString(MARKER_NAME, ""); final int pos = arguments.getInt(MARKER_POSITION);
int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX, 0); String markerName = arguments.getString(MARKER_NAME);
long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE, 0); int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX);
long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE);
((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName); ((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))); ((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)); ((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)); ((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 { interface HistoryMarkerMenuFragmentListener {
void onMakeMarkerActive(int pos);
void onDeleteMarker(int pos);
} }
} }

View file

@ -32,10 +32,15 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
app = getMyApplication(); 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()); final RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final MapActivity mapActivity = (MapActivity) getActivity();
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() { adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
@ -47,10 +52,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
MapMarker marker = (MapMarker) item; MapMarker marker = (MapMarker) item;
HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex); arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate); arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
fragment.setArguments(arguments); fragment.setArguments(arguments);
fragment.setListener(createHistoryMarkerMenuListener());
fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
} }
} }
@ -62,6 +69,24 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
return recyclerView; 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 @Override
public void onDestroy() { public void onDestroy() {
app.getMapMarkersHelper().removeListener(this); app.getMapMarkersHelper().removeListener(this);