package org.lee.android.simples.unionlist.view;

import org.lee.android.simples.unionlist.R;
import org.lee.android.simples.unionlist.mode.Bean;
import org.lee.android.volley.VolleyLoader;
import org.lee.android.widget.UnionView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;

public class TwoUnionView extends UnionView<Bean> {

	public TwoUnionView(Context context) {
		super(context);
		init();
	}

	public TwoUnionView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TwoUnionView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	private void init() {
		setPadding(4, 4, 4, 4);
		setOrientation(LinearLayout.HORIZONTAL);

	}

	@Override
	protected void onCreateItemView(View child, int position) {
		ChildViewBuffer viewHolder = new ChildViewBuffer(child);
		child.setTag(viewHolder);
	}

	@Override
	protected void setItem(View v, Bean bean) {
		ChildViewBuffer viewHolder = (ChildViewBuffer) v.getTag();
		viewHolder.setItem(bean);
	}

	private class ChildViewBuffer {

		private NetworkImageView mImageView;
		private TextView mTitleText;
		private TextView mNumText;
		private Bean mItem;

		ChildViewBuffer(View v) {
			mImageView = (NetworkImageView) v.findViewById(R.id.ImageView);
			mImageView.setErrorImageResId(R.drawable.logo);
			mTitleText = (TextView) v.findViewById(R.id.Title);
			mNumText = (TextView) v.findViewById(R.id.Num);
		}

		public void setItem(Bean item) {
			mItem = item;
			attachToView();
		}

		private void attachToView() {
			mImageView.setImageUrl(mItem.Url, VolleyLoader.getInstance()
					.getImageLoader());
			mTitleText.setText(mItem.Title);
			mNumText.setText(mItem.Num);
		}

	}

}

@@ -290,16 +290,41 @@
 uteSet;%0A
+import android.util.Log;%0A
 import a
@@ -440,32 +440,241 @@
 ley.
-toolbox.NetworkImageView
+VolleyError;%0Aimport com.android.volley.toolbox.ImageLoader;%0Aimport com.android.volley.toolbox.ImageLoader.ImageListener;%0Aimport com.android.volley.toolbox.NetworkImageView;%0Aimport com.android.volley.toolbox.ImageLoader.ImageContainer
 ;%0A%0Ap
@@ -1582,16 +1582,92 @@
 n mItem;
+%0A%09%09private ImageLoader iImageLoader;%0A%09%09private ImageListener iImageListener;
 %0A%0A%09%09Chil
@@ -1908,24 +1908,412 @@
 (R.id.Num);%0A
+%09%09%09iImageLoader = VolleyLoader.getInstance().getImageLoader();%0A%09%09%09iImageListener = new ImageListener() %7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void onErrorResponse(VolleyError error) %7B%0A%09%09%09%09%09Log.d(%22TAG%22, %22onErrorResponse():%22 + error);%0A%0A%09%09%09%09%7D%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void onResponse(ImageContainer response,%0A%09%09%09%09%09%09boolean isImmediate) %7B%0A%09%09%09%09%09Log.d(%22TAG%22, %22onResponse():%22 + isImmediate);%0A%0A%09%09%09%09%7D%0A%09%09%09%7D;%0A
 %09%09%7D%0A%0A%09%09publi
@@ -2420,78 +2420,91 @@
 %0A%09%09%09
-m
+i
 Image
-View.setImageUrl(mItem.Url, VolleyLoader.getInstance()%0A%09%09%09%09%09.get
+Loader.get(mItem.Url, iImageListener);%0A%09%09%09mImageView.setImageUrl(mItem.Url, i
 Imag
@@ -2510,18 +2510,16 @@
 geLoader
-()
 );%0A%09%09%09mT
@@ -2585,15 +2585,14 @@
 m);%0A%09%09%7D%0A
-%0A
 %09%7D%0A%0A%7D%0A

add ImageLoader.