added parkingTypeBottomSheetDialog
This commit is contained in:
parent
7a699131ba
commit
cc136f9796
2 changed files with 122 additions and 44 deletions
|
@ -4,6 +4,8 @@ package net.osmand.plus.parkingpoint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.text.format.Time;
|
import android.text.format.Time;
|
||||||
|
@ -242,49 +244,17 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
||||||
* It allows user to choose a type of parking (time-limited or time-unlimited).
|
* It allows user to choose a type of parking (time-limited or time-unlimited).
|
||||||
*/
|
*/
|
||||||
public void showAddParkingDialog(final MapActivity mapActivity, final double latitude, final double longitude) {
|
public void showAddParkingDialog(final MapActivity mapActivity, final double latitude, final double longitude) {
|
||||||
final boolean wasEventPreviouslyAdded = isParkingEventAdded();
|
Bundle args = new Bundle();
|
||||||
|
args.putDouble(ParkingTypeBottomSheetDialogFragment.LAT_KEY, latitude);
|
||||||
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
|
args.putDouble(ParkingTypeBottomSheetDialogFragment.LON_KEY, longitude);
|
||||||
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
|
FragmentManager fragmentManager=mapActivity.getSupportFragmentManager();
|
||||||
|
ParkingTypeBottomSheetDialogFragment fragment = new ParkingTypeBottomSheetDialogFragment();
|
||||||
menuAdapter.addItem(itemBuilder.setTitleId(R.string.osmand_parking_no_lim_text, app)
|
fragment.setUsedOnMap(true);
|
||||||
.setIcon(R.drawable.ic_action_time_start).setTag(1).createItem());
|
fragment.setArguments(args);
|
||||||
menuAdapter.addItem(itemBuilder.setTitleId(R.string.osmand_parking_time_limit, app)
|
fragment.show(fragmentManager, ParkingTypeBottomSheetDialogFragment.TAG);
|
||||||
.setIcon(R.drawable.ic_action_time_span).setTag(2).createItem());
|
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
|
|
||||||
boolean light = app.getSettings().isLightContent();
|
|
||||||
final ArrayAdapter<ContextMenuItem> listAdapter = menuAdapter.createListAdapter(mapActivity, light);
|
|
||||||
builder.setTitle(R.string.parking_options);
|
|
||||||
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(final DialogInterface dialog, int which) {
|
|
||||||
ContextMenuItem item = menuAdapter.getItem(which);
|
|
||||||
int index = item.getTag();
|
|
||||||
if (index == 1) {
|
|
||||||
dialog.dismiss();
|
|
||||||
if (wasEventPreviouslyAdded) {
|
|
||||||
showDeleteEventWarning(mapActivity);
|
|
||||||
}
|
|
||||||
addOrRemoveParkingEvent(false);
|
|
||||||
setParkingPosition(mapActivity, latitude, longitude, false);
|
|
||||||
showContextMenuIfNeeded(mapActivity,true);
|
|
||||||
mapActivity.getMapView().refreshMap();
|
|
||||||
} else if (index == 2) {
|
|
||||||
if (wasEventPreviouslyAdded) {
|
|
||||||
showDeleteEventWarning(mapActivity);
|
|
||||||
}
|
|
||||||
setParkingPosition(mapActivity, latitude, longitude, true);
|
|
||||||
showSetTimeLimitDialog(mapActivity, dialog);
|
|
||||||
mapActivity.getMapView().refreshMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
|
||||||
builder.create().show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showContextMenuIfNeeded(final MapActivity mapActivity, boolean animated) {
|
void showContextMenuIfNeeded(final MapActivity mapActivity, boolean animated) {
|
||||||
if (parkingLayer != null) {
|
if (parkingLayer != null) {
|
||||||
MapContextMenu menu = mapActivity.getContextMenu();
|
MapContextMenu menu = mapActivity.getContextMenu();
|
||||||
if (menu.isVisible()) {
|
if (menu.isVisible()) {
|
||||||
|
@ -324,7 +294,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
||||||
* @param mapActivity
|
* @param mapActivity
|
||||||
* @param choose
|
* @param choose
|
||||||
*/
|
*/
|
||||||
private void showSetTimeLimitDialog(final MapActivity mapActivity, final DialogInterface choose) {
|
void showSetTimeLimitDialog(final MapActivity mapActivity, final DialogInterface choose) {
|
||||||
final View setTimeParking = mapActivity.getLayoutInflater().inflate(R.layout.parking_set_time_limit, null);
|
final View setTimeParking = mapActivity.getLayoutInflater().inflate(R.layout.parking_set_time_limit, null);
|
||||||
AlertDialog.Builder setTime = new AlertDialog.Builder(mapActivity);
|
AlertDialog.Builder setTime = new AlertDialog.Builder(mapActivity);
|
||||||
setTime.setView(setTimeParking);
|
setTime.setView(setTimeParking);
|
||||||
|
@ -414,7 +384,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
||||||
* Method shows warning, if previously the event for time-limited parking was added to Calendar app.
|
* Method shows warning, if previously the event for time-limited parking was added to Calendar app.
|
||||||
* @param activity
|
* @param activity
|
||||||
*/
|
*/
|
||||||
private void showDeleteEventWarning(final Activity activity) {
|
void showDeleteEventWarning(final Activity activity) {
|
||||||
if (isParkingEventAdded()) {
|
if (isParkingEventAdded()) {
|
||||||
AlertDialog.Builder deleteEventWarning = new AlertDialog.Builder(activity);
|
AlertDialog.Builder deleteEventWarning = new AlertDialog.Builder(activity);
|
||||||
deleteEventWarning.setTitle(activity.getString(R.string.osmand_parking_warning));
|
deleteEventWarning.setTitle(activity.getString(R.string.osmand_parking_warning));
|
||||||
|
@ -436,7 +406,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
||||||
* @param longitude
|
* @param longitude
|
||||||
* @param isLimited
|
* @param isLimited
|
||||||
*/
|
*/
|
||||||
private void setParkingPosition(final MapActivity mapActivity, final double latitude, final double longitude, boolean isLimited) {
|
void setParkingPosition(final MapActivity mapActivity, final double latitude, final double longitude, boolean isLimited) {
|
||||||
setParkingPosition(latitude, longitude);
|
setParkingPosition(latitude, longitude);
|
||||||
setParkingType(isLimited);
|
setParkingType(isLimited);
|
||||||
setParkingStartTime(Calendar.getInstance().getTimeInMillis());
|
setParkingStartTime(Calendar.getInstance().getTimeInMillis());
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
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;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
|
||||||
|
|
||||||
|
public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public static final String TAG = "ParkingTypeBottomSheetDialogFragment";
|
||||||
|
public static final String LAT_KEY = "latitude";
|
||||||
|
public static final String LON_KEY = "longitude";
|
||||||
|
private ParkingPositionPlugin plugin;
|
||||||
|
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);
|
||||||
|
BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_action_time_start))
|
||||||
|
.setTitle(getString(R.string.osmand_parking_no_lim_text))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
addParkingPositionByType(ParkingType.TYPE_UNLIMITED);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(byTypeItem);
|
||||||
|
|
||||||
|
BaseBottomSheetItem byDateItem = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_action_time_span))
|
||||||
|
.setTitle(getString(R.string.osmand_parking_time_limit))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
addParkingPositionByType(ParkingType.TYPE_LIMITED);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(byDateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addParkingPositionByType(ParkingType type) {
|
||||||
|
if (plugin != null) {
|
||||||
|
if (type.isLimited()) {
|
||||||
|
if (plugin.isParkingEventAdded()) {
|
||||||
|
plugin.showDeleteEventWarning(getActivity());
|
||||||
|
}
|
||||||
|
plugin.addOrRemoveParkingEvent(false);
|
||||||
|
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), false);
|
||||||
|
plugin.showContextMenuIfNeeded(mapActivity, true);
|
||||||
|
mapActivity.refreshMap();
|
||||||
|
} else if (type.isUnlimited()) {
|
||||||
|
if (plugin.isParkingEventAdded()) {
|
||||||
|
plugin.showDeleteEventWarning(mapActivity);
|
||||||
|
}
|
||||||
|
plugin.setParkingPosition(mapActivity, latLon.getLatitude(), latLon.getLongitude(), true);
|
||||||
|
plugin.showSetTimeLimitDialog(mapActivity, new Dialog(getContext()));
|
||||||
|
mapActivity.getMapView().refreshMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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