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;
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<User> 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 {

View File

@ -1,56 +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">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/contact_photo"
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"
<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">
<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" />
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/contact_photo"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
app:riv_corner_radius="2dp"/>
<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"/>
<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:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"
android:typeface="monospace"
android:fontFamily="monospace"
android:visibility="gone" />
</LinearLayout>
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/contact_photo"
android:orientation="vertical"
android:paddingLeft="@dimen/avatar_item_distance">
</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>