package BWP.widget;

import java.util.List;
import java.util.Map;

import org.forks.jsonrpc.RpcFacade;

import BWP.MobileSale.R;
import android.R.bool;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class SelectSimpleAdapter extends SimpleAdapter {
	
	int mSelectedPosition=-1;
	boolean isOrNotShowSecond;
	public void setSelect(int position){
		mSelectedPosition = position;
	}

	public SelectSimpleAdapter(Context context,
			List<? extends Map<String, ?>> data, int resource, String[] from,
			int[] to) {
		super(context, data, resource, from, to);
		String method = "/Sale/Sale/Rpcs/MobileOrderRpc/CheckIsOrNotShowSecond";
		isOrNotShowSecond = RpcFacade.rpcCall(method);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.i("SelectSimpleAdapter",String.format("position:%s",position));
		
		Log.i("SelectSimpleAdapter", String.format("view:%s", convertView));
		
		View result = super.getView(position, convertView, parent);
		if(!isOrNotShowSecond){
			TextView aaTextView = (TextView)result.findViewById(R.id.SecondNumber);
			if(aaTextView!=null){
			aaTextView.setVisibility(View.INVISIBLE);
			}
		}
		SetBackground(position,result);
		return result;
	}

	private void SetBackground(int position, View convertView) {
		if(convertView == null){
			return;
		}
		if(position == mSelectedPosition){
			convertView.setBackgroundColor(Color.DKGRAY);
		}else{
			convertView.setBackgroundColor(Color.TRANSPARENT);
		}
		
	}
	
	

}
