Show our device words in preferences if we're a secondary device.

This commit is contained in:
Mikunj 2019-11-20 15:21:54 +11:00
parent 28a04f13af
commit e72d5502ce
2 changed files with 11 additions and 2 deletions

View File

@ -1573,7 +1573,7 @@
<!-- Conversation list activity --> <!-- Conversation list activity -->
<string name="activity_conversation_list_empty_state_message">Looks like you don\'t have any conversations yet. Get started by messaging a friend.</string> <string name="activity_conversation_list_empty_state_message">Looks like you don\'t have any conversations yet. Get started by messaging a friend.</string>
<!-- Settings activity --> <!-- Settings activity -->
<string name="activity_settings_secondary_device_tag">Secondary device</string> <string name="activity_settings_linked_device_tag">Linked device (%s)</string>
<string name="activity_settings_public_key_copied_message">Copied to clipboard</string> <string name="activity_settings_public_key_copied_message">Copied to clipboard</string>
<string name="activity_settings_share_public_key_button_title">Share Public Key</string> <string name="activity_settings_share_public_key_button_title">Share Public Key</string>
<string name="activity_settings_show_qr_code_button_title">Show QR Code</string> <string name="activity_settings_show_qr_code_button_title">Show QR Code</string>

View File

@ -20,7 +20,9 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable; import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable;
import org.thoughtcrime.securesms.loki.MnemonicUtilities;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec;
import network.loki.messenger.R; import network.loki.messenger.R;
@ -31,6 +33,7 @@ public class ProfilePreference extends Preference {
private TextView profileNameView; private TextView profileNameView;
private TextView profileNumberView; private TextView profileNumberView;
private TextView profileTagView; private TextView profileTagView;
private String ourDeviceWords;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@ -127,6 +130,12 @@ public class ProfilePreference extends Preference {
profileNumberView.setText(localAddress.toPhoneString()); profileNumberView.setText(localAddress.toPhoneString());
profileTagView.setVisibility(primaryDevicePublicKey == null ? View.GONE : View.VISIBLE); 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 : "-"));
} }
} }