Show name and short id in linked device screen.

This commit is contained in:
Mikunj 2019-11-20 15:47:28 +11:00
parent e72d5502ce
commit c3bda57ac1
4 changed files with 50 additions and 66 deletions

View File

@ -6,30 +6,36 @@
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"> android:layout_marginEnd="16dp">
<TextView android:id="@+id/name" <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?attr/conversation_list_item_contact_color" android:textColor="?attr/conversation_list_item_contact_color"
android:singleLine="true" android:textSize="18sp" />
android:ellipsize="marquee"
android:layout_marginTop="8dp" <TextView
android:layout_marginBottom="8dp" android:id="@+id/shortId"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--
<TextView android:id="@+id/created"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:layout_marginTop="2dp"
android:textColor="?attr/conversation_list_item_subject_color" android:ellipsize="marquee"
android:fontFamily="sans-serif-light" /> android:singleLine="true"
android:text="shortId"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#A2A2A2"
android:textSize="14sp" />
</LinearLayout>
<TextView android:id="@+id/active"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?attr/conversation_list_item_subject_color"
android:fontFamily="sans-serif-light"
android:layout_marginBottom="8dp" />
-->
</org.thoughtcrime.securesms.DeviceListItem> </org.thoughtcrime.securesms.DeviceListItem>

View File

@ -17,8 +17,7 @@ public class DeviceListItem extends LinearLayout {
private String deviceId; private String deviceId;
private TextView name; private TextView name;
private TextView created; private TextView shortId;
private TextView lastActive;
public DeviceListItem(Context context) { public DeviceListItem(Context context) {
super(context); super(context);
@ -32,27 +31,15 @@ public class DeviceListItem extends LinearLayout {
public void onFinishInflate() { public void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
this.name = (TextView) findViewById(R.id.name); this.name = (TextView) findViewById(R.id.name);
// this.created = (TextView) findViewById(R.id.created); this.shortId = (TextView) findViewById(R.id.shortId);
// this.lastActive = (TextView) findViewById(R.id.active);
} }
public void set(Device deviceInfo, Locale locale) { public void set(Device deviceInfo, Locale locale) {
if (TextUtils.isEmpty(deviceInfo.getName())) this.name.setText(R.string.DeviceListItem_unnamed_device);
else this.name.setText(deviceInfo.getName());
/*
this.created.setText(getContext().getString(R.string.DeviceListItem_linked_s,
DateUtils.getDayPrecisionTimeSpanString(getContext(),
locale,
deviceInfo.getCreated())));
this.lastActive.setText(getContext().getString(R.string.DeviceListItem_last_active_s,
DateUtils.getDayPrecisionTimeSpanString(getContext(),
locale,
deviceInfo.getLastSeen())));
*/
this.deviceId = deviceInfo.getId(); this.deviceId = deviceInfo.getId();
boolean hasName = !TextUtils.isEmpty(deviceInfo.getName());
this.name.setText(hasName ? deviceInfo.getName() : deviceInfo.getShortId());
this.shortId.setText(deviceInfo.getShortId());
this.shortId.setVisibility(hasName ? VISIBLE : GONE);
} }
public String getDeviceId() { public String getDeviceId() {

View File

@ -7,8 +7,10 @@ import android.text.TextUtils;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.database.Database;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.devicelist.Device; import org.thoughtcrime.securesms.devicelist.Device;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.MnemonicUtilities; import org.thoughtcrime.securesms.loki.MnemonicUtilities;
import org.thoughtcrime.securesms.util.AsyncLoader; import org.thoughtcrime.securesms.util.AsyncLoader;
@ -66,8 +68,9 @@ public class DeviceListLoader extends AsyncLoader<List<Device>> {
} }
private Device mapToDevice(@NonNull String hexEncodedPublicKey) { private Device mapToDevice(@NonNull String hexEncodedPublicKey) {
long now = System.currentTimeMillis(); String shortId = MnemonicUtilities.getFirst3Words(mnemonicCodec, hexEncodedPublicKey);
return new Device(hexEncodedPublicKey, MnemonicUtilities.getFirst3Words(mnemonicCodec, hexEncodedPublicKey), now, now); String name = DatabaseFactory.getLokiUserDatabase(getContext()).getDisplayName(hexEncodedPublicKey);
return new Device(hexEncodedPublicKey, shortId, name);
} }
private static class DeviceComparator implements Comparator<Device> { private static class DeviceComparator implements Comparator<Device> {

View File

@ -3,30 +3,18 @@ package org.thoughtcrime.securesms.devicelist;
public class Device { public class Device {
private final String id; private final String id;
private final String shortId;
private final String name; private final String name;
private final long created;
private final long lastSeen;
public Device(String id, String name, long created, long lastSeen) { public Device(String id, String shortId, String name) {
this.id = id; this.id = id;
this.shortId = shortId;
this.name = name; this.name = name;
this.created = created;
this.lastSeen = lastSeen;
} }
public String getId() { public String getId() {
return id; return id;
} }
public String getShortId() { return shortId; }
public String getName() { public String getName() { return name; }
return name;
}
public long getCreated() {
return created;
}
public long getLastSeen() {
return lastSeen;
}
} }