use data binder for list item adapater
This commit is contained in:
parent
595757fe00
commit
fc5a2922e9
|
@ -3,6 +3,7 @@ package eu.siacs.conversations.ui.adapter;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -22,6 +23,7 @@ import java.util.List;
|
|||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.ContactBinding;
|
||||
import eu.siacs.conversations.entities.ListItem;
|
||||
import eu.siacs.conversations.ui.SettingsActivity;
|
||||
import eu.siacs.conversations.ui.XmppActivity;
|
||||
|
@ -81,14 +83,17 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
|
|||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
LayoutInflater inflater = activity.getLayoutInflater();
|
||||
ListItem item = getItem(position);
|
||||
ViewHolder viewHolder;
|
||||
if (view == null) {
|
||||
view = inflater.inflate(R.layout.contact, parent, false);
|
||||
ContactBinding binding = DataBindingUtil.inflate(inflater,R.layout.contact,parent,false);
|
||||
viewHolder = ViewHolder.get(binding);
|
||||
view = binding.getRoot();
|
||||
} else {
|
||||
viewHolder = (ViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
ViewHolder viewHolder = ViewHolder.get(view);
|
||||
|
||||
List<ListItem.Tag> tags = item.getTags(activity);
|
||||
if (tags.size() == 0 || !this.showDynamicTags) {
|
||||
viewHolder.tags.setVisibility(View.GONE);
|
||||
|
@ -155,16 +160,13 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
|
|||
|
||||
}
|
||||
|
||||
public static ViewHolder get(View layout) {
|
||||
ViewHolder viewHolder = (ViewHolder) layout.getTag();
|
||||
if (viewHolder == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
viewHolder.name = layout.findViewById(R.id.contact_display_name);
|
||||
viewHolder.jid = layout.findViewById(R.id.contact_jid);
|
||||
viewHolder.avatar = layout.findViewById(R.id.contact_photo);
|
||||
viewHolder.tags = layout.findViewById(R.id.tags);
|
||||
layout.setTag(viewHolder);
|
||||
}
|
||||
public static ViewHolder get(ContactBinding binding) {
|
||||
ViewHolder viewHolder = new ViewHolder();
|
||||
viewHolder.name = binding.contactDisplayName;
|
||||
viewHolder.jid = binding.contactJid;
|
||||
viewHolder.avatar = binding.contactPhoto;
|
||||
viewHolder.tags = binding.tags;
|
||||
binding.getRoot().setTag(viewHolder);
|
||||
return viewHolder;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +194,8 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
|
|||
|
||||
@Override
|
||||
protected Bitmap doInBackground(ListItem... params) {
|
||||
return activity.avatarService().get(params[0], activity.getPixel(48), isCancelled());
|
||||
this.item = params[0];
|
||||
return activity.avatarService().get(this.item, activity.getPixel(48), isCancelled());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue