[android] Supported rutaxi in interface

This commit is contained in:
Dmitry Donskoy 2018-09-19 15:11:04 +03:00 committed by Aleksandr Zatsepin
parent 596fa3c1a3
commit 87df122743
12 changed files with 99 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -92,4 +92,5 @@
<string name="pref_opt_out_mopub" translatable="false">pref_opt_out_mopub</string>
<string name="pref_opt_out_flurry" translatable="false">pref_opt_out_flurry</string>
<string name="rutaxi_title" translatable="false">RuTaxi</string>
</resources>

View file

@ -0,0 +1,13 @@
package com.mapswithme.maps.taxi;
import android.support.annotation.NonNull;
class DefaultFormatPriceStrategy implements FormatPriceStrategy
{
@NonNull
@Override
public String format(@NonNull TaxiInfo.Product product)
{
return product.getPrice();
}
}

View file

@ -0,0 +1,9 @@
package com.mapswithme.maps.taxi;
import android.support.annotation.NonNull;
interface FormatPriceStrategy
{
@NonNull
String format(@NonNull TaxiInfo.Product product);
}

View file

@ -0,0 +1,15 @@
package com.mapswithme.maps.taxi;
import android.support.annotation.NonNull;
import com.mapswithme.util.Utils;
class LocaleDependentFormatPriceStrategy implements FormatPriceStrategy
{
@NonNull
@Override
public String format(@NonNull TaxiInfo.Product product)
{
return Utils.formatCurrencyString(product.getPrice(), product.getCurrency());
}
}

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import java.util.List;
@ -53,35 +54,21 @@ public class TaxiAdapter extends PagerAdapter
String separator;
// We ignore all Yandex.Taxi product names until they do support of passing product parameters
// to their app via deeplink.
if (mType == TaxiType.YANDEX || mType == TaxiType.MAXIM)
{
name.setText(mType.getTitle());
separator = " • ~";
}
else
{
name.setText(product.getName());
separator = "";
}
TextView timeAndPrice = (TextView) v.findViewById(R.id.arrival_time_price);
boolean isApproxPrice = mType.isApproximatePrice();
name.setText(isApproxPrice ? mContext.getString(mType.getTitle()) : product.getName());
separator = UiUtils.PHRASE_SEPARATOR + (isApproxPrice ? UiUtils.APPROXIMATE_SYMBOL : "");
TextView timeAndPriceView = (TextView) v.findViewById(R.id.arrival_time_price);
int time = Integer.parseInt(product.getTime());
CharSequence waitTime = RoutingController.formatRoutingTime(mContext, time,
R.dimen.text_size_body_3);
timeAndPrice.setText(mContext.getString(R.string.taxi_wait, waitTime + separator
+ formatPrice(product)));
String formattedPrice = mType.getFormatPriceStrategy().format(product);
String timeAndPriceValue = waitTime + separator + formattedPrice;
String timeAndPrice = mContext.getString(mType.getWaitingTemplateResId(), timeAndPriceValue);
timeAndPriceView.setText(timeAndPrice);
container.addView(v, 0);
return v;
}
@NonNull
private String formatPrice(@NonNull TaxiInfo.Product product)
{
if (mType == TaxiType.YANDEX)
return Utils.formatCurrencyString(product.getPrice(), product.getCurrency());
// For Uber and Maxim we don't do formatting, because Uber and Maxim does it on its side.
return product.getPrice();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{

View file

@ -7,6 +7,11 @@ import android.support.annotation.StringRes;
import com.mapswithme.maps.R;
import com.mapswithme.util.Utils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
public enum TaxiType
{
UBER
@ -41,7 +46,7 @@ public enum TaxiType
return "Uber";
}
},
YANDEX
YANDEX(new LocaleDependentFormatPriceStrategy())
{
@NonNull
public String getPackageName()
@ -105,7 +110,7 @@ public enum TaxiType
return "Maxim";
}
},
RUTAXI
RUTAXI(R.string.place_page_starting_from, new LocaleDependentFormatPriceStrategy())
{
@NonNull
public String getPackageName()
@ -122,13 +127,13 @@ public enum TaxiType
@DrawableRes
public int getIcon()
{
return R.drawable.ic_taxi_logo_maksim;
return R.drawable.ic_taxi_logo_rutaxi;
}
@StringRes
public int getTitle()
{
return R.string.maxim_taxi_title;
return R.string.rutaxi_title;
}
@NonNull
@ -138,6 +143,30 @@ public enum TaxiType
}
};
private static final Collection<TaxiType> APPROXIMATE_PRICE_TAXI_TYPES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(YANDEX, MAXIM, RUTAXI)));
@StringRes
private final int mWaitingTemplateResId;
@NonNull
private final FormatPriceStrategy mFormatPriceStrategy;
TaxiType(@StringRes int waitingTemplateResId, @NonNull FormatPriceStrategy strategy)
{
mWaitingTemplateResId = waitingTemplateResId;
mFormatPriceStrategy = strategy;
}
TaxiType(@NonNull FormatPriceStrategy strategy)
{
this(R.string.taxi_wait, strategy);
}
TaxiType()
{
this(R.string.taxi_wait, new DefaultFormatPriceStrategy());
}
@NonNull
public abstract String getPackageName();
@ -152,4 +181,22 @@ public enum TaxiType
@NonNull
public abstract String getProviderName();
@StringRes
public int getWaitingTemplateResId()
{
return mWaitingTemplateResId;
}
public boolean isApproximatePrice()
{
return APPROXIMATE_PRICE_TAXI_TYPES.contains(this);
}
// For Uber and Maxim we don't do formatting, because Uber and Maxim does it on its side.
@NonNull
public FormatPriceStrategy getFormatPriceStrategy()
{
return mFormatPriceStrategy;
}
}

View file

@ -46,6 +46,7 @@ public final class UiUtils
private static final int DEFAULT_TINT_COLOR = Color.parseColor("#20000000");
public static final int NO_ID = -1;
public static final String PHRASE_SEPARATOR = "";
public static final String APPROXIMATE_SYMBOL = "~";
private static float sScreenDensity;
public static void addStatusBarOffset(@NonNull View view)