refactored some code

This commit is contained in:
Chumva 2018-03-02 19:06:34 +02:00
parent 604956da71
commit 68ab65e024

View file

@ -19,16 +19,9 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
public static final String TAG = "ParkingTypeBottomSheetDialogFragment";
public static final String LAT_KEY = "latitude";
public static final String LON_KEY = "longitude";
public static final int TYPE_UNLIMITED = 0;
public static final int TYPE_LIMITED = 1;
private LatLon latLon;
@Override
public void createMenuItems(Bundle savedInstanceState) {
Bundle args = getArguments();
latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY));
items.add(new TitleItem(getString(R.string.parking_options)));
BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_time_start))
@ -37,7 +30,7 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addParkingPositionByType(TYPE_UNLIMITED);
addParkingPositionByType(false);
}
})
.create();
@ -50,32 +43,32 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addParkingPositionByType(TYPE_LIMITED);
addParkingPositionByType(true);
}
})
.create();
items.add(byDateItem);
}
private void addParkingPositionByType(int type) {
private void addParkingPositionByType(boolean limited) {
Bundle args = getArguments();
LatLon latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY));
ParkingPositionPlugin plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
MapActivity mapActivity = (MapActivity) getActivity();
if (plugin != null) {
if (type == 0) {
if (plugin.isParkingEventAdded()) {
plugin.showDeleteEventWarning(mapActivity);
}
if (plugin.isParkingEventAdded()) {
plugin.showDeleteEventWarning(mapActivity);
}
if (limited) {
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), true);
plugin.showSetTimeLimitDialog(mapActivity, new Dialog(getContext()));
mapActivity.getMapView().refreshMap();
} else {
plugin.addOrRemoveParkingEvent(false);
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), false);
plugin.showContextMenuIfNeeded(mapActivity, true);
mapActivity.refreshMap();
} else if (type == 1) {
if (plugin.isParkingEventAdded()) {
plugin.showDeleteEventWarning(mapActivity);
}
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), true);
plugin.showSetTimeLimitDialog(mapActivity, new Dialog(getContext()));
mapActivity.getMapView().refreshMap();
}
}
dismiss();