From f7b670206379b420d66d9f164e386a8bb71368e7 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 20 Mar 2018 21:14:32 +0100 Subject: use data binder for inflating muc items --- .../messenger/ui/ConferenceDetailsActivity.java | 60 +++++------- src/main/res/layout/contact.xml | 104 +++++++++++---------- 2 files changed, 78 insertions(+), 86 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index d9fe66975..fa77b9423 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.res.Resources; +import android.databinding.DataBindingUtil; import android.graphics.Bitmap; import android.graphics.PorterDuff; import android.graphics.drawable.BitmapDrawable; @@ -41,6 +42,7 @@ import java.util.concurrent.atomic.AtomicInteger; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.crypto.PgpEngine; +import de.pixart.messenger.databinding.ContactBinding; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Bookmark; import de.pixart.messenger.entities.Contact; @@ -669,56 +671,44 @@ 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) { + ContactBinding binding = DataBindingUtil.inflate(inflater, R.layout.contact, membersView, false); final Contact contact = user.getContact(); - View view = inflater.inflate(R.layout.contact, membersView, false); - this.setListItemBackgroundOnView(view); + final String name = user.getName(); + this.setListItemBackgroundOnView(binding.getRoot()); if (contact != null && contact.showInRoster()) { - view.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - switchToContactDetails(contact); - } - }); + binding.getRoot().setOnClickListener((OnClickListener) view -> switchToContactDetails(contact)); } - registerForContextMenu(view); - view.setTag(user); - TextView tvDisplayName = view.findViewById(R.id.contact_display_name); - TextView tvKey = view.findViewById(R.id.key); - TextView tvStatus = view.findViewById(R.id.contact_jid); + 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())); } - 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 = 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.contactDisplayName.setAlpha(INACTIVE_ALPHA); + binding.key.setAlpha(INACTIVE_ALPHA); + binding.contactJid.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 c414271ab..eea98181e 100644 --- a/src/main/res/layout/contact.xml +++ b/src/main/res/layout/contact.xml @@ -1,59 +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 -- cgit v1.2.3