From e72d5502ce28fef86f0cf60ad7bedf8243ed0457 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 20 Nov 2019 15:21:54 +1100 Subject: [PATCH] Show our device words in preferences if we're a secondary device. --- res/values/strings.xml | 2 +- .../preferences/widgets/ProfilePreference.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index e737cc857f..9321c1f6c7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1573,7 +1573,7 @@ Looks like you don\'t have any conversations yet. Get started by messaging a friend. - Secondary device + Linked device (%s) Copied to clipboard Share Public Key Show QR Code diff --git a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java index 63b82c4bf7..5cd135a943 100644 --- a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java +++ b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java @@ -20,7 +20,9 @@ import android.widget.Toast; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable; +import org.thoughtcrime.securesms.loki.MnemonicUtilities; import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; import network.loki.messenger.R; @@ -31,6 +33,7 @@ public class ProfilePreference extends Preference { private TextView profileNameView; private TextView profileNumberView; private TextView profileTagView; + private String ourDeviceWords; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { @@ -127,6 +130,12 @@ public class ProfilePreference extends Preference { profileNumberView.setText(localAddress.toPhoneString()); profileTagView.setVisibility(primaryDevicePublicKey == null ? View.GONE : View.VISIBLE); - profileTagView.setText(R.string.activity_settings_secondary_device_tag); + if (primaryDevicePublicKey != null && ourDeviceWords == null) { + MnemonicCodec codec = new MnemonicCodec(MnemonicUtilities.getLanguageFileDirectory(context)); + ourDeviceWords = MnemonicUtilities.getFirst3Words(codec, userHexEncodedPublicKey); + } + + String tag = context.getResources().getString(R.string.activity_settings_linked_device_tag); + profileTagView.setText(String.format(tag, ourDeviceWords != null ? ourDeviceWords : "-")); } }