Пример #1
0
  @Override
  public void bindView(final View view, final Context context, final Cursor cursor) {
    final ViewHolder holder = (ViewHolder) view.getTag();
    final Favori item = mFavoriManager.getSingleFromCursor(cursor);

    if (item.getBackground() == null) {
      final GradientDrawable background =
          ColorUtils.getRoundedGradiant(item.getCouleurBackground());
      item.setBackground(background);
    }

    holder.ligneCode.setText(item.getLettre());
    holder.ligneCode.setBackgroundDrawable(item.getBackground());
    holder.ligneCode.setTextColor(item.getCouleurTexte());

    if (item.getNomFavori() == null) {
      holder.itemTitle.setText(item.getNomArret());
      holder.itemDescription.setText(FormatUtils.formatSens(item.getNomSens()));
    } else {
      holder.itemTitle.setText(item.getNomFavori());
      holder.itemDescription.setText(
          FormatUtils.formatArretSens(item.getNomArret(), item.getNomSens()));
    }

    if (item.getDelay() == null) {
      holder.nextHoraire.setVisibility(View.GONE);
      holder.progressBar.setVisibility(View.VISIBLE);
    } else {
      holder.progressBar.setVisibility(View.GONE);
      holder.nextHoraire.setText(item.getDelay());
      holder.nextHoraire.setVisibility(View.VISIBLE);
    }
  }
  @Override
  public View getView(final int position, final View convertView, final ViewGroup parent) {
    View view = convertView;
    ViewHolder viewHolder;
    if (view == null) {
      view = mLayoutInflater.inflate(R.layout.list_item_leg, parent, false);

      viewHolder = new ViewHolder();
      viewHolder.itemIcon = (ImageView) view.findViewById(R.id.itemIcon);
      viewHolder.itemSymbole = (TextView) view.findViewById(R.id.itemSymbole);
      viewHolder.itemTime = (TextView) view.findViewById(R.id.itemTime);
      viewHolder.itemPlace = (TextView) view.findViewById(R.id.itemPlace);
      viewHolder.itemMetroPoint = view.findViewById(R.id.itemMetroPoint);

      view.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) view.getTag();
    }

    final LegWrapper legWrapper = getItem(position);
    final Ligne ligne = legWrapper.getLigne();
    final Place place = legWrapper.getPlace();

    if ("WALK".equals(legWrapper.getMode())) {

      viewHolder.itemSymbole.setVisibility(View.INVISIBLE);

      if (legWrapper.getType() == Type.IN) {

        final String direction =
            FormatUtils.formatWithDot(legWrapper.getDuration(), legWrapper.getDistance());
        final CharSequence title =
            TextUtils.concat(
                getContext().getString(R.string.itinerary_go_to, place.name) + "\n",
                FormatUtils.formatColorAndSize(getContext(), mSecondaryColor, direction));

        viewHolder.itemIcon.setVisibility(View.VISIBLE);
        viewHolder.itemPlace.setText(title);
      } else {
        viewHolder.itemIcon.setVisibility(View.GONE);
        viewHolder.itemPlace.setText(place.name);
      }

    } else {

      if (legWrapper.getType() == Type.IN) {
        viewHolder.itemPlace.setText(place.name);

        final String direction = FormatUtils.formatSens(legWrapper.getHeadsign());
        final CharSequence title =
            TextUtils.concat(
                place.name + "\n",
                FormatUtils.formatColorAndSize(getContext(), mSecondaryColor, direction));

        viewHolder.itemPlace.setText(title);
      } else {
        viewHolder.itemPlace.setText(place.name);
      }

      if (ligne != null) {
        viewHolder.itemIcon.setVisibility(View.GONE);
        viewHolder.itemSymbole.setVisibility(View.VISIBLE);

        viewHolder.itemSymbole.setText(ligne.getLettre());
        viewHolder.itemSymbole.setTextColor(ligne.getCouleurTexte());
        viewHolder.itemSymbole.setBackgroundDrawable(ColorUtils.getCircle(ligne.getCouleur()));
      } else {
        viewHolder.itemIcon.setVisibility(View.INVISIBLE);
        viewHolder.itemSymbole.setVisibility(View.INVISIBLE);
      }
    }

    if (legWrapper.isTrip()) {
      if (legWrapper.getType() == Type.IN) {
        viewHolder.itemMetroPoint.setBackgroundResource(R.drawable.ic_arret_first_silver);
      } else {
        viewHolder.itemMetroPoint.setBackgroundResource(R.drawable.ic_arret_last_silver);
      }
      viewHolder.itemMetroPoint.setVisibility(View.VISIBLE);
    } else {
      viewHolder.itemMetroPoint.setVisibility(View.GONE);
    }

    viewHolder.itemTime.setText(legWrapper.getTime());

    return view;
  }