From c3bda57ac10b4c1f530b5b130b8aa5ae10cc3b06 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 20 Nov 2019 15:47:28 +1100 Subject: [PATCH] Show name and short id in linked device screen. --- res/layout/device_list_item_view.xml | 54 ++++++++++--------- .../securesms/DeviceListItem.java | 27 +++------- .../database/loaders/DeviceListLoader.java | 7 ++- .../securesms/devicelist/Device.java | 28 +++------- 4 files changed, 50 insertions(+), 66 deletions(-) diff --git a/res/layout/device_list_item_view.xml b/res/layout/device_list_item_view.xml index b5a0432d32..52bb83aad7 100644 --- a/res/layout/device_list_item_view.xml +++ b/res/layout/device_list_item_view.xml @@ -6,30 +6,36 @@ android:layout_marginStart="16dp" android:layout_marginEnd="16dp"> - + - \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/DeviceListItem.java b/src/org/thoughtcrime/securesms/DeviceListItem.java index 9f38c89dd0..83d2f2a7d9 100644 --- a/src/org/thoughtcrime/securesms/DeviceListItem.java +++ b/src/org/thoughtcrime/securesms/DeviceListItem.java @@ -17,8 +17,7 @@ public class DeviceListItem extends LinearLayout { private String deviceId; private TextView name; - private TextView created; - private TextView lastActive; + private TextView shortId; public DeviceListItem(Context context) { super(context); @@ -31,28 +30,16 @@ public class DeviceListItem extends LinearLayout { @Override public void onFinishInflate() { super.onFinishInflate(); - this.name = (TextView) findViewById(R.id.name); - // this.created = (TextView) findViewById(R.id.created); - // this.lastActive = (TextView) findViewById(R.id.active); + this.name = (TextView) findViewById(R.id.name); + this.shortId = (TextView) findViewById(R.id.shortId); } 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(); + 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() { diff --git a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java index 1f661b67db..6961feb8a1 100644 --- a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java +++ b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java @@ -7,8 +7,10 @@ import android.text.TextUtils; import com.annimon.stream.Stream; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; +import org.thoughtcrime.securesms.database.Database; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.devicelist.Device; +import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.MnemonicUtilities; import org.thoughtcrime.securesms.util.AsyncLoader; @@ -66,8 +68,9 @@ public class DeviceListLoader extends AsyncLoader> { } private Device mapToDevice(@NonNull String hexEncodedPublicKey) { - long now = System.currentTimeMillis(); - return new Device(hexEncodedPublicKey, MnemonicUtilities.getFirst3Words(mnemonicCodec, hexEncodedPublicKey), now, now); + String shortId = MnemonicUtilities.getFirst3Words(mnemonicCodec, hexEncodedPublicKey); + String name = DatabaseFactory.getLokiUserDatabase(getContext()).getDisplayName(hexEncodedPublicKey); + return new Device(hexEncodedPublicKey, shortId, name); } private static class DeviceComparator implements Comparator { diff --git a/src/org/thoughtcrime/securesms/devicelist/Device.java b/src/org/thoughtcrime/securesms/devicelist/Device.java index 00cdb6df34..e6f4f13967 100644 --- a/src/org/thoughtcrime/securesms/devicelist/Device.java +++ b/src/org/thoughtcrime/securesms/devicelist/Device.java @@ -2,31 +2,19 @@ package org.thoughtcrime.securesms.devicelist; public class Device { - private final String id; + private final String id; + private final String shortId; private final String name; - private final long created; - private final long lastSeen; - public Device(String id, String name, long created, long lastSeen) { - this.id = id; - this.name = name; - this.created = created; - this.lastSeen = lastSeen; + public Device(String id, String shortId, String name) { + this.id = id; + this.shortId = shortId; + this.name = name; } public String getId() { return id; } - - public String getName() { - return name; - } - - public long getCreated() { - return created; - } - - public long getLastSeen() { - return lastSeen; - } + public String getShortId() { return shortId; } + public String getName() { return name; } }