Skip to content

Commit

Permalink
For tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
CullyCross committed Nov 4, 2015
1 parent 99439cf commit 3d0ca3d
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,18 @@ public ContactsCursorAdapter(Context context, Cursor cursor) {

@Override public void onBindViewHolder(ContactItem holder, Cursor cursor) {

final String image =
cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));

if (image != null) {
Picasso.with(mContext).load(Uri.parse(image)).fit().centerCrop().into(holder.mPhoto);
} else {
holder.mPhoto.setImageResource(R.mipmap.ic_launcher);
}

final String name =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

holder.mName.setText(name);
initImage(holder, cursor);
initName(holder, cursor);

final String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
final ContentResolver contentResolver = mContext.getContentResolver();

initPhones(holder, id, contentResolver);
initEmails(holder, id, contentResolver);
initExpander(holder);
}

private void initExpander(ContactItem holder) {
if (holder.getAdapterPosition() == mExpandedPosition) {
holder.mExpandArea.setVisibility(View.VISIBLE);
} else {
Expand All @@ -90,6 +82,24 @@ public ContactsCursorAdapter(Context context, Cursor cursor) {
});
}

private void initName(ContactItem holder, Cursor cursor) {
final String name =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

holder.mName.setText(name);
}

private void initImage(ContactItem holder, Cursor cursor) {
final String image =
cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));

if (image != null) {
Picasso.with(mContext).load(Uri.parse(image)).fit().centerCrop().into(holder.mPhoto);
} else {
holder.mPhoto.setImageResource(R.mipmap.ic_launcher);
}
}

private void initEmails(ContactItem holder, String id, ContentResolver contentResolver) {
final Cursor emailCursor =
contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
Expand All @@ -114,10 +124,6 @@ private void initPhones(ContactItem holder, String id, ContentResolver contentRe
holder.mPhonesRecyclerView.setAdapter(new PhoneCursorAdapter(mContext, phoneCursor));
}

private void initEmpty(ContactItem holder) {
holder.mPhonesRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
}

static class ContactItem extends RecyclerView.ViewHolder {

@Bind(R.id.contact_layout) View mContactLayout;
Expand Down

0 comments on commit 3d0ca3d

Please sign in to comment.