package com.arjunalabs.parallaxlistviewitem.app;

import android.content.Context;
import android.graphics.Matrix;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by bobbyadiprabowo on 6/3/14.
 */
public class ImageListAdapter extends BaseAdapter {

    private Context context;

    public ImageListAdapter(Context context) {
        super();
        this.context = context;
    }

    @Override
    public int getCount() {
        return 20;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(this.context).inflate(R.layout.item, null, false);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
            TextView textView = (TextView) convertView.findViewById(R.id.text);
            imageView.setScaleType(ImageView.ScaleType.MATRIX);
            Matrix matrix = imageView.getImageMatrix();
            matrix.postTranslate(0, -100);
            imageView.setImageMatrix(matrix);
            if (position % 2 == 0) {
                imageView.setImageResource(R.drawable.lorempixel2);
            } else if (position % 3 == 0) {
                imageView.setImageResource(R.drawable.lorempixel3);
            } else {
                imageView.setImageResource(R.drawable.lorempixel);
            }
            viewHolder = new ViewHolder();
            viewHolder.imageView = imageView;
            viewHolder.textView = textView;
            convertView.setTag(viewHolder);
        }
        viewHolder = (ViewHolder) convertView.getTag();
        Matrix matrix = viewHolder.imageView.getImageMatrix();
        matrix.reset();
        matrix.postTranslate(0, -100);
        viewHolder.imageView.setImageMatrix(matrix);
        viewHolder.textView.setText("Row "+ position);
        return convertView;
    }

    static class ViewHolder {
        ImageView imageView;
        TextView textView;
    }

}

@@ -1278,153 +1278,8 @@
 X);%0A
-            Matrix matrix = imageView.getImageMatrix();%0A            matrix.postTranslate(0, -100);%0A            imageView.setImageMatrix(matrix);%0A
     
@@ -1303,32 +1303,32 @@
 ion %25 2 == 0) %7B%0A
+
                 
@@ -1585,32 +1585,177 @@
 ;%0A            %7D%0A
+            Matrix matrix = imageView.getImageMatrix();%0A            matrix.postTranslate(0, -100);%0A            imageView.setImageMatrix(matrix);%0A
             view
@@ -1917,32 +1917,32 @@
 der);%0A        %7D%0A
+
         viewHold
@@ -1985,187 +1985,8 @@
 ();%0A
-        Matrix matrix = viewHolder.imageView.getImageMatrix();%0A        matrix.reset();%0A        matrix.postTranslate(0, -100);%0A        viewHolder.imageView.setImageMatrix(matrix);%0A
     

update to fix glitch