This commit is contained in:
Dmitry Donskoy 2019-04-09 13:41:52 +03:00 committed by Aleksandr Zatsepin
parent a954d3a337
commit e92a2f5c3f
6 changed files with 70 additions and 45 deletions

View file

@ -25,7 +25,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.mapswithme.maps.Framework.MapObjectListener;
@ -52,6 +51,7 @@ import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.dialog.AlertDialogCallback;
import com.mapswithme.maps.dialog.DialogUtils;
import com.mapswithme.maps.dialog.DrivingOptionsDialogFactory;
import com.mapswithme.maps.discovery.DiscoveryActivity;
import com.mapswithme.maps.discovery.DiscoveryFragment;
import com.mapswithme.maps.discovery.ItemType;
@ -85,7 +85,7 @@ import com.mapswithme.maps.routing.NavigationController;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.routing.RoutingBottomMenuListener;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.routing.RoutingOptions;
import com.mapswithme.maps.routing.RoutingErrorDialogFragment;
import com.mapswithme.maps.routing.RoutingPlanFragment;
import com.mapswithme.maps.routing.RoutingPlanInplaceController;
import com.mapswithme.maps.search.BookingFilterParams;
@ -915,6 +915,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
if (mRoutingPlanInplaceController == null)
return;
mRoutingPlanInplaceController.hideDrivingOptionsView();
RoutingController.get().attach(this);
RoutingController.get().prepare();
@ -1945,16 +1946,12 @@ public class MwmActivity extends BaseMwmFragmentActivity
private int calcFloatingViewOffset()
{
int extraOppositeOffset;
if (mRoutingPlanInplaceController == null
|| mRoutingPlanInplaceController.getFrame().getHeight() == 0)
|| (extraOppositeOffset = mRoutingPlanInplaceController.calcFloatingViewsOffset()) == 0)
return UiUtils.getStatusBarHeight(this);
View driverOptionsView = mRoutingPlanInplaceController.getDrivingOptionsBtnContainer();
int extraOppositeOffset = driverOptionsView.getVisibility() == View.VISIBLE
? 0
: driverOptionsView.getHeight();
return mRoutingPlanInplaceController.getFrame().getHeight() - extraOppositeOffset;
return extraOppositeOffset;
}
@Override
@ -2085,6 +2082,35 @@ public class MwmActivity extends BaseMwmFragmentActivity
return SubwayManager.from(this).isEnabled();
}
@Override
public void onBuildError(int lastResultCode, @NonNull String[] lastMissingMaps)
{
RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(lastResultCode, lastMissingMaps);
fragment.show(getSupportFragmentManager(), RoutingErrorDialogFragment.class.getSimpleName());
}
@Override
public void onCalculateRouteError()
{
showUnableCalculateRouteFirstTimeDialog();
}
private void showUnableCalculateRouteFirstTimeDialog()
{
com.mapswithme.maps.dialog.AlertDialog dialog =
new com.mapswithme.maps.dialog.AlertDialog.Builder()
.setTitleId(R.string.unable_to_calc_alert_title)
.setMessageId(R.string.unable_to_calc_alert_subtitle)
.setPositiveBtnId(R.string.settings)
.setNegativeBtnId(R.string.cancel)
.setReqCode(REQ_CODE_ERROR_CALCULATE_ROUTE_FIRST_TIME)
.setDialogFactory(new DrivingOptionsDialogFactory())
.setFragManagerStrategyType(com.mapswithme.maps.dialog.AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER)
.build();
dialog.show(this,
ERROR_CALCULATE_ROUTE_FIRST_TIME_TAG);
}
private void updateSearchBar()
{
if (!TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))

View file

@ -1,13 +1,10 @@
package com.mapswithme.maps.dialog;
import android.content.Context;
public class DrivingOptionsDialog extends AlertDialog
public class ActivityCallbackAlertDialog extends AlertDialog
{
@Override
public void onAttach(Context context)
protected void onAttachInternal()
{
super.onAttach(context);
AlertDialogCallback callback = (AlertDialogCallback) getActivity();
setTargetCallback(callback);
}

View file

@ -89,8 +89,7 @@ public class AlertDialog extends BaseMwmDialogFragment
super.onAttach(context);
try
{
mTargetCallback = (AlertDialogCallback) (getParentFragment() == null ? getTargetFragment()
: getParentFragment());
onAttachInternal();
}
catch (ClassCastException e)
{
@ -100,6 +99,12 @@ public class AlertDialog extends BaseMwmDialogFragment
}
}
protected void onAttachInternal()
{
mTargetCallback = (AlertDialogCallback) (getParentFragment() == null ? getTargetFragment()
: getParentFragment());
}
@Override
public void onDetach()
{

View file

@ -8,6 +8,6 @@ public class DrivingOptionsDialogFactory implements DialogFactory
@Override
public AlertDialog createDialog()
{
return new DrivingOptionsDialog();
return new ActivityCallbackAlertDialog();
}
}

View file

@ -17,12 +17,10 @@ import android.view.View;
import android.widget.TextView;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.dialog.DrivingOptionsDialogFactory;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.taxi.TaxiInfo;
@ -82,6 +80,8 @@ public class RoutingController implements TaxiManager.TaxiListener
void onBuiltRoute();
void onRouteWarningReceived();
boolean isSubwayEnabled();
void onBuildError(int lastResultCode, @NonNull String[] lastMissingMaps);
void onCalculateRouteError();
/**
* @param progress progress to be displayed.
@ -213,8 +213,7 @@ public class RoutingController implements TaxiManager.TaxiListener
if (ResultCodesHelper.isMoreMapsNeeded(mLastResultCode))
{
RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(mLastResultCode, mLastMissingMaps);
fragment.show(mContainer.getActivity().getSupportFragmentManager(), RoutingErrorDialogFragment.class.getSimpleName());
mContainer.onBuildError(mLastResultCode, mLastMissingMaps);
return;
}
@ -223,23 +222,7 @@ public class RoutingController implements TaxiManager.TaxiListener
updateProgress();
if (RoutingOptions.hasAnyOptions())
showUnableCalculateRouteFirstTimeDialog();
}
private void showUnableCalculateRouteFirstTimeDialog()
{
com.mapswithme.maps.dialog.AlertDialog dialog =
new com.mapswithme.maps.dialog.AlertDialog.Builder()
.setTitleId(R.string.unable_to_calc_alert_title)
.setMessageId(R.string.unable_to_calc_alert_subtitle)
.setPositiveBtnId(R.string.settings)
.setNegativeBtnId(R.string.cancel)
.setReqCode(MwmActivity.REQ_CODE_ERROR_CALCULATE_ROUTE_FIRST_TIME)
.setDialogFactory(new DrivingOptionsDialogFactory())
.setFragManagerStrategyType(com.mapswithme.maps.dialog.AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER)
.build();
dialog.show(mContainer.getActivity(),
MwmActivity.ERROR_CALCULATE_ROUTE_FIRST_TIME_TAG);
mContainer.onCalculateRouteError();
}
private void setState(State newState)
@ -426,7 +409,7 @@ public class RoutingController implements TaxiManager.TaxiListener
public void prepare()
{
prepare(getStartPoint(), getEndPoint(), getEndPoint() == null);
prepare(getStartPoint(), getEndPoint(), false);
}
public void prepare(boolean canUseMyPositionAsStart, @Nullable MapObject endPoint)
@ -861,9 +844,9 @@ public class RoutingController implements TaxiManager.TaxiListener
private void setPointsInternal(@Nullable MapObject startPoint, @Nullable MapObject endPoint)
{
boolean hasStart = startPoint != null;
boolean hasEnd = endPoint != null;
boolean hasOnePointAtLeast = hasStart || hasEnd;
final boolean hasStart = startPoint != null;
final boolean hasEnd = endPoint != null;
final boolean hasOnePointAtLeast = hasStart || hasEnd;
if (hasOnePointAtLeast)
applyRemovingIntermediatePointsTransaction();

View file

@ -80,7 +80,8 @@ public class RoutingPlanController extends ToolbarController
}
RoutingPlanController(View root, Activity activity,
@NonNull RoutingPlanInplaceController.RoutingPlanListener routingPlanListener, @Nullable RoutingBottomMenuListener listener)
@NonNull RoutingPlanInplaceController.RoutingPlanListener routingPlanListener,
@Nullable RoutingBottomMenuListener listener)
{
super(root, activity);
mFrame = root;
@ -106,13 +107,13 @@ public class RoutingPlanController extends ToolbarController
}
@NonNull
public View getFrame()
protected View getFrame()
{
return mFrame;
}
@NonNull
public View getDrivingOptionsBtnContainer()
private View getDrivingOptionsBtnContainer()
{
return mDrivingOptionsBtnContainer;
}
@ -359,6 +360,19 @@ public class RoutingPlanController extends ToolbarController
UiUtils.hide(mDrivingOptionsBtnContainer);
}
public int calcFloatingViewsOffset()
{
int frameHeight = getFrame().getHeight();
if (frameHeight == 0)
return 0;
View driverOptionsView = getDrivingOptionsBtnContainer();
int extraOppositeOffset = driverOptionsView.getVisibility() == View.VISIBLE
? 0
: driverOptionsView.getHeight();
return frameHeight - extraOppositeOffset;
}
private class SelfTerminatedDrivingOptionsLayoutListener implements View.OnLayoutChangeListener
{