This commit is contained in:
Vitaliy 2020-05-18 16:22:08 +03:00
parent 66902018f1
commit f8b3b2dae8
3 changed files with 27 additions and 35 deletions

View file

@ -4,7 +4,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -23,6 +22,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -59,18 +59,16 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
private HashMap<String, Boolean> routingParametersMap; private HashMap<String, Boolean> routingParametersMap;
private List<LatLon> removedImpassableRoads; private List<LatLon> removedImpassableRoads;
private LinearLayout stylesContainer; private LinearLayout stylesContainer;
private List<BottomSheetItemWithCompoundButton> compoundButtons = new ArrayList<>();
private boolean hideImpassableRoads; private boolean hideImpassableRoads;
@ColorRes private int compoundButtonColorId = INVALID_ID; @ColorRes
private int compoundButtonColorId = INVALID_ID;
public AvoidRoadsBottomSheetDialogFragment() { public void setHideImpassableRoads(boolean hideImpassableRoads) {
}
public AvoidRoadsBottomSheetDialogFragment(boolean hideImpassableRoads) {
this.hideImpassableRoads = hideImpassableRoads; this.hideImpassableRoads = hideImpassableRoads;
} }
List<BottomSheetItemWithCompoundButton> compoundButtons = new ArrayList<>();
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
@ -79,12 +77,10 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
} }
routingOptionsHelper = app.getRoutingOptionsHelper(); routingOptionsHelper = app.getRoutingOptionsHelper();
if (savedInstanceState != null) { if (savedInstanceState != null) {
hideImpassableRoads = savedInstanceState.getBoolean(HIDE_IMPASSABLE_ROADS_KEY);
if (savedInstanceState.containsKey(AVOID_ROADS_TYPES_KEY)) { if (savedInstanceState.containsKey(AVOID_ROADS_TYPES_KEY)) {
routingParametersMap = (HashMap<String, Boolean>) savedInstanceState.getSerializable(AVOID_ROADS_TYPES_KEY); routingParametersMap = (HashMap<String, Boolean>) savedInstanceState.getSerializable(AVOID_ROADS_TYPES_KEY);
} }
if (savedInstanceState.containsKey(HIDE_IMPASSABLE_ROADS_KEY)) {
hideImpassableRoads = true;
}
if (savedInstanceState.containsKey(AVOID_ROADS_OBJECTS_KEY)) { if (savedInstanceState.containsKey(AVOID_ROADS_OBJECTS_KEY)) {
removedImpassableRoads = (List<LatLon>) savedInstanceState.getSerializable(AVOID_ROADS_OBJECTS_KEY); removedImpassableRoads = (List<LatLon>) savedInstanceState.getSerializable(AVOID_ROADS_OBJECTS_KEY);
} }
@ -96,8 +92,8 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
removedImpassableRoads = new ArrayList<LatLon>(); removedImpassableRoads = new ArrayList<LatLon>();
} }
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; LayoutInflater themedInflater = UiUtilities.getInflater(getContext(), nightMode);
final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_toolbar_title, null); final View titleView = themedInflater.inflate(R.layout.bottom_sheet_item_toolbar_title, null);
TextView textView = (TextView) titleView.findViewById(R.id.title); TextView textView = (TextView) titleView.findViewById(R.id.title);
textView.setText(!hideImpassableRoads ? R.string.impassable_road : R.string.avoid_pt_types); textView.setText(!hideImpassableRoads ? R.string.impassable_road : R.string.avoid_pt_types);
@ -118,8 +114,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
items.add(titleItem); items.add(titleItem);
final SimpleBottomSheetItem descriptionItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() final SimpleBottomSheetItem descriptionItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setTitle( .setTitle(!hideImpassableRoads ? getString(R.string.avoid_roads_descr) : getString(R.string.avoid_pt_types_descr))
!hideImpassableRoads ? getString(R.string.avoid_roads_descr) : getString(R.string.avoid_pt_types_descr))
.setLayoutId(R.layout.bottom_sheet_item_title_long) .setLayoutId(R.layout.bottom_sheet_item_title_long)
.create(); .create();
items.add(descriptionItem); items.add(descriptionItem);
@ -129,18 +124,18 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
stylesContainer.setOrientation(LinearLayout.VERTICAL); stylesContainer.setOrientation(LinearLayout.VERTICAL);
stylesContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small), 0, 0); stylesContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small), 0, 0);
items.add(new BaseBottomSheetItem.Builder().setCustomView(stylesContainer).create());
if (!hideImpassableRoads) {
for (final LatLon routeDataObject : app.getAvoidSpecificRoads().getImpassableRoads().keySet()) { for (final LatLon routeDataObject : app.getAvoidSpecificRoads().getImpassableRoads().keySet()) {
if (removedImpassableRoads.contains(routeDataObject)) { if (removedImpassableRoads.contains(routeDataObject)) {
continue; continue;
} }
LayoutInflater.from(new ContextThemeWrapper(app, themeRes)).inflate(R.layout.bottom_sheet_item_simple_right_icon, stylesContainer, true); themedInflater.inflate(R.layout.bottom_sheet_item_simple_right_icon, stylesContainer, true);
} }
items.add(new BaseBottomSheetItem.Builder().setCustomView(stylesContainer).create());
if(!hideImpassableRoads) {
populateImpassableRoadsObjects(); populateImpassableRoadsObjects();
final View buttonView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_btn, null); final View buttonView = themedInflater.inflate(R.layout.bottom_sheet_item_btn, null);
TextView buttonDescription = (TextView) buttonView.findViewById(R.id.button_descr); TextView buttonDescription = (TextView) buttonView.findViewById(R.id.button_descr);
buttonDescription.setText(R.string.shared_string_select_on_map); buttonDescription.setText(R.string.shared_string_select_on_map);
buttonDescription.setTextColor(getResolvedColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); buttonDescription.setTextColor(getResolvedColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
@ -169,15 +164,12 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
dismiss(); dismiss();
} }
}); });
final SimpleBottomSheetItem buttonItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() SimpleBottomSheetItem buttonItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(buttonView) .setCustomView(buttonView)
.create(); .create();
items.add(buttonItem); items.add(buttonItem);
} }
items.add(new SubtitleDividerItem(app)); items.add(new SubtitleDividerItem(app));
populateImpassableRoadsTypes(); populateImpassableRoadsTypes();
@ -270,9 +262,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putSerializable(AVOID_ROADS_TYPES_KEY, routingParametersMap); outState.putSerializable(AVOID_ROADS_TYPES_KEY, routingParametersMap);
outState.putSerializable(AVOID_ROADS_OBJECTS_KEY, (Serializable) removedImpassableRoads); outState.putSerializable(AVOID_ROADS_OBJECTS_KEY, (Serializable) removedImpassableRoads);
if(hideImpassableRoads) { outState.putBoolean(HIDE_IMPASSABLE_ROADS_KEY, hideImpassableRoads);
outState.putBoolean(HIDE_IMPASSABLE_ROADS_KEY, true);
}
} }
@Override @Override
@ -284,7 +274,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
@Nullable @Nullable
private MapActivity getMapActivity() { private MapActivity getMapActivity() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null && activity instanceof MapActivity) { if (activity instanceof MapActivity) {
return (MapActivity) activity; return (MapActivity) activity;
} }
return null; return null;

View file

@ -760,7 +760,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (card instanceof PublicTransportNotFoundWarningCard) { } else if (card instanceof PublicTransportNotFoundWarningCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN); updateApplicationMode(null, ApplicationMode.PEDESTRIAN);
} else if (card instanceof PublicTransportNotFoundSettingsWarningCard) { } else if (card instanceof PublicTransportNotFoundSettingsWarningCard) {
AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment();
avoidRoadsFragment.setHideImpassableRoads(true);
avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG);
} else if (card instanceof PedestrianRouteCard) { } else if (card instanceof PedestrianRouteCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN); updateApplicationMode(null, ApplicationMode.PEDESTRIAN);

View file

@ -300,7 +300,8 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem);
AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment();
avoidRoadsFragment.setHideImpassableRoads(true);
avoidRoadsFragment.setTargetFragment(RouteOptionsBottomSheet.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE); avoidRoadsFragment.setTargetFragment(RouteOptionsBottomSheet.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE);
avoidRoadsFragment.setCompoundButtonColorId(selectedModeColorId); avoidRoadsFragment.setCompoundButtonColorId(selectedModeColorId);
avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG);