aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-20 21:17:33 +0100
committerChristian Schneppe <christian@pix-art.de>2018-03-20 21:17:33 +0100
commitbfb065558512032b9105515c06def55c445ea7a6 (patch)
tree9de7b566bd8e2d273a4f8ac7e1efd18fb53c2ee7 /src/main
parentf7b670206379b420d66d9f164e386a8bb71368e7 (diff)
use data binder for list item adapater
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java
index 8b4af00d8..2df1e5b0f 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java
@@ -1,8 +1,8 @@
package de.pixart.messenger.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;
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import de.pixart.messenger.R;
+import de.pixart.messenger.databinding.ContactBinding;
import de.pixart.messenger.entities.ListItem;
import de.pixart.messenger.ui.SettingsActivity;
import de.pixart.messenger.ui.XmppActivity;
@@ -60,15 +61,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) {
@@ -137,7 +140,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(56), isCancelled());
}
@Override
@@ -221,17 +225,13 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
private ViewHolder() {
}
- 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;
}
}