/*
 * Copyright (c) 2011 Kurt Aaholst <kaaholst@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.org.ngo.squeezer.itemlists;

import uk.org.ngo.squeezer.R;
import uk.org.ngo.squeezer.framework.SqueezerBaseListActivity;
import uk.org.ngo.squeezer.model.SqueezerPlugin;
import uk.org.ngo.squeezer.service.ISqueezeService;
import uk.org.ngo.squeezer.util.ImageFetcher;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public abstract class SqueezerPluginView extends SqueezerIconicItemView<SqueezerPlugin> {
    public SqueezerPluginView(SqueezerBaseListActivity<SqueezerPlugin> activity) {
		super(activity);
	}

    public View getAdapterView(View convertView, SqueezerPlugin item, ImageFetcher imageFetcher) {
		ViewHolder viewHolder;

		if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater().inflate(R.layout.icon_large_row_layout, null);
			viewHolder = new ViewHolder();
			viewHolder.label = (TextView) convertView.findViewById(R.id.label);
			viewHolder.icon = (ImageView) convertView.findViewById(R.id.icon);
			convertView.setTag(viewHolder);
		} else
			viewHolder = (ViewHolder) convertView.getTag();

		viewHolder.label.setText(item.getName());
        imageFetcher.loadThumbnailImage(getIconUrl(item.getIcon()), viewHolder.icon,
                ICON_PENDING_ARTWORK);

		return convertView;
	}

	private String getIconUrl(String icon) {
		if (icon == null) return null;

		ISqueezeService service = getActivity().getService();
		if (service == null) return null;

		try {
			return service.getIconUrl(icon);
		} catch (RemoteException e) {
			Log.e(getClass().getSimpleName(), "Error requesting icon url: " + e);
			return null;
		}
	}

	private static class ViewHolder {
		TextView label;
		ImageView icon;
	}

}

@@ -1244,16 +1244,30 @@
 y);%0A%09%7D%0A%0A
+    @Override%0A
     publ
@@ -1383,18 +1383,24 @@
 older;%0A%0A
-%09%09
+        
 if (conv
@@ -1446,16 +1446,94 @@
  == null
+%0A                %7C%7C !ViewHolder.class.isAssignableFrom(convertView.getClass())
 ) %7B%0A    
@@ -1835,16 +1835,24 @@
 r);%0A
-%09%09
+        
 %7D else
+ %7B
 %0A%09%09%09
@@ -1898,16 +1898,26 @@
 etTag();
+%0A        %7D
 %0A%0A%09%09view

Make sure that convertView is a suitable type.