aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-20 21:14:32 +0100
committerChristian Schneppe <christian@pix-art.de>2018-03-20 21:14:32 +0100
commitf7b670206379b420d66d9f164e386a8bb71368e7 (patch)
tree29f7a9a6948125fc02a8fa6c4c62a21998c4f966 /src/main
parent35c70127720d048cd200dcefad8a710313019243 (diff)
use data binder for inflating muc items
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java60
-rw-r--r--src/main/res/layout/contact.xml104
2 files changed, 78 insertions, 86 deletions
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<User> 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 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?android:attr/activatedBackgroundIndicator"
- android:padding="@dimen/list_padding">
-
- <com.makeramen.roundedimageview.RoundedImageView
- android:id="@+id/contact_photo"
- android:layout_width="56dp"
- android:layout_height="56dp"
- android:layout_alignParentLeft="true"
- app:riv_border_width="1dp"
- app:riv_border_color="@color/grey500"
- app:riv_corner_radius="28dp" />
-
- <LinearLayout
- android:layout_width="wrap_content"
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <RelativeLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_toRightOf="@+id/contact_photo"
- android:orientation="vertical"
- android:paddingLeft="@dimen/avatar_item_distance" >
+ android:background="?android:attr/activatedBackgroundIndicator"
+ android:padding="@dimen/list_padding">
- <android.support.text.emoji.widget.EmojiTextView
- android:id="@+id/contact_display_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
+ <com.makeramen.roundedimageview.RoundedImageView
+ android:id="@+id/contact_photo"
+ android:layout_width="56dp"
+ android:layout_height="56dp"
+ android:layout_alignParentLeft="true"
+ app:riv_border_color="@color/grey500"
+ app:riv_border_width="1dp"
+ app:riv_corner_radius="28dp" />
- <TextView
- android:id="@+id/contact_jid"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" />
+ android:layout_centerVertical="true"
+ android:layout_toRightOf="@+id/contact_photo"
+ android:orientation="vertical"
+ android:paddingLeft="@dimen/avatar_item_distance">
- <com.wefika.flowlayout.FlowLayout
- android:id="@+id/tags"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="-2dp"
- android:orientation="horizontal">
- </com.wefika.flowlayout.FlowLayout>
+ <android.support.text.emoji.widget.EmojiTextView
+ android:id="@+id/contact_display_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
- <TextView
- android:id="@+id/key"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/black87"
- android:textSize="?attr/TextSizeBody"
- android:typeface="monospace"
- android:fontFamily="monospace"
- android:visibility="gone" />
- </LinearLayout>
-
-</RelativeLayout> \ No newline at end of file
+ <TextView
+ android:id="@+id/contact_jid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" />
+
+ <com.wefika.flowlayout.FlowLayout
+ android:id="@+id/tags"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="-2dp"
+ android:orientation="horizontal"></com.wefika.flowlayout.FlowLayout>
+
+ <TextView
+ android:id="@+id/key"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:fontFamily="monospace"
+ android:textColor="@color/black87"
+ android:textSize="?attr/TextSizeBody"
+ android:typeface="monospace"
+ android:visibility="gone" />
+ </LinearLayout>
+
+ </RelativeLayout>
+</layout> \ No newline at end of file