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

UGCRatingRecordsAdapter.java « ugc « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4f3ec2f0ae1c13e6f7bfa752d9c4a9b2ed2db82 (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
package com.mapswithme.maps.ugc;

import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.util.Utils;

import java.util.ArrayList;
import java.util.List;

class UGCRatingRecordsAdapter extends RecyclerView.Adapter<UGCRatingRecordsAdapter.ViewHolder>
{
  @NonNull
  private ArrayList<UGC.Rating> mItems = new ArrayList<>();

  @Override
  public UGCRatingRecordsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
  {
    return new UGCRatingRecordsAdapter.ViewHolder(LayoutInflater.from(parent.getContext())
                                                                .inflate(R.layout.item_ugc_rating_record, parent, false));
  }

  @Override
  public void onBindViewHolder(UGCRatingRecordsAdapter.ViewHolder holder, int position)
  {
    holder.bind(mItems.get(position));
  }

  @Override
  public int getItemCount()
  {
    return mItems.size();
  }

  public void setItems(@NonNull List<UGC.Rating> items)
  {
    this.mItems.clear();
    this.mItems.addAll(items);
    notifyDataSetChanged();
  }

  static class ViewHolder extends RecyclerView.ViewHolder
  {
    @NonNull
    final TextView mName;
    @NonNull
    final RatingBar mBar;

    public ViewHolder(View itemView)
    {
      super(itemView);
      mName = (TextView) itemView.findViewById(R.id.name);
      mBar = (RatingBar) itemView.findViewById(R.id.rating);
    }

    public void bind(UGC.Rating rating)
    {
      @StringRes
      int nameId = Utils.getStringIdByKey(mName.getContext(), rating.getName());
      if (nameId != Utils.INVALID_ID)
        mName.setText(nameId);
      mBar.setRating(rating.getValue());
    }
  }
}