Created
December 24, 2018 11:51
-
-
Save mohsenk/73770a8fef23f53763f831beec3a4005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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