Hide sort by and move to history in options menu
This commit is contained in:
parent
0eb9eed459
commit
1c755ce65a
3 changed files with 65 additions and 30 deletions
|
@ -200,6 +200,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/move_all_to_history_divider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/measurement_tool_bottom_divider_margin_bottom"
|
||||
|
|
|
@ -39,6 +39,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
|
||||
public static final String TAG = "MapMarkersDialogFragment";
|
||||
|
||||
private static final int ACTIVE_MARKERS_POSITION = 0;
|
||||
private static final int GROUPS_POSITION = 1;
|
||||
private static final int HISTORY_MARKERS_POSITION = 2;
|
||||
|
||||
private MapMarkersActiveFragment activeFragment;
|
||||
private MapMarkersGroupsFragment groupsFragment;
|
||||
private MapMarkersHistoryFragment historyFragment;
|
||||
|
@ -121,6 +125,11 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
public void onClick(View view) {
|
||||
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
|
||||
fragment.setListener(createOptionsFragmentListener());
|
||||
Bundle args = new Bundle();
|
||||
int pos = viewPager.getCurrentItem();
|
||||
args.putBoolean(OptionsBottomSheetDialogFragment.SHOW_SORT_BY_ROW, pos == ACTIVE_MARKERS_POSITION);
|
||||
args.putBoolean(OptionsBottomSheetDialogFragment.SHOW_MOVE_ALL_TO_HISTORY_ROW, pos != HISTORY_MARKERS_POSITION);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(getChildFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
});
|
||||
|
@ -142,35 +151,35 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
case R.id.action_active:
|
||||
activeFragment.startLocationUpdate();
|
||||
groupsFragment.stopLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 0) {
|
||||
if (viewPager.getCurrentItem() != ACTIVE_MARKERS_POSITION) {
|
||||
hideSnackbar();
|
||||
activeFragment.updateAdapter();
|
||||
historyFragment.hideSnackbar();
|
||||
groupsFragment.hideSnackbar();
|
||||
}
|
||||
viewPager.setCurrentItem(0);
|
||||
viewPager.setCurrentItem(ACTIVE_MARKERS_POSITION);
|
||||
return true;
|
||||
case R.id.action_groups:
|
||||
activeFragment.stopLocationUpdate();
|
||||
groupsFragment.startLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 1) {
|
||||
if (viewPager.getCurrentItem() != GROUPS_POSITION) {
|
||||
hideSnackbar();
|
||||
groupsFragment.updateAdapter();
|
||||
activeFragment.hideSnackbar();
|
||||
historyFragment.hideSnackbar();
|
||||
}
|
||||
viewPager.setCurrentItem(1);
|
||||
viewPager.setCurrentItem(GROUPS_POSITION);
|
||||
return true;
|
||||
case R.id.action_history:
|
||||
activeFragment.stopLocationUpdate();
|
||||
groupsFragment.stopLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 2) {
|
||||
if (viewPager.getCurrentItem() != HISTORY_MARKERS_POSITION) {
|
||||
hideSnackbar();
|
||||
historyFragment.updateAdapter();
|
||||
groupsFragment.hideSnackbar();
|
||||
activeFragment.hideSnackbar();
|
||||
}
|
||||
viewPager.setCurrentItem(2);
|
||||
viewPager.setCurrentItem(HISTORY_MARKERS_POSITION);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -245,17 +254,21 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers());
|
||||
helper.moveAllActiveMarkersToHistory();
|
||||
activeFragment.updateAdapter();
|
||||
groupsFragment.updateAdapter();
|
||||
historyFragment.updateAdapter();
|
||||
if (viewPager.getCurrentItem() == ACTIVE_MARKERS_POSITION) {
|
||||
activeFragment.updateAdapter();
|
||||
} else {
|
||||
groupsFragment.updateAdapter();
|
||||
}
|
||||
snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
helper.restoreMarkersFromHistory(markers);
|
||||
activeFragment.updateAdapter();
|
||||
groupsFragment.updateAdapter();
|
||||
historyFragment.updateAdapter();
|
||||
if (viewPager.getCurrentItem() == ACTIVE_MARKERS_POSITION) {
|
||||
activeFragment.updateAdapter();
|
||||
} else {
|
||||
groupsFragment.updateAdapter();
|
||||
}
|
||||
}
|
||||
});
|
||||
View snackBarView = snackbar.getView();
|
||||
|
@ -323,8 +336,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
if (orderByMode != MapMarkersOrderByMode.CUSTOM) {
|
||||
getMyApplication().getMapMarkersHelper().orderMarkers(orderByMode);
|
||||
activeFragment.updateAdapter();
|
||||
groupsFragment.updateAdapter();
|
||||
historyFragment.updateAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,26 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public final static String TAG = "OptionsBottomSheetDialogFragment";
|
||||
public final static String SHOW_SORT_BY_ROW = "show_sort_by_row";
|
||||
public final static String SHOW_MOVE_ALL_TO_HISTORY_ROW = "show_move_to_history_row";
|
||||
|
||||
private MarkerOptionsFragmentListener listener;
|
||||
private boolean portrait;
|
||||
private boolean showSortBy;
|
||||
private boolean showMoveAllToHistory;
|
||||
|
||||
public void setListener(MarkerOptionsFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = getArguments();
|
||||
showSortBy = args.getBoolean(SHOW_SORT_BY_ROW, true);
|
||||
showMoveAllToHistory = args.getBoolean(SHOW_MOVE_ALL_TO_HISTORY_ROW, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -76,15 +88,20 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setTextColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.color_dialog_buttons_dark : R.color.map_widget_blue_pressed));
|
||||
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity()));
|
||||
|
||||
mainView.findViewById(R.id.sort_by_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.sortByOnClick();
|
||||
View sortByRow = mainView.findViewById(R.id.sort_by_row);
|
||||
if (!showSortBy) {
|
||||
sortByRow.setVisibility(View.GONE);
|
||||
} else {
|
||||
sortByRow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.sortByOnClick();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
mainView.findViewById(R.id.show_direction_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -121,15 +138,21 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
dismiss();
|
||||
}
|
||||
});
|
||||
mainView.findViewById(R.id.move_all_to_history_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.moveAllToHistoryOnClick();
|
||||
View moveAllToHistoryRow = mainView.findViewById(R.id.move_all_to_history_row);
|
||||
if (!showMoveAllToHistory) {
|
||||
mainView.findViewById(R.id.move_all_to_history_divider).setVisibility(View.GONE);
|
||||
moveAllToHistoryRow.setVisibility(View.GONE);
|
||||
} else {
|
||||
moveAllToHistoryRow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.moveAllToHistoryOnClick();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
|
Loading…
Reference in a new issue