refactored some code
This commit is contained in:
parent
cc136f9796
commit
604956da71
1 changed files with 13 additions and 38 deletions
|
@ -1,12 +1,8 @@
|
|||
package net.osmand.plus.parkingpoint;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -23,16 +19,17 @@ 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";
|
||||
private ParkingPositionPlugin plugin;
|
||||
public static final int TYPE_UNLIMITED = 0;
|
||||
public static final int TYPE_LIMITED = 1;
|
||||
|
||||
private LatLon latLon;
|
||||
private MapActivity mapActivity;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
items.add(new TitleItem(getString(R.string.parking_options)));
|
||||
Bundle args = getArguments();
|
||||
latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY));
|
||||
plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
|
||||
|
||||
items.add(new TitleItem(getString(R.string.parking_options)));
|
||||
BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_time_start))
|
||||
.setTitle(getString(R.string.osmand_parking_no_lim_text))
|
||||
|
@ -40,7 +37,7 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addParkingPositionByType(ParkingType.TYPE_UNLIMITED);
|
||||
addParkingPositionByType(TYPE_UNLIMITED);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
@ -53,24 +50,26 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addParkingPositionByType(ParkingType.TYPE_LIMITED);
|
||||
addParkingPositionByType(TYPE_LIMITED);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(byDateItem);
|
||||
}
|
||||
|
||||
private void addParkingPositionByType(ParkingType type) {
|
||||
private void addParkingPositionByType(int type) {
|
||||
ParkingPositionPlugin plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
|
||||
MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (plugin != null) {
|
||||
if (type.isLimited()) {
|
||||
if (type == 0) {
|
||||
if (plugin.isParkingEventAdded()) {
|
||||
plugin.showDeleteEventWarning(getActivity());
|
||||
plugin.showDeleteEventWarning(mapActivity);
|
||||
}
|
||||
plugin.addOrRemoveParkingEvent(false);
|
||||
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), false);
|
||||
plugin.showContextMenuIfNeeded(mapActivity, true);
|
||||
mapActivity.refreshMap();
|
||||
} else if (type.isUnlimited()) {
|
||||
} else if (type == 1) {
|
||||
if (plugin.isParkingEventAdded()) {
|
||||
plugin.showDeleteEventWarning(mapActivity);
|
||||
}
|
||||
|
@ -81,28 +80,4 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||
Context context = getActivity();
|
||||
if (context instanceof MapActivity) {
|
||||
mapActivity = (MapActivity) context;
|
||||
}
|
||||
return super.onCreateView(inflater, parent, savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
public enum ParkingType {
|
||||
TYPE_UNLIMITED,
|
||||
TYPE_LIMITED;
|
||||
|
||||
public boolean isLimited() {
|
||||
return this == TYPE_UNLIMITED;
|
||||
}
|
||||
|
||||
public boolean isUnlimited() {
|
||||
return this == TYPE_LIMITED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue