package com.lianxin.pubqq.activity;
import java.util.List;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Toast;
import com.lianxin.pubqq.R;
import com.lianxin.pubqq.activity.adpter.MytypeListAdapter;
import com.lianxin.pubqq.activity.adpter.MytypeListAdapter.OnMyButClickListener;
import com.lianxin.panqq.edit.AskJoinDialog;
import com.lianxin.panqq.common.BaseActivity;
import com.lianxin.panqq.common.DefineUser;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.list.bean.EMGroup;
import com.lianxin.panqq.client.callback.listCallBack;
import com.lianxin.panqq.common.bean.AskInfo;
import com.lianxin.panqq.list.ExMytypeList;

//我的分类列表
public class MytypeListActivity extends BaseActivity implements OnClickListener {
	private ImageView img_back, img_right;     
	private MytypeListAdapter mAdapter;
	private List<EMGroup> typeList;//搜索用户列表
	private ExMytypeList mListView;	
	
	private int groupType = DefineUser.TYPE_CROWD;		

    @Override
   	public void onCreate(Bundle savedInstanceState) {
      	 
   		super.onCreate(savedInstanceState);
   		setContentView(R.layout.activity_mytypelist);
		img_back = (ImageView) findViewById(R.id.img_back); 		
		img_back.setOnClickListener(this);   		
		mListView = (ExMytypeList)findViewById(R.id.user_xListView);
		mListView.setPullLoadEnable(true);

		groupType = getIntent().getIntExtra("TypeType", DefineUser.TYPE_CROWD);
	//	groupId = getIntent().getIntExtra("TypeID", 10001);	
		mListView.setType(groupType);		
	//	initData();		 
		mAdapter =  new MytypeListAdapter(this, typeList);
		mListView.setAdapter(mAdapter);
		mListView.setDataAdapter(typeList,mAdapter);		
		mListView.setStatusListener(new listCallBack(){
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
		
			}
			@Override
			public void onFailure(int errorCode, String errorMessage) {
				// TODO Auto-generated method stub
				
			}
		});		
		
		mListView.initData(); //初始化数据(视图初始化所需要的)		
	//	mListView.setXListViewListener(this);
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v, int position,
					long id) {
	            Toast.makeText(context, "I am ", Toast.LENGTH_SHORT).show(); 				
				//Intent intent = new Intent(getActivity(), Userinfo.class);
				Intent intent = new Intent(MytypeListActivity.this, MytypeInfoActivity.class);				
		//		intent.putExtra("userId", mAdapter.getItem(position).getName());
				EMGroup typeInfo = mAdapter.getItem(position-1);	

				intent.putExtra("TypeID", typeInfo.getId());
				intent.putExtra("TypeType", groupType);			
				intent.putExtra("TypeName", typeInfo.getName());
				intent.putExtra("Info_UserId", typeInfo.getId());
				intent.putExtra("Info_NickName", typeInfo.getName());
			//	intent.putExtra("Info_Image", person.imageid);
				intent.putExtra("Info_Image",1);			
				intent.putExtra("Info_Power", typeInfo.mypower);
				intent.putExtra("Info_Index", typeInfo.index);				
				startActivity(intent);			}
			
		});

		mAdapter.setButListener(new OnMyButClickListener(){  
			@Override
			public void onButClicked(int position) {
				// TODO Auto-generated method stub
				onItemButtonClick(position);						
			}  
        });	
		mListView.resetData();	//刷新远程数据		
    }
 
	@Override
	public void onClick(View v) {

		int id = v.getId();
		if (id == R.id.img_back) {
			Utils.finish(MytypeListActivity.this);
			//finish();
			//overridePendingTransition(R.anim.push_right_in,
			//		R.anim.push_right_out);
		} else if (id == R.id.img_right) {
		}
	}     
    
	public void onItemButtonClick(int position) {
		// TODO Auto-generated method stub
		EMGroup groupInfo = mAdapter.getItem(position);
		int nGroupId = groupInfo.getId();
		String strGroupName = groupInfo.getName();			
		int image = groupInfo.imageid;		
		AskInfo uinfo = new AskInfo(nGroupId,strGroupName,image);			
		new AskJoinDialog(MytypeListActivity.this,uinfo,
				new AskJoinDialog.OnSetListener() {
					@Override
					public void onSelect(AskInfo askInfo) {
					//	joinGroup(askInfo);
					}
				}).show();
    }	    

}
 