[android] Review fixes

This commit is contained in:
Roman Romanov 2017-06-16 08:51:15 +04:00
parent 3bc2665a74
commit 13f92bb514
5 changed files with 119 additions and 132 deletions

View file

@ -2,7 +2,6 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/height_block_base"

View file

@ -56,7 +56,6 @@ import com.mapswithme.maps.editor.ReportFragment;
import com.mapswithme.maps.location.CompassData;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.routing.NavigationController;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.routing.RoutingPlanController;
import com.mapswithme.maps.routing.RoutingPlanFragment;
@ -1596,14 +1595,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (controller.isBuilt() || controller.isUberRequestHandled())
{
showLineFrame(true, new Runnable()
{
@Override
public void run()
{
adjustRuler(0, 0);
}
});
showLineFrame();
if (completion != null)
completion.run();
@ -1612,32 +1604,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (controller.isPlanning() || controller.isBuilding() || controller.isErrorEncountered())
{
if (!controller.hasStartPoint())
{
needsStartPoint();
showLineFrame(true, new Runnable()
{
@Override
public void run()
{
adjustRuler(0, 0);
}
});
if (showAddStartOrFinishFrame(controller, true))
return;
}
if (!controller.hasEndPoint())
{
needsFinishPoint();
showLineFrame(true, new Runnable()
{
@Override
public void run()
{
adjustRuler(0, 0);
}
});
return;
}
showLineFrame(false, new Runnable()
{
@ -1655,6 +1623,74 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
hideRoutingActionFrame();
showLineFrame();
if (completion != null)
completion.run();
}
private boolean showAddStartOrFinishFrame(@NonNull RoutingController controller,
boolean showFrame)
{
if (!controller.hasStartPoint())
{
showAddStartFrame();
if (showFrame)
showLineFrame();
return true;
}
if (!controller.hasEndPoint())
{
showAddFinishFrame();
if (showFrame)
showLineFrame();
return true;
}
return false;
}
private void showAddStartFrame()
{
if (!mIsFragmentContainer)
{
mRoutingPlanInplaceController.showAddStartFrame();
return;
}
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.showAddStartFrame();
}
private void showAddFinishFrame()
{
if (!mIsFragmentContainer)
{
mRoutingPlanInplaceController.showAddFinishFrame();
return;
}
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.showAddFinishFrame();
}
private void hideRoutingActionFrame()
{
if (!mIsFragmentContainer)
{
mRoutingPlanInplaceController.hideActionFrame();
return;
}
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.hideActionFrame();
}
private void showLineFrame()
{
showLineFrame(true, new Runnable()
{
@Override
@ -1663,51 +1699,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
adjustRuler(0, 0);
}
});
if (completion != null)
completion.run();
}
private void needsStartPoint()
{
if (mIsFragmentContainer)
{
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.needsStartPoint();
}
else
{
mRoutingPlanInplaceController.needsStartPoint();
}
}
private void needsFinishPoint()
{
if (mIsFragmentContainer)
{
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.needsFinishPoint();
}
else
{
mRoutingPlanInplaceController.needsFinishPoint();
}
}
private void hideRoutingActionFrame()
{
if (mIsFragmentContainer)
{
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.hideActionFrame();
}
else
{
mRoutingPlanInplaceController.hideActionFrame();
}
}
private void showLineFrame(boolean show, @Nullable Runnable completion)
@ -1744,14 +1735,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (mIsFragmentContainer)
{
replaceFragment(RoutingPlanFragment.class, null, completionListener);
if (!RoutingController.get().hasStartPoint())
{
needsStartPoint();
}
else if (!RoutingController.get().hasEndPoint())
{
needsFinishPoint();
}
showAddStartOrFinishFrame(RoutingController.get(), false);
adjustTraffic(UiUtils.dimen(R.dimen.panel_width), UiUtils.getStatusBarHeight(getApplicationContext()));
}
else

View file

@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
@ -71,15 +72,42 @@ final class RoutingBottomMenuController implements View.OnClickListener
@Nullable
private UberInfo.Product mUberProduct;
RoutingBottomMenuController(@NonNull Activity context,
@NonNull View altitudeChartFrame,
@NonNull View uberFrame,
@NonNull TextView error,
@NonNull Button start,
@NonNull ImageView altitudeChart,
@NonNull TextView altitudeDifference,
@NonNull View numbersFrame,
@NonNull View actionFrame)
@NonNull
static RoutingBottomMenuController newInstance(@NonNull Activity activity, @NonNull View frame)
{
View altitudeChartFrame = getViewById(activity, frame, R.id.altitude_chart_panel);
View uberFrame = getViewById(activity, frame, R.id.uber_panel);
TextView error = (TextView) getViewById(activity, frame, R.id.error);
Button start = (Button) getViewById(activity, frame, R.id.start);
ImageView altitudeChart = (ImageView) getViewById(activity, frame, R.id.altitude_chart);
TextView altitudeDifference = (TextView) getViewById(activity, frame, R.id.altitude_difference);
View numbersFrame = getViewById(activity, frame, R.id.numbers);
View actionFrame = getViewById(activity, frame, R.id.routing_action_frame);
return new RoutingBottomMenuController(activity, altitudeChartFrame,
uberFrame, error, start,
altitudeChart,
altitudeDifference,
numbersFrame, actionFrame);
}
@NonNull
private static View getViewById(@NonNull Activity activity, @NonNull View frame,
@IdRes int resourceId)
{
View view = frame.findViewById(resourceId);
return view == null ? activity.findViewById(resourceId) : view;
}
private RoutingBottomMenuController(@NonNull Activity context,
@NonNull View altitudeChartFrame,
@NonNull View uberFrame,
@NonNull TextView error,
@NonNull Button start,
@NonNull ImageView altitudeChart,
@NonNull TextView altitudeDifference,
@NonNull View numbersFrame,
@NonNull View actionFrame)
{
mContext = context;
mAltitudeChartFrame = altitudeChartFrame;
@ -147,7 +175,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
UiUtils.show(mUberFrame);
}
void needsStartPoint()
void showAddStartFrame()
{
UiUtils.show(mActionFrame, mActionButton);
mActionMessage.setText(R.string.routing_add_start_point);
@ -157,7 +185,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
mActionIcon.setImageDrawable(Graphics.tint(icon, colorAccent));
}
void needsFinishPoint()
void showAddFinishFrame()
{
UiUtils.show(mActionFrame);
mActionMessage.setText(R.string.routing_add_finish_point);

View file

@ -12,12 +12,10 @@ import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
@ -153,20 +151,7 @@ public class RoutingPlanController extends ToolbarController implements SlotFram
mProgressBicycle = (WheelProgressView) progressFrame.findViewById(R.id.progress_bicycle);
mProgressTaxi = (WheelProgressView) progressFrame.findViewById(R.id.progress_taxi);
View altitudeChartFrame = getViewById(R.id.altitude_chart_panel);
View uberFrame = getViewById(R.id.uber_panel);
TextView error = (TextView) getViewById(R.id.error);
Button start = (Button) getViewById(R.id.start);
ImageView altitudeChart = (ImageView) getViewById(R.id.altitude_chart);
TextView altitudeDifference = (TextView) getViewById(R.id.altitude_difference);
View numbersFrame = getViewById(R.id.numbers);
View actionFrame = getViewById(R.id.routing_action_frame);
mRoutingBottomMenuController = new RoutingBottomMenuController(activity, altitudeChartFrame,
uberFrame, error, start,
altitudeChart,
altitudeDifference,
numbersFrame, actionFrame);
mRoutingBottomMenuController = RoutingBottomMenuController.newInstance(mActivity, mFrame);
mToggle.setImageDrawable(mToggleImage);
mToggle.setOnClickListener(new View.OnClickListener()
@ -429,15 +414,6 @@ public class RoutingPlanController extends ToolbarController implements SlotFram
mRoutingBottomMenuController.showStartButton(show);
}
@NonNull
private View getViewById(@IdRes int resourceId)
{
View view = mFrame.findViewById(resourceId);
if (view == null)
view = mActivity.findViewById(resourceId);
return view;
}
void saveRoutingPanelState(@NonNull Bundle outState)
{
mRoutingBottomMenuController.saveRoutingPanelState(outState);
@ -458,14 +434,14 @@ public class RoutingPlanController extends ToolbarController implements SlotFram
mToggleListener = listener;
}
public void needsStartPoint()
public void showAddStartFrame()
{
mRoutingBottomMenuController.needsStartPoint();
mRoutingBottomMenuController.showAddStartFrame();
}
public void needsFinishPoint()
public void showAddFinishFrame()
{
mRoutingBottomMenuController.needsFinishPoint();
mRoutingBottomMenuController.showAddFinishFrame();
}
public void hideActionFrame()

View file

@ -78,14 +78,14 @@ public class RoutingPlanFragment extends BaseMwmFragment
mPlanController.saveRoutingPanelState(outState);
}
public void needsStartPoint()
public void showAddStartFrame()
{
mPlanController.needsStartPoint();
mPlanController.showAddStartFrame();
}
public void needsFinishPoint()
public void showAddFinishFrame()
{
mPlanController.needsFinishPoint();
mPlanController.showAddFinishFrame();
}
public void hideActionFrame()