package ondemandmbile.crypto_assistant;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.DecimalFormat;

import io.realm.RealmResults;
import ondemandmbile.crypto_assistant.models.Currency;

 * Created by robertnyangate on 18/05/2017.

public class MarketAdapter extends RecyclerView.Adapter {
    private static final String TAG = "BambaAdapter";
    private Context context;
    private LayoutInflater layoutInflater;
    RealmResults<Currency> conversions;
    public MarketAdapter(Context context, RealmResults<Currency>conversions) {
        try {
            this.context = context;
            layoutInflater = LayoutInflater.from(context);
        } catch (Exception e) {


    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        public TextView name, buy,sell;
        public CardView card_view;

        public ViewHolder(View convertView) {
            name = (TextView) convertView.findViewById(;
            card_view = (CardView) convertView.findViewById(;
            buy = (TextView) convertView.findViewById(;
            sell = (TextView) convertView.findViewById(;



    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.convertions_adapter, parent, false);
        // set the view's size, margins, paddings and layout parameters
        ViewHolder vh = new ViewHolder(v);
        return vh;

    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        final Currency competitor=conversions.get(position);
        DecimalFormat decimalFormat=new DecimalFormat("#,###.##");
        ((ViewHolder)holder).buy.setText(competitor.getSymbol()+" "+decimalFormat.format
        ((ViewHolder)holder).sell.setText(competitor.getSymbol()+" "+decimalFormat.format


    public int getItemViewType(int position) {
        return super.getItemViewType(position);

    public long getItemId(int i) {
        return i;

     * Returns the total number of items in the data set hold by the adapter.
     * @return The total number of items in this adapter.
    public int getItemCount() {
        return conversions.size();