package fishrungames.bashgid;

import java.util.ArrayList;

import fishrungames.bashgid.core.HtmlDownloadManager;

import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainPageHListViewAdapters {
	
	
	public static class SimpleElementAdapter extends BaseAdapter {
				
	    private Context mContext;
	    ArrayList<TextFileRecord> localHtmlList;

	    public SimpleElementAdapter(Context c) {
	        mContext = c;	     

	        localHtmlList = HtmlDownloadManager.getInstance().getGlobalHtmlList();
	    }

	    public int getCount() {
	        return localHtmlList.size();
	    }

	    public Object getItem(int position) {
	        return null;
	    }

	    public long getItemId(int position) {
	        return 0;
	    }

	    // create a new ImageView for each item referenced by the Adapter
	    @SuppressLint("InflateParams")
	    public View getView(int position, View convertView, ViewGroup parent) {
	        
	    	
	    	View view;
	        if (convertView == null) {  // if it's not recycled, initialize some attributes
	        	LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        	view = inflater.inflate(R.layout.simple_hview_list_element, null);
	        	
	   
	        } else {
	        	view = convertView;
	        }
	        
	        TextView textView = (TextView) view.findViewById(R.id.textView);
	        
	        TextView subTextView = (TextView) view.findViewById(R.id.subTextView);
	        
	        ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);
	        
	        
	        textView.setText(localHtmlList.get(position).title);
	        
	        subTextView.setText("");
	        
	        ImageManager.getInstance().ApplyImageToImageView(imageButton, localHtmlList.get(position).topicImg);
	        
	        imageButton.setOnClickListener(new ContentButtonOnClickListener(localHtmlList.get(position)));
	        
	        return view;
	    }

	}
	
	
public static class DarkenElementAdapter extends BaseAdapter {
		
	String [] textsArray;
	String [] subTextsArray;
	int [] imgIdArray;
	
    private Context mContext;

    public DarkenElementAdapter(Context c, String [] textsArray, String [] subTextsArray, int [] imgIdArray) {
        mContext = c;
        this.textsArray = textsArray;
        this.subTextsArray = subTextsArray;
        this.imgIdArray = imgIdArray;
        
    }

	    public int getCount() {
	        return textsArray.length;
	    }

	    public Object getItem(int position) {
	        return null;
	    }

	    public long getItemId(int position) {
	        return 0;
	    }

	    // create a new ImageView for each item referenced by the Adapter
	    @SuppressLint("InflateParams")
	    public View getView(int position, View convertView, ViewGroup parent) {
	        
	    	
	    	View view;
	        if (convertView == null) {  // if it's not recycled, initialize some attributes
	        	LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        	view = inflater.inflate(R.layout.darken_hview_list_element, null);
	        	
	   
	        } else {
	        	view = convertView;
	        }
	        
	        TextView textView = (TextView) view.findViewById(R.id.textView);
	        
	        TextView subTextView = (TextView) view.findViewById(R.id.subTextView);

	        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout);
	        
	        textView.setText(textsArray[position]);
	        
	        subTextView.setText(subTextsArray[position]);
	        
	        linearLayout.setBackgroundResource(imgIdArray[position]);
	        
	        return view;
	    }

	}
	
	
public static class ContentButtonOnClickListener implements OnClickListener
{
	
	TextFileRecord contentRecord;
	
	public ContentButtonOnClickListener(TextFileRecord contentRecord)
	{
		this.contentRecord = contentRecord;
	}

	@Override
	public void onClick(View v)
	{
		//MainActivity.getInstance().OpenHtmlViewerScreen(url);
		MainActivity.getInstance().OpenLinkContentScreen(contentRecord);
	}
	
}
	

}
