package fr.tvbarthel.apps.cameracolorpicker.adapters;

import android.content.Context;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import fr.tvbarthel.apps.cameracolorpicker.R;
import fr.tvbarthel.apps.cameracolorpicker.data.ColorItem;

/**
 * TODO comment.
 */
public class ColorAdapter extends ArrayAdapter<ColorItem> {

    public ColorAdapter(Context context) {
        super(context, R.layout.row_color_item);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (view == null) {
            view = createView(parent);
        }

        final ViewHolder viewHolder = (ViewHolder) view.getTag();
        bindViewHolder(viewHolder, position);

        return view;
    }

    protected View createView(ViewGroup parent) {
        final View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.row_color_item, parent, false);
        final ViewHolder viewHolder = new ViewHolder(view);
        view.setTag(viewHolder);
        return view;
    }

    protected void bindViewHolder(ViewHolder viewHolder, int position) {
        final int color = getItem(position).getColor();
        viewHolder.mColorPreview.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        viewHolder.mColorText.setText(Integer.toHexString(color));
    }

    private static class ViewHolder {
        public View mColorPreview;
        public TextView mColorText;

        public ViewHolder(View view) {
            mColorPreview = view.findViewById(R.id.row_color_item_preview);
            mColorText = (TextView) view.findViewById(R.id.row_color_item_text);
        }
    }
}

@@ -1307,17 +1307,27 @@
 nal 
-int
+ColorItem
  color
+Item
  = g
@@ -1346,19 +1346,8 @@
 ion)
-.getColor()
 ;%0A  
@@ -1413,16 +1413,31 @@
 er(color
+Item.getColor()
 , Porter
@@ -1499,18 +1499,21 @@
 ext(
-Integer.to
+colorItem.get
 HexS
@@ -1518,21 +1518,16 @@
 xString(
-color
 ));%0A    

Use the hexadecimal representation in the ColorAdapter class