forked from organicmaps/organicmaps
[android] Implemented transit step adapter and embeded it into routing bottom panel
This commit is contained in:
parent
e7bc373a0c
commit
0a9d0ce8d1
11 changed files with 170 additions and 21 deletions
|
@ -13,6 +13,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<include
|
||||
layout="@layout/routing_bottom_panel_transit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<include
|
||||
layout="@layout/taxi_panel"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
<include layout="@layout/altitude_chart_panel"
|
||||
tools:visibility="gone"/>
|
||||
|
||||
<include layout="@layout/routing_bottom_panel_transit"/>
|
||||
|
||||
<include layout="@layout/taxi_panel"/>
|
||||
|
||||
<include
|
||||
|
|
|
@ -49,11 +49,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
tools:text="1 km"/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/transit"
|
||||
android:id="@+id/transit_recycler_view"
|
||||
android:layout_marginTop="@dimen/margin_half_plus"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/total_distance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
12
android/res/layout/routing_transit_step_view.xml
Normal file
12
android/res/layout/routing_transit_step_view.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mapswithme.maps.routing.TransitStepView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/routing_transit_step_min_height"
|
||||
android:textSize="@dimen/text_size_body_1"
|
||||
android:textColor="@android:color/white"
|
||||
android:paddingStart="@dimen/margin_quarter"
|
||||
android:paddingLeft="@dimen/margin_quarter"
|
||||
android:paddingEnd="@dimen/margin_quarter"
|
||||
android:paddingRight="@dimen/margin_quarter"/>
|
|
@ -81,6 +81,7 @@
|
|||
<dimen name="routing_shadow_bottom_margin_dragging">4dp</dimen>
|
||||
<dimen name="routing_turns_padding">8dp</dimen>
|
||||
<dimen name="routing_transit_step_corner_radius">2dp</dimen>
|
||||
<dimen name="routing_transit_step_min_height">20dp</dimen>
|
||||
|
||||
<!-- Bottom menu -->
|
||||
<dimen name="menu_line_height">48dp</dimen>
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.support.annotation.StringRes;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -22,7 +23,6 @@ import android.widget.TextView;
|
|||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.api.RoutePoint;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.taxi.TaxiAdapter;
|
||||
|
@ -30,6 +30,7 @@ import com.mapswithme.maps.taxi.TaxiInfo;
|
|||
import com.mapswithme.maps.taxi.TaxiLinks;
|
||||
import com.mapswithme.maps.taxi.TaxiManager;
|
||||
import com.mapswithme.maps.widget.DotPager;
|
||||
import com.mapswithme.maps.widget.recycler.TagLayoutManager;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
@ -50,6 +51,8 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
@NonNull
|
||||
private final View mAltitudeChartFrame;
|
||||
@NonNull
|
||||
private final View mTransitFrame;
|
||||
@NonNull
|
||||
private final View mTaxiFrame;
|
||||
@NonNull
|
||||
private final TextView mError;
|
||||
|
@ -83,6 +86,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
@Nullable RoutingBottomMenuListener listener)
|
||||
{
|
||||
View altitudeChartFrame = getViewById(activity, frame, R.id.altitude_chart_panel);
|
||||
View transitFrame = getViewById(activity, frame, R.id.transit_panel);
|
||||
View taxiFrame = getViewById(activity, frame, R.id.taxi_panel);
|
||||
TextView error = (TextView) getViewById(activity, frame, R.id.error);
|
||||
Button start = (Button) getViewById(activity, frame, R.id.start);
|
||||
|
@ -91,9 +95,9 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
View numbersFrame = getViewById(activity, frame, R.id.numbers);
|
||||
View actionFrame = getViewById(activity, frame, R.id.routing_action_frame);
|
||||
|
||||
return new RoutingBottomMenuController(activity, altitudeChartFrame, taxiFrame, error, start,
|
||||
altitudeChart, altitudeDifference, numbersFrame,
|
||||
actionFrame, listener);
|
||||
return new RoutingBottomMenuController(activity, altitudeChartFrame, transitFrame, taxiFrame,
|
||||
error, start, altitudeChart, altitudeDifference,
|
||||
numbersFrame, actionFrame, listener);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -106,6 +110,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
|
||||
private RoutingBottomMenuController(@NonNull Activity context,
|
||||
@NonNull View altitudeChartFrame,
|
||||
@NonNull View transitFrame,
|
||||
@NonNull View taxiFrame,
|
||||
@NonNull TextView error,
|
||||
@NonNull Button start,
|
||||
|
@ -117,6 +122,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
{
|
||||
mContext = context;
|
||||
mAltitudeChartFrame = altitudeChartFrame;
|
||||
mTransitFrame = transitFrame;
|
||||
mTaxiFrame = taxiFrame;
|
||||
mError = error;
|
||||
mStart = start;
|
||||
|
@ -136,7 +142,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
|
||||
void showAltitudeChartAndRoutingDetails()
|
||||
{
|
||||
UiUtils.hide(mError, mTaxiFrame, mActionFrame);
|
||||
UiUtils.hide(mError, mTaxiFrame, mActionFrame, mTransitFrame);
|
||||
|
||||
showRouteAltitudeChart();
|
||||
showRoutingDetails();
|
||||
|
@ -153,7 +159,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
|
||||
void showTaxiInfo(@NonNull TaxiInfo info)
|
||||
{
|
||||
UiUtils.hide(mError, mAltitudeChartFrame, mActionFrame);
|
||||
UiUtils.hide(mError, mAltitudeChartFrame, mActionFrame, mTransitFrame);
|
||||
UiUtils.showTaxiIcon((ImageView) mTaxiFrame.findViewById(R.id.iv__logo), info.getType());
|
||||
final List<TaxiInfo.Product> products = info.getProducts();
|
||||
mTaxiInfo = info;
|
||||
|
@ -176,9 +182,27 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
UiUtils.show(mTaxiFrame);
|
||||
}
|
||||
|
||||
void showTransitInfo(@NonNull TransitRouteInfo info)
|
||||
{
|
||||
UiUtils.hide(mError, mAltitudeChartFrame, mActionFrame, mAltitudeChartFrame, mTaxiFrame);
|
||||
UiUtils.show(mTransitFrame);
|
||||
RecyclerView rv = (RecyclerView) mTransitFrame.findViewById(R.id.transit_recycler_view);
|
||||
TransitStepAdapter adapter = new TransitStepAdapter();
|
||||
rv.setLayoutManager(new TagLayoutManager());
|
||||
rv.setNestedScrollingEnabled(false);
|
||||
// TODO: make dot decorator.
|
||||
rv.setAdapter(adapter);
|
||||
adapter.setItems(info.getTransitSteps());
|
||||
|
||||
TextView totalTimeView = (TextView) mTransitFrame.findViewById(R.id.total_time);
|
||||
totalTimeView.setText(RoutingController.formatRoutingTime(mContext, (int) info.getTotalTime(),
|
||||
R.dimen.text_size_routing_number));
|
||||
// TODO: set pedestrian total distance.
|
||||
}
|
||||
|
||||
void showAddStartFrame()
|
||||
{
|
||||
UiUtils.hide(mTaxiFrame, mError);
|
||||
UiUtils.hide(mTaxiFrame, mError, mTransitFrame);
|
||||
UiUtils.show(mActionFrame);
|
||||
mActionMessage.setText(R.string.routing_add_start_point);
|
||||
mActionMessage.setTag(RoutePointInfo.ROUTE_MARK_START);
|
||||
|
@ -198,7 +222,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
|
||||
void showAddFinishFrame()
|
||||
{
|
||||
UiUtils.hide(mTaxiFrame, mError);
|
||||
UiUtils.hide(mTaxiFrame, mError, mTransitFrame);
|
||||
UiUtils.show(mActionFrame);
|
||||
mActionMessage.setText(R.string.routing_add_finish_point);
|
||||
mActionMessage.setTag(RoutePointInfo.ROUTE_MARK_FINISH);
|
||||
|
@ -272,7 +296,7 @@ final class RoutingBottomMenuController implements View.OnClickListener
|
|||
|
||||
private void showError(@NonNull String message)
|
||||
{
|
||||
UiUtils.hide(mTaxiFrame, mAltitudeChartFrame, mActionFrame);
|
||||
UiUtils.hide(mTaxiFrame, mAltitudeChartFrame, mActionFrame, mTransitFrame);
|
||||
mError.setText(message);
|
||||
mError.setVisibility(View.VISIBLE);
|
||||
showStartButton(false);
|
||||
|
|
|
@ -694,6 +694,11 @@ public class RoutingController implements TaxiManager.TaxiListener
|
|||
return mLastRouterType == Framework.ROUTER_TYPE_TAXI;
|
||||
}
|
||||
|
||||
boolean isTransitType()
|
||||
{
|
||||
return mLastRouterType == Framework.ROUTER_TYPE_TRANSIT;
|
||||
}
|
||||
|
||||
boolean isVehicleRouterType()
|
||||
{
|
||||
return mLastRouterType == Framework.ROUTER_TYPE_VEHICLE;
|
||||
|
@ -799,6 +804,12 @@ public class RoutingController implements TaxiManager.TaxiListener
|
|||
return mCachedRoutingInfo;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
TransitRouteInfo getCachedTransitInfo()
|
||||
{
|
||||
return mCachedTransitRouteInfo;
|
||||
}
|
||||
|
||||
private void setPointsInternal(@Nullable MapObject startPoint, @Nullable MapObject endPoint)
|
||||
{
|
||||
if (startPoint != null)
|
||||
|
|
|
@ -171,6 +171,14 @@ public class RoutingPlanController extends ToolbarController
|
|||
return;
|
||||
}
|
||||
|
||||
if (isTransitType())
|
||||
{
|
||||
TransitRouteInfo info = RoutingController.get().getCachedTransitInfo();
|
||||
if (info != null)
|
||||
mRoutingBottomMenuController.showTransitInfo(info);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isTaxiRouterType())
|
||||
{
|
||||
mRoutingBottomMenuController.setStartButton();
|
||||
|
@ -243,11 +251,21 @@ public class RoutingPlanController extends ToolbarController
|
|||
return RoutingController.get().isTaxiRouterType();
|
||||
}
|
||||
|
||||
private boolean isTransitType()
|
||||
{
|
||||
return RoutingController.get().isTransitType();
|
||||
}
|
||||
|
||||
public void showTaxiInfo(@NonNull TaxiInfo info)
|
||||
{
|
||||
mRoutingBottomMenuController.showTaxiInfo(info);
|
||||
}
|
||||
|
||||
public void showTransitInfo(@NonNull TransitRouteInfo info)
|
||||
{
|
||||
mRoutingBottomMenuController.showTransitInfo(info);
|
||||
}
|
||||
|
||||
public void showTaxiError(@NonNull TaxiManager.ErrorCode code)
|
||||
{
|
||||
switch (code)
|
||||
|
|
|
@ -2,23 +2,27 @@ package com.mapswithme.maps.routing;
|
|||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents TransitRouteInfo from core.
|
||||
*/
|
||||
public class TransitRouteInfo
|
||||
{
|
||||
@NonNull
|
||||
public final String mTotalDistance;
|
||||
private final String mTotalDistance;
|
||||
@NonNull
|
||||
public final String mTotalDistanceUnits;
|
||||
public final int mTotalTimeInSec;
|
||||
private final String mTotalDistanceUnits;
|
||||
private final int mTotalTimeInSec;
|
||||
@NonNull
|
||||
public final String mTotalPedestrianDistance;
|
||||
private final String mTotalPedestrianDistance;
|
||||
@NonNull
|
||||
public final String mTotalPedestrianDistanceUnits;
|
||||
public final int mTotalPedestrianTimeInSec;
|
||||
private final String mTotalPedestrianDistanceUnits;
|
||||
private final int mTotalPedestrianTimeInSec;
|
||||
@NonNull
|
||||
public final TransitStepInfo[] mSteps;
|
||||
private final TransitStepInfo[] mSteps;
|
||||
|
||||
public TransitRouteInfo(@NonNull String totalDistance, @NonNull String totalDistanceUnits, int totalTimeInSec,
|
||||
@NonNull String totalPedestrianDistance, @NonNull String totalPedestrianDistanceUnits,
|
||||
|
@ -32,4 +36,15 @@ public class TransitRouteInfo
|
|||
mTotalPedestrianTimeInSec = totalPedestrianTimeInSec;
|
||||
mSteps = steps;
|
||||
}
|
||||
}
|
||||
|
||||
int getTotalTime()
|
||||
{
|
||||
return mTotalTimeInSec;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
List<TransitStepInfo> getTransitSteps()
|
||||
{
|
||||
return new ArrayList<>(Arrays.asList(mSteps));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.mapswithme.maps.routing;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TransitStepAdapter extends RecyclerView.Adapter<TransitStepAdapter.TransitStepViewHolder>
|
||||
{
|
||||
@NonNull
|
||||
private List<TransitStepInfo> mItems = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public TransitStepViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
return new TransitStepViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.routing_transit_step_view, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(TransitStepViewHolder holder, int position)
|
||||
{
|
||||
holder.bind(mItems.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
public void setItems(@NonNull List<TransitStepInfo> items)
|
||||
{
|
||||
mItems.clear();
|
||||
mItems.addAll(items);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
static class TransitStepViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private TransitStepView mView;
|
||||
|
||||
TransitStepViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
mView = (TransitStepView) itemView;
|
||||
}
|
||||
|
||||
void bind(@NonNull TransitStepInfo info)
|
||||
{
|
||||
mView.setTransitStepInfo(info);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -116,12 +116,12 @@ public final class UiUtils
|
|||
});
|
||||
}
|
||||
|
||||
public static void hide(View view)
|
||||
public static void hide(@NonNull View view)
|
||||
{
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public static void hide(View... views)
|
||||
public static void hide(@NonNull View... views)
|
||||
{
|
||||
for (final View v : views)
|
||||
v.setVisibility(View.GONE);
|
||||
|
|
Loading…
Add table
Reference in a new issue