Skip to content

Instantly share code, notes, and snippets.

@mohsenk
Created December 24, 2018 11:51
Show Gist options
  • Save mohsenk/73770a8fef23f53763f831beec3a4005 to your computer and use it in GitHub Desktop.
Save mohsenk/73770a8fef23f53763f831beec3a4005 to your computer and use it in GitHub Desktop.
public class ContactsAdapter extends ArrayAdapter<User> {
private Context context;
private List<User> contacts;
private Callback<User> onCall;
public ContactsAdapter(@NonNull Context context, List<User> list, Callback<User> onCall) {
super(context, 0, list);
this.context = context;
contacts = list;
this.onCall = onCall;
}
public void setContacts(List<User> contacts) {
this.contacts = contacts;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItem = convertView;
if (listItem == null)
listItem = LayoutInflater.from(context).inflate(R.layout.row_contact, parent, false);
Log.i("ContactsAdapter", "Render List Item " + position);
User contact = contacts.get(position);
TextView usernameText = listItem.findViewById(R.id.textView3);
usernameText.setText(contact.getFullName());
ImageView avatarImage = listItem.findViewById(R.id.avatar_image);
Picasso.get().load(contact.getAvatarURL())
.placeholder(R.drawable.ic_user)
.error(R.drawable.ic_user)
.transform(new CircleTransform()).into(avatarImage);
TextView mobileNumberText = listItem.findViewById(R.id.mobile_number_text);
mobileNumberText.setText(contact.getMobileNumber());
listItem.findViewById(R.id.call_button).setOnClickListener(view -> {
onCall.accept(contact);
});
return listItem;
}
@Override
public int getCount() {
return contacts.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment