Refactor
parent
dd9b134dab
commit
42d74208ff
@ -1,79 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.thoughtcrime.securesms.contacts.ContactSelectionListItem
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:focusable="true"
|
||||
android:background="@drawable/conversation_item_background"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView
|
||||
android:id="@+id/profilePictureView"
|
||||
android:layout_width="@dimen/medium_profile_picture_size"
|
||||
android:layout_height="@dimen/medium_profile_picture_size" />
|
||||
|
||||
<LinearLayout android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textSize="@dimen/medium_font_size"
|
||||
android:textColor="@color/text"
|
||||
android:textStyle="bold"
|
||||
tools:text="Frieeeeeeedrich Nieeeeeeeeeetzsche" />
|
||||
|
||||
<LinearLayout android:id="@+id/number_container"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView android:id="@+id/number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textDirection="ltr"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="+1 (555) 555-5555" />
|
||||
|
||||
<TextView android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dip"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="Mobile" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox android:id="@+id/check_box"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:focusable="false"
|
||||
android:clickable="false" />
|
||||
|
||||
</org.thoughtcrime.securesms.contacts.ContactSelectionListItem>
|
@ -1,161 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contacts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class ContactSelectionListItem extends LinearLayout implements RecipientModifiedListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ContactSelectionListItem.class.getSimpleName();
|
||||
|
||||
private ProfilePictureView profilePictureView;
|
||||
private TextView numberView;
|
||||
private TextView nameView;
|
||||
private TextView labelView;
|
||||
private CheckBox checkBox;
|
||||
|
||||
private String number;
|
||||
private Recipient recipient;
|
||||
private GlideRequests glideRequests;
|
||||
private long threadID;
|
||||
|
||||
public ContactSelectionListItem(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ContactSelectionListItem(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
this.profilePictureView = findViewById(R.id.profilePictureView);
|
||||
this.numberView = findViewById(R.id.number);
|
||||
this.labelView = findViewById(R.id.label);
|
||||
this.nameView = findViewById(R.id.name);
|
||||
this.checkBox = findViewById(R.id.check_box);
|
||||
|
||||
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
|
||||
}
|
||||
|
||||
public void set(@NonNull GlideRequests glideRequests, int type, String name, String number, String label, int color, boolean multiSelect) {
|
||||
this.glideRequests = glideRequests;
|
||||
this.number = number;
|
||||
|
||||
if (type == ContactsDatabase.NEW_TYPE) {
|
||||
this.recipient = null;
|
||||
} else if (!TextUtils.isEmpty(number)) {
|
||||
Address address = Address.fromExternal(getContext(), number);
|
||||
this.recipient = Recipient.from(getContext(), address, true);
|
||||
this.recipient.addListener(this);
|
||||
|
||||
if (this.recipient.getName() != null) {
|
||||
name = this.recipient.getName();
|
||||
}
|
||||
}
|
||||
|
||||
threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(recipient);
|
||||
|
||||
this.numberView.setTextColor(color);
|
||||
updateProfilePicture(glideRequests, name, threadID);
|
||||
|
||||
if (!multiSelect && recipient != null && recipient.isLocalNumber()) {
|
||||
name = getContext().getString(R.string.note_to_self);
|
||||
}
|
||||
|
||||
setText(type, name, number, label);
|
||||
|
||||
if (multiSelect) this.checkBox.setVisibility(View.VISIBLE);
|
||||
else this.checkBox.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void setChecked(boolean selected) {
|
||||
this.checkBox.setChecked(selected);
|
||||
}
|
||||
|
||||
public void unbind(GlideRequests glideRequests) {
|
||||
if (recipient != null) {
|
||||
recipient.removeListener(this);
|
||||
recipient = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setText(int type, String name, String number, String label) {
|
||||
if (number == null || number.isEmpty() || GroupUtil.isEncodedGroup(number)) {
|
||||
this.nameView.setEnabled(false);
|
||||
this.numberView.setText("");
|
||||
this.labelView.setVisibility(View.GONE);
|
||||
} else if (type == ContactsDatabase.PUSH_TYPE) {
|
||||
this.numberView.setText(number);
|
||||
this.nameView.setEnabled(true);
|
||||
this.labelView.setVisibility(View.GONE);
|
||||
} else {
|
||||
this.numberView.setText(number);
|
||||
this.nameView.setEnabled(true);
|
||||
this.labelView.setText(label);
|
||||
this.labelView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
this.nameView.setText(name);
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModified(final Recipient recipient) {
|
||||
if (this.recipient == recipient) {
|
||||
Util.runOnMain(() -> {
|
||||
threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(recipient);
|
||||
updateProfilePicture(glideRequests, recipient.getName(), threadID);
|
||||
nameView.setText(recipient.toShortString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProfilePicture(GlideRequests glide, String name, long threadID) {
|
||||
if (this.recipient.isGroupRecipient()) {
|
||||
Set<String> usersAsSet = LokiAPI.Companion.getUserHexEncodedPublicKeyCache().get(threadID);
|
||||
if (usersAsSet == null) {
|
||||
usersAsSet = new HashSet<>();
|
||||
}
|
||||
ArrayList<String> users = new ArrayList<>(usersAsSet);
|
||||
Collections.sort(users); // Sort to provide a level of stability
|
||||
profilePictureView.setHexEncodedPublicKey(users.size() > 0 ? users.get(0) : "");
|
||||
profilePictureView.setAdditionalHexEncodedPublicKey(users.size() > 1 ? users.get(1) : "");
|
||||
profilePictureView.setRSSFeed(name.equals("Loki News") || name.equals("Session Updates"));
|
||||
} else {
|
||||
profilePictureView.setHexEncodedPublicKey(this.number);
|
||||
profilePictureView.setAdditionalHexEncodedPublicKey(null);
|
||||
profilePictureView.setRSSFeed(false);
|
||||
}
|
||||
profilePictureView.glide = glide;
|
||||
profilePictureView.update();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue