From 595757fe0089395ecc4a024ab385a79d5bf3f8b0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 19 Feb 2018 10:46:13 +0100 Subject: [PATCH] use data binder for inflating muc items --- .../ui/ConferenceDetailsActivity.java | 58 +++++----- src/main/res/layout/contact.xml | 101 +++++++++--------- 2 files changed, 77 insertions(+), 82 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index a60bf4a1c..5a8713ddd 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui; +import android.databinding.DataBindingUtil; import android.support.v7.app.AlertDialog; import android.app.PendingIntent; import android.content.Context; @@ -38,6 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; +import eu.siacs.conversations.databinding.ContactBinding; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; @@ -604,54 +606,42 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers mNotifyStatusText.setText(R.string.notify_only_when_highlighted); } - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); membersView.removeAllViews(); + if (inflater == null) { + return; + } final ArrayList users = mucOptions.getUsers(); Collections.sort(users); for (final User user : users) { - View view = inflater.inflate(R.layout.contact, membersView,false); - this.setListItemBackgroundOnView(view); - view.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - highlightInMuc(mConversation, user.getName()); - } - }); - registerForContextMenu(view); - view.setTag(user); - TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name); - TextView tvKey = (TextView) view.findViewById(R.id.key); - TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid); + ContactBinding binding = DataBindingUtil.inflate(inflater,R.layout.contact,membersView,false); + this.setListItemBackgroundOnView(binding.getRoot()); + binding.getRoot().setOnClickListener(view1 -> highlightInMuc(mConversation, user.getName())); + registerForContextMenu(binding.getRoot()); + binding.getRoot().setTag(user); if (mAdvancedMode && user.getPgpKeyId() != 0) { - tvKey.setVisibility(View.VISIBLE); - tvKey.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - viewPgpKey(user); - } - }); - tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId())); + binding.key.setVisibility(View.VISIBLE); + binding.key.setOnClickListener(v -> viewPgpKey(user)); + binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId())); } Contact contact = user.getContact(); String name = user.getName(); if (contact != null) { - tvDisplayName.setText(contact.getDisplayName()); - tvStatus.setText((name != null ? name+ " \u2022 " : "") + getStatus(user)); + binding.contactDisplayName.setText(contact.getDisplayName()); + binding.contactJid.setText((name != null ? name+ " \u2022 " : "") + getStatus(user)); } else { - tvDisplayName.setText(name == null ? "" : name); - tvStatus.setText(getStatus(user)); + binding.contactDisplayName.setText(name == null ? "" : name); + binding.contactJid.setText(getStatus(user)); } - ImageView iv = (ImageView) view.findViewById(R.id.contact_photo); - loadAvatar(user,iv); + loadAvatar(user,binding.contactPhoto); if (user.getRole() == MucOptions.Role.NONE) { - tvDisplayName.setAlpha(INACTIVE_ALPHA); - tvKey.setAlpha(INACTIVE_ALPHA); - tvStatus.setAlpha(INACTIVE_ALPHA); - iv.setAlpha(INACTIVE_ALPHA); + binding.contactJid.setAlpha(INACTIVE_ALPHA); + binding.key.setAlpha(INACTIVE_ALPHA); + binding.contactDisplayName.setAlpha(INACTIVE_ALPHA); + binding.contactPhoto.setAlpha(INACTIVE_ALPHA); } - membersView.addView(view); + membersView.addView(binding.getRoot()); if (mConversation.getMucOptions().canInvite()) { mInviteButton.setVisibility(View.VISIBLE); } else { diff --git a/src/main/res/layout/contact.xml b/src/main/res/layout/contact.xml index 82c062bb7..fffdd0841 100644 --- a/src/main/res/layout/contact.xml +++ b/src/main/res/layout/contact.xml @@ -1,56 +1,61 @@ - + - - - + android:background="?android:attr/activatedBackgroundIndicator" + android:padding="@dimen/list_padding"> - + - - - - - + android:layout_centerVertical="true" + android:layout_toRightOf="@+id/contact_photo" + android:orientation="vertical" + android:paddingLeft="@dimen/avatar_item_distance"> - \ No newline at end of file + + + + + + + + + + + + \ No newline at end of file