mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
refactor and optimize binder code
This commit is contained in:
parent
620ecbea33
commit
9b1520c0f2
1 changed files with 46 additions and 43 deletions
|
@ -613,65 +613,27 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContactListFragment.ContactItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
@NonNull
|
||||||
|
public ContactListFragment.ContactItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(context).inflate(R.layout.contactlist_list_item, parent, false);
|
View view = LayoutInflater.from(context).inflate(R.layout.contactlist_list_item, parent, false);
|
||||||
|
|
||||||
return new ContactListFragment.ContactItemViewHolder(view);
|
return new ContactListFragment.ContactItemViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
|
public void onBindViewHolder(@NonNull final ContactListFragment.ContactItemViewHolder holder, final int position) {
|
||||||
final int verifiedPosition = holder.getAdapterPosition();
|
final int verifiedPosition = holder.getAdapterPosition();
|
||||||
final VCard vcard = vCards.get(verifiedPosition);
|
final VCard vcard = vCards.get(verifiedPosition);
|
||||||
|
|
||||||
if (vcard != null) {
|
if (vcard != null) {
|
||||||
|
|
||||||
if (checkedVCards.contains(position)) {
|
setChecked(checkedVCards.contains(position), holder.getName());
|
||||||
holder.getName().setChecked(true);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
holder.getName().getCheckMarkDrawable()
|
|
||||||
.setColorFilter(ThemeUtils.primaryAccentColor(context), PorterDuff.Mode.SRC_ATOP);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
holder.getName().setChecked(false);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
holder.getName().getCheckMarkDrawable().clearColorFilter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.getName().setText(getDisplayName(vcard));
|
holder.getName().setText(getDisplayName(vcard));
|
||||||
|
|
||||||
// photo
|
// photo
|
||||||
if (vcard.getPhotos().size() > 0) {
|
if (vcard.getPhotos().size() > 0) {
|
||||||
Photo firstPhoto = vcard.getPhotos().get(0);
|
setPhoto(holder.getBadge(), vcard.getPhotos().get(0));
|
||||||
String url = firstPhoto.getUrl();
|
|
||||||
byte[] data = firstPhoto.getData();
|
|
||||||
|
|
||||||
if (data != null && data.length > 0) {
|
|
||||||
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
|
|
||||||
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(),
|
|
||||||
thumbnail);
|
|
||||||
|
|
||||||
holder.getBadge().setImageDrawable(drawable);
|
|
||||||
} else if (url != null) {
|
|
||||||
ImageView badge = holder.getBadge();
|
|
||||||
SimpleTarget target = new SimpleTarget<Drawable>() {
|
|
||||||
@Override
|
|
||||||
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
|
|
||||||
holder.getBadge().setImageDrawable(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
|
||||||
super.onLoadFailed(e, errorDrawable);
|
|
||||||
holder.getBadge().setImageDrawable(errorDrawable);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user,
|
|
||||||
badge.getWidth(), badge.getHeight());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.getBadge().setImageDrawable(
|
holder.getBadge().setImageDrawable(
|
||||||
|
@ -689,6 +651,47 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setPhoto(ImageView imageView, Photo firstPhoto) {
|
||||||
|
String url = firstPhoto.getUrl();
|
||||||
|
byte[] data = firstPhoto.getData();
|
||||||
|
|
||||||
|
if (data != null && data.length > 0) {
|
||||||
|
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||||
|
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(),
|
||||||
|
thumbnail);
|
||||||
|
|
||||||
|
imageView.setImageDrawable(drawable);
|
||||||
|
} else if (url != null) {
|
||||||
|
SimpleTarget target = new SimpleTarget<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
|
||||||
|
imageView.setImageDrawable(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||||
|
super.onLoadFailed(e, errorDrawable);
|
||||||
|
imageView.setImageDrawable(errorDrawable);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user, imageView.getWidth(),
|
||||||
|
imageView.getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChecked(boolean checked, CheckedTextView checkedTextView) {
|
||||||
|
checkedTextView.setChecked(checked);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
if (checked) {
|
||||||
|
checkedTextView.getCheckMarkDrawable()
|
||||||
|
.setColorFilter(ThemeUtils.primaryAccentColor(context), PorterDuff.Mode.SRC_ATOP);
|
||||||
|
} else {
|
||||||
|
checkedTextView.getCheckMarkDrawable().clearColorFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void toggleVCard(ContactListFragment.ContactItemViewHolder holder, int verifiedPosition) {
|
private void toggleVCard(ContactListFragment.ContactItemViewHolder holder, int verifiedPosition) {
|
||||||
holder.getName().setChecked(!holder.getName().isChecked());
|
holder.getName().setChecked(!holder.getName().isChecked());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue