diff --git a/res/layout/profile_preference_view.xml b/res/layout/profile_preference_view.xml
index 6df515f480..620b984f88 100644
--- a/res/layout/profile_preference_view.xml
+++ b/res/layout/profile_preference_view.xml
@@ -30,6 +30,14 @@
android:layout_height="wrap_content"
tools:text="+14151231234"/>
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 51065f8cc1..eb564c207e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1572,6 +1572,7 @@
Looks like you don\'t have any conversations yet. Get started by messaging a friend.
+ This is a secondary device
Copied to clipboard
Share Public Key
Show QR Code
diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java
index a17d5327c4..39b6b7bf38 100644
--- a/src/org/thoughtcrime/securesms/ApplicationContext.java
+++ b/src/org/thoughtcrime/securesms/ApplicationContext.java
@@ -190,8 +190,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
lokiPublicChatManager = new LokiPublicChatManager(this);
// Loki - Update device mappings
- setUpStorageAPIIfNeeded();
- if (IdentityKeyUtil.hasIdentityKey(this)) {
+ if (setUpStorageAPIIfNeeded()) {
LokiStorageAPI.Companion.getShared().updateUserDeviceMappings();
}
}
@@ -455,14 +454,16 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
// region Loki
- public void setUpStorageAPIIfNeeded() {
+ public boolean setUpStorageAPIIfNeeded() {
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
if (userHexEncodedPublicKey != null && IdentityKeyUtil.hasIdentityKey(this)) {
boolean isDebugMode = BuildConfig.DEBUG;
byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize();
LokiAPIDatabaseProtocol database = DatabaseFactory.getLokiAPIDatabase(this);
LokiStorageAPI.Companion.configure(isDebugMode, userHexEncodedPublicKey, userPrivateKey, database);
+ return true;
}
+ return false;
}
public void setUpP2PAPI() {
diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
index b95405a8a1..279db687a3 100644
--- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
+++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
@@ -164,9 +164,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
boolean isMasterDevice = (masterHexEncodedPublicKey == null);
Preference profilePreference = this.findPreference(PREFERENCE_CATEGORY_PROFILE);
- // Hide if this is a slave device
- profilePreference.setVisible(isMasterDevice);
- profilePreference.setOnPreferenceClickListener(new ProfileClickListener());
+ if (isMasterDevice) { profilePreference.setOnPreferenceClickListener(new ProfileClickListener()); }
/*
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS));
diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java
index df31ce5517..ce99f0a3e2 100644
--- a/src/org/thoughtcrime/securesms/ConversationListActivity.java
+++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java
@@ -41,6 +41,7 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.components.RatingManager;
import org.thoughtcrime.securesms.components.SearchToolbar;
import org.thoughtcrime.securesms.conversation.ConversationActivity;
+import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
@@ -194,6 +195,13 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
+
+ // Display the correct identicon if we're a secondary device
+ String currentUser = TextSecurePreferences.getLocalNumber(this);
+ String recipientAddress = recipient.getAddress().serialize();
+ String primaryAddress = TextSecurePreferences.getMasterHexEncodedPublicKey(this);
+ String profileAddress = (recipientAddress.equalsIgnoreCase(currentUser) && primaryAddress != null) ? primaryAddress : recipientAddress;
+
profilePictureImageView.setClipToOutline(true);
profilePictureImageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@@ -203,7 +211,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
int height = profilePictureImageView.getHeight();
if (width == 0 || height == 0) return true;
profilePictureImageView.getViewTreeObserver().removeOnPreDrawListener(this);
- JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, recipient.getAddress().serialize().toLowerCase());
+ JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, profileAddress.toLowerCase());
profilePictureImageView.setImageDrawable(identicon);
return true;
}
diff --git a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java
index 0d464dd325..63b82c4bf7 100644
--- a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java
+++ b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java
@@ -30,6 +30,7 @@ public class ProfilePreference extends Preference {
private ImageView avatarView;
private TextView profileNameView;
private TextView profileNumberView;
+ private TextView profileTagView;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -64,6 +65,7 @@ public class ProfilePreference extends Preference {
avatarView = (ImageView)viewHolder.findViewById(R.id.avatar);
profileNameView = (TextView)viewHolder.findViewById(R.id.profile_name);
profileNumberView = (TextView)viewHolder.findViewById(R.id.number);
+ profileTagView = (TextView)viewHolder.findViewById(R.id.tag);
refresh();
}
@@ -72,13 +74,15 @@ public class ProfilePreference extends Preference {
if (profileNumberView == null) return;
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
- final Address localAddress = Address.fromSerialized(userHexEncodedPublicKey);
+ String primaryDevicePublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(getContext());
+ String publicKey = primaryDevicePublicKey != null ? primaryDevicePublicKey : userHexEncodedPublicKey;
+ final Address localAddress = Address.fromSerialized(publicKey);
final String profileName = TextSecurePreferences.getProfileName(getContext());
Context context = getContext();
containerView.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("Public Key", userHexEncodedPublicKey);
+ ClipData clip = ClipData.newPlainText("Public Key", publicKey);
clipboard.setPrimaryClip(clip);
Toast.makeText(context, R.string.activity_settings_public_key_copied_message, Toast.LENGTH_SHORT).show();
return true;
@@ -100,7 +104,7 @@ public class ProfilePreference extends Preference {
int height = avatarView.getHeight();
if (width == 0 || height == 0) return true;
avatarView.getViewTreeObserver().removeOnPreDrawListener(this);
- JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, userHexEncodedPublicKey.toLowerCase());
+ JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, publicKey.toLowerCase());
avatarView.setImageDrawable(identicon);
return true;
}
@@ -120,7 +124,9 @@ public class ProfilePreference extends Preference {
}
profileNameView.setVisibility(TextUtils.isEmpty(profileName) ? View.GONE : View.VISIBLE);
-
profileNumberView.setText(localAddress.toPhoneString());
+
+ profileTagView.setVisibility(primaryDevicePublicKey == null ? View.GONE : View.VISIBLE);
+ profileTagView.setText(R.string.activity_settings_secondary_device_tag);
}
}
diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
index ed87f3dcae..46499f05f0 100644
--- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
+++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
@@ -1183,7 +1183,7 @@ public class TextSecurePreferences {
}
public static void setMasterHexEncodedPublicKey(Context context, String masterHexEncodedPublicKey) {
- setStringPreference(context, "master_hex_encoded_publicKey", masterHexEncodedPublicKey);
+ setStringPreference(context, "master_hex_encoded_public_key", masterHexEncodedPublicKey);
}
// endregion
}