use data binder for inflating muc items

This commit is contained in:
Daniel Gultsch 2018-02-19 10:46:13 +01:00
parent fb383c7881
commit 595757fe00
2 changed files with 77 additions and 82 deletions

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
@ -38,6 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.databinding.ContactBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact; 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); 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(); membersView.removeAllViews();
if (inflater == null) {
return;
}
final ArrayList<User> users = mucOptions.getUsers(); final ArrayList<User> users = mucOptions.getUsers();
Collections.sort(users); Collections.sort(users);
for (final User user : users) { for (final User user : users) {
View view = inflater.inflate(R.layout.contact, membersView,false); ContactBinding binding = DataBindingUtil.inflate(inflater,R.layout.contact,membersView,false);
this.setListItemBackgroundOnView(view); this.setListItemBackgroundOnView(binding.getRoot());
view.setOnClickListener(new OnClickListener() { binding.getRoot().setOnClickListener(view1 -> highlightInMuc(mConversation, user.getName()));
@Override registerForContextMenu(binding.getRoot());
public void onClick(View view) { binding.getRoot().setTag(user);
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);
if (mAdvancedMode && user.getPgpKeyId() != 0) { if (mAdvancedMode && user.getPgpKeyId() != 0) {
tvKey.setVisibility(View.VISIBLE); binding.key.setVisibility(View.VISIBLE);
tvKey.setOnClickListener(new OnClickListener() { binding.key.setOnClickListener(v -> viewPgpKey(user));
binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
@Override
public void onClick(View v) {
viewPgpKey(user);
}
});
tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
} }
Contact contact = user.getContact(); Contact contact = user.getContact();
String name = user.getName(); String name = user.getName();
if (contact != null) { if (contact != null) {
tvDisplayName.setText(contact.getDisplayName()); binding.contactDisplayName.setText(contact.getDisplayName());
tvStatus.setText((name != null ? name+ " \u2022 " : "") + getStatus(user)); binding.contactJid.setText((name != null ? name+ " \u2022 " : "") + getStatus(user));
} else { } else {
tvDisplayName.setText(name == null ? "" : name); binding.contactDisplayName.setText(name == null ? "" : name);
tvStatus.setText(getStatus(user)); binding.contactJid.setText(getStatus(user));
} }
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo); loadAvatar(user,binding.contactPhoto);
loadAvatar(user,iv);
if (user.getRole() == MucOptions.Role.NONE) { if (user.getRole() == MucOptions.Role.NONE) {
tvDisplayName.setAlpha(INACTIVE_ALPHA); binding.contactJid.setAlpha(INACTIVE_ALPHA);
tvKey.setAlpha(INACTIVE_ALPHA); binding.key.setAlpha(INACTIVE_ALPHA);
tvStatus.setAlpha(INACTIVE_ALPHA); binding.contactDisplayName.setAlpha(INACTIVE_ALPHA);
iv.setAlpha(INACTIVE_ALPHA); binding.contactPhoto.setAlpha(INACTIVE_ALPHA);
} }
membersView.addView(view); membersView.addView(binding.getRoot());
if (mConversation.getMucOptions().canInvite()) { if (mConversation.getMucOptions().canInvite()) {
mInviteButton.setVisibility(View.VISIBLE); mInviteButton.setVisibility(View.VISIBLE);
} else { } else {

View file

@ -1,56 +1,61 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" 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 <RelativeLayout
android:id="@+id/contact_photo" android:layout_width="match_parent"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
app:riv_corner_radius="2dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:background="?android:attr/activatedBackgroundIndicator"
android:layout_toRightOf="@+id/contact_photo" android:padding="@dimen/list_padding">
android:orientation="vertical"
android:paddingLeft="@dimen/avatar_item_distance" >
<TextView <com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/contact_display_name" android:id="@+id/contact_photo"
android:layout_width="wrap_content" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="48dp"
android:singleLine="true" android:layout_alignParentLeft="true"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> android:scaleType="centerCrop"
app:riv_corner_radius="2dp"/>
<TextView <LinearLayout
android:id="@+id/contact_jid"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:layout_centerVertical="true"
android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary"/> android:layout_toRightOf="@+id/contact_photo"
<com.wefika.flowlayout.FlowLayout android:orientation="vertical"
android:id="@+id/tags" android:paddingLeft="@dimen/avatar_item_distance">
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:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"
android:typeface="monospace"
android:fontFamily="monospace"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout> <TextView
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/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="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"
android:typeface="monospace"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
</layout>