From fc5a2922e97bb05af4eaa0428c9235a6a6410100 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 19 Feb 2018 13:12:45 +0100 Subject: [PATCH] use data binder for list item adapater --- .../ui/adapter/ListItemAdapter.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 1a915440e..b14821056 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -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 { @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 tags = item.getTags(activity); if (tags.size() == 0 || !this.showDynamicTags) { viewHolder.tags.setVisibility(View.GONE); @@ -155,16 +160,13 @@ public class ListItemAdapter extends ArrayAdapter { } - 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 { @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