Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TaxiAdapter.java « taxi « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3cf9dd55edc363bdd0ec4d1b88c26852b995cad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.mapswithme.maps.taxi;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.util.UiUtils;

import java.util.List;

public class TaxiAdapter extends PagerAdapter
{
  @NonNull
  private final Context mContext;
  @NonNull
  private final List<TaxiInfo.Product> mProducts;
  @NonNull
  private final TaxiType mType;

  public TaxiAdapter(@NonNull Context context, @NonNull TaxiType type,
                     @NonNull List<TaxiInfo.Product> products)
  {
    mContext = context;
    mType = type;
    mProducts = products;
  }

  @Override
  public int getCount()
  {
    return mProducts.size();
  }

  @Override
  public boolean isViewFromObject(View view, Object object)
  {
    return view == object;
  }

  @Override
  public Object instantiateItem(ViewGroup container, int position)
  {
    TaxiInfo.Product product = mProducts.get(position);

    View v = LayoutInflater.from(mContext).inflate(R.layout.taxi_pager_item, container, false);
    TextView name = (TextView) v.findViewById(R.id.product_name);
    boolean isApproxPrice = mType.isPriceApproximated();
    name.setText(isApproxPrice ? mContext.getString(mType.getTitle()) : product.getName());
    String 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);
    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;
  }

  @Override
  public void destroyItem(ViewGroup container, int position, Object object)
  {
    container.removeView((View) object);
  }
}