// Path: src/com/example/lovetalk/service/AddRequestService.java
// public class AddRequestService {
// 	public static int countAddRequests() throws AVException {
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
// 		q.whereEqualTo(AddRequest.TO_USER, AVUser.getCurrentUser());
// 		try {
// 			return q.count();
// 		} catch (AVException e) {
// 			if (e.getCode() == AVException.CACHE_MISS) {
// 				return 0;
// 			} else {
// 				throw e;
// 			}
// 		}
// 	}
// 
// 	public static List<AddRequest> findAddRequests() throws AVException {
// 		AVUser user = AVUser.getCurrentUser();
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.include(AddRequest.FROM_USER);
// 		q.whereEqualTo(AddRequest.TO_USER, user);
// 		q.orderByDescending("createdAt");
// 		q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
// 		return q.find();
// 	}
// 
// 	public static boolean hasAddRequest() throws AVException {
// 		PreferenceMap preferenceMap = PreferenceMap.getMyPrefDao(DemoApplication.context);
// 		int addRequestN = preferenceMap.getAddRequestN();
// 		int requestN = countAddRequests();
// 		if (requestN > addRequestN) {
// 			return true;
// 		} else {
// 			return false;
// 		}
// 	}
// 
// 	public static void agreeAddRequest(final AddRequest addRequest, final SaveCallback saveCallback) {
// 		UserService.addFriend(addRequest.getFromUser().getObjectId(), new SaveCallback() {
// 			@Override
// 			public void done(AVException e) {
// 				if (e != null) {
// 					if (e.getCode() == AVException.DUPLICATE_VALUE) {
// 						addRequest.setStatus(AddRequest.STATUS_DONE);
// 						addRequest.saveInBackground(saveCallback);
// 					} else {
// 						saveCallback.done(e);
// 					}
// 				} else {
// 					addRequest.setStatus(AddRequest.STATUS_DONE);
// 					addRequest.saveInBackground(saveCallback);
// 				}
// 			}
// 		});
// 	}
// 
// 	public static void createAddRequest(AVUser toUser) throws Exception {
// 		AVUser curUser = AVUser.getCurrentUser();
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.whereEqualTo(AddRequest.FROM_USER, curUser);
// 		q.whereEqualTo(AddRequest.TO_USER, toUser);
// 		q.whereEqualTo(AddRequest.STATUS, AddRequest.STATUS_WAIT);
// 		int count = 0;
// 		try {
// 			count = q.count();
// 		} catch (AVException e) {
// 			e.printStackTrace();
// 			if (e.getCode() == AVException.OBJECT_NOT_FOUND) {
// 				count = 0;
// 			} else {
// 				throw e;
// 			}
// 		}
// 		if (count > 0) {
// 			throw new Exception(DemoApplication.context.getString(R.string.contact_alreadyCreateAddRequest));
// 		} else {
// 			AddRequest add = new AddRequest();
// 			add.setFromUser(curUser);
// 			add.setToUser(toUser);
// 			add.setStatus(AddRequest.STATUS_WAIT);
// 			add.save();
// 		}
// 	}
// 
// 	public static void createAddRequestInBackground(Context ctx, final AVUser user) {
// 		new MyAsyncTask(ctx) {
// 			@Override
// 			protected void doInBack() throws Exception {
// 				AddRequestService.createAddRequest(user);
// 			}
// 
// 			@Override
// 			protected void onSucceed() {
// 				Utils.toast(R.string.contact_sendRequestSucceed);
// 			}
// 		}.execute();
// 	}
// }
// 
// Path: src/com/example/lovetalk/view/ViewHolder.java
// public class ViewHolder {
// 	public static <T extends View> T findViewById(View view, int id) {
// 		SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
// 		if (viewHolder == null) {
// 			viewHolder = new SparseArray<View>();
// 			view.setTag(viewHolder);
// 		}
// 		View childView = viewHolder.get(id);
// 		if (childView == null) {
// 			childView = view.findViewById(id);
// 			viewHolder.put(id, childView);
// 		}
// 		return (T) childView;
// 	}
// }


import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.avos.avoscloud.AVUser;
import com.example.lovetalk.R;
import com.example.lovetalk.service.AddRequestService;
import com.example.lovetalk.view.ViewHolder;
import java.util.List;
package com.example.lovetalk.adapter;




public class AddFriendAdapter extends BaseListAdapter<AVUser> {
	Context mContext;

	public AddFriendAdapter(Context context, List<AVUser> list) {
		super(context, list);
		// TODO Auto-generated constructor stub
		mContext = context;
	}

	@Override
	public View getView(int position, View conView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (conView == null) {
			conView = inflater.inflate(R.layout.contact_add_friend_item, null);
		}
		final AVUser user = datas.get(position);
		TextView nameView = ViewHolder.findViewById(conView, R.id.name);
		ImageView avatarView = ViewHolder.findViewById(conView, R.id.avatar);
		Button addBtn = ViewHolder.findViewById(conView, R.id.add);
//    String avatarUrl = contact.getAvatarUrl();
//    UserService.displayAvatar(avatarUrl, avatarView);
		nameView.setText(user.getUsername());
		addBtn.setText(R.string.add);
		addBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
// Path: src/com/example/lovetalk/service/AddRequestService.java
// public class AddRequestService {
// 	public static int countAddRequests() throws AVException {
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
// 		q.whereEqualTo(AddRequest.TO_USER, AVUser.getCurrentUser());
// 		try {
// 			return q.count();
// 		} catch (AVException e) {
// 			if (e.getCode() == AVException.CACHE_MISS) {
// 				return 0;
// 			} else {
// 				throw e;
// 			}
// 		}
// 	}
// 
// 	public static List<AddRequest> findAddRequests() throws AVException {
// 		AVUser user = AVUser.getCurrentUser();
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.include(AddRequest.FROM_USER);
// 		q.whereEqualTo(AddRequest.TO_USER, user);
// 		q.orderByDescending("createdAt");
// 		q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
// 		return q.find();
// 	}
// 
// 	public static boolean hasAddRequest() throws AVException {
// 		PreferenceMap preferenceMap = PreferenceMap.getMyPrefDao(DemoApplication.context);
// 		int addRequestN = preferenceMap.getAddRequestN();
// 		int requestN = countAddRequests();
// 		if (requestN > addRequestN) {
// 			return true;
// 		} else {
// 			return false;
// 		}
// 	}
// 
// 	public static void agreeAddRequest(final AddRequest addRequest, final SaveCallback saveCallback) {
// 		UserService.addFriend(addRequest.getFromUser().getObjectId(), new SaveCallback() {
// 			@Override
// 			public void done(AVException e) {
// 				if (e != null) {
// 					if (e.getCode() == AVException.DUPLICATE_VALUE) {
// 						addRequest.setStatus(AddRequest.STATUS_DONE);
// 						addRequest.saveInBackground(saveCallback);
// 					} else {
// 						saveCallback.done(e);
// 					}
// 				} else {
// 					addRequest.setStatus(AddRequest.STATUS_DONE);
// 					addRequest.saveInBackground(saveCallback);
// 				}
// 			}
// 		});
// 	}
// 
// 	public static void createAddRequest(AVUser toUser) throws Exception {
// 		AVUser curUser = AVUser.getCurrentUser();
// 		AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
// 		q.whereEqualTo(AddRequest.FROM_USER, curUser);
// 		q.whereEqualTo(AddRequest.TO_USER, toUser);
// 		q.whereEqualTo(AddRequest.STATUS, AddRequest.STATUS_WAIT);
// 		int count = 0;
// 		try {
// 			count = q.count();
// 		} catch (AVException e) {
// 			e.printStackTrace();
// 			if (e.getCode() == AVException.OBJECT_NOT_FOUND) {
// 				count = 0;
// 			} else {
// 				throw e;
// 			}
// 		}
// 		if (count > 0) {
// 			throw new Exception(DemoApplication.context.getString(R.string.contact_alreadyCreateAddRequest));
// 		} else {
// 			AddRequest add = new AddRequest();
// 			add.setFromUser(curUser);
// 			add.setToUser(toUser);
// 			add.setStatus(AddRequest.STATUS_WAIT);
// 			add.save();
// 		}
// 	}
// 
// 	public static void createAddRequestInBackground(Context ctx, final AVUser user) {
// 		new MyAsyncTask(ctx) {
// 			@Override
// 			protected void doInBack() throws Exception {
// 				AddRequestService.createAddRequest(user);
// 			}
// 
// 			@Override
// 			protected void onSucceed() {
// 				Utils.toast(R.string.contact_sendRequestSucceed);
// 			}
// 		}.execute();
// 	}
// }
// 
// Path: src/com/example/lovetalk/view/ViewHolder.java
// public class ViewHolder {
// 	public static <T extends View> T findViewById(View view, int id) {
// 		SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
// 		if (viewHolder == null) {
// 			viewHolder = new SparseArray<View>();
// 			view.setTag(viewHolder);
// 		}
// 		View childView = viewHolder.get(id);
// 		if (childView == null) {
// 			childView = view.findViewById(id);
// 			viewHolder.put(id, childView);
// 		}
// 		return (T) childView;
// 	}
// }


// Path: src/com/example/lovetalk/adapter/AddFriendAdapter.java
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.avos.avoscloud.AVUser;
import com.example.lovetalk.R;
import com.example.lovetalk.service.AddRequestService;
import com.example.lovetalk.view.ViewHolder;
import java.util.List;

package com.example.lovetalk.adapter;




public class AddFriendAdapter extends BaseListAdapter<AVUser> {
	Context mContext;

	public AddFriendAdapter(Context context, List<AVUser> list) {
		super(context, list);
		// TODO Auto-generated constructor stub
		mContext = context;
	}

	@Override
	public View getView(int position, View conView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (conView == null) {
			conView = inflater.inflate(R.layout.contact_add_friend_item, null);
		}
		final AVUser user = datas.get(position);
		TextView nameView = ViewHolder.findViewById(conView, R.id.name);
		ImageView avatarView = ViewHolder.findViewById(conView, R.id.avatar);
		Button addBtn = ViewHolder.findViewById(conView, R.id.add);
//    String avatarUrl = contact.getAvatarUrl();
//    UserService.displayAvatar(avatarUrl, avatarView);
		nameView.setText(user.getUsername());
		addBtn.setText(R.string.add);
		addBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				AddRequestService.createAddRequestInBackground(mContext, user);