Fix multi-device ui

This commit is contained in:
Mikunj 2019-10-24 13:35:14 +11:00
parent 24ae0c640b
commit 94a9303d7a
7 changed files with 34 additions and 12 deletions

View File

@ -30,6 +30,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:text="+14151231234"/> tools:text="+14151231234"/>
<TextView
android:id="@+id/tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="#A2A2A2"
tools:text="Secondary Device" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -1572,6 +1572,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">This is a secondary device</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

@ -190,8 +190,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
lokiPublicChatManager = new LokiPublicChatManager(this); lokiPublicChatManager = new LokiPublicChatManager(this);
// Loki - Update device mappings // Loki - Update device mappings
setUpStorageAPIIfNeeded(); if (setUpStorageAPIIfNeeded()) {
if (IdentityKeyUtil.hasIdentityKey(this)) {
LokiStorageAPI.Companion.getShared().updateUserDeviceMappings(); LokiStorageAPI.Companion.getShared().updateUserDeviceMappings();
} }
} }
@ -455,14 +454,16 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
} }
// region Loki // region Loki
public void setUpStorageAPIIfNeeded() { public boolean setUpStorageAPIIfNeeded() {
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this); String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
if (userHexEncodedPublicKey != null && IdentityKeyUtil.hasIdentityKey(this)) { if (userHexEncodedPublicKey != null && IdentityKeyUtil.hasIdentityKey(this)) {
boolean isDebugMode = BuildConfig.DEBUG; boolean isDebugMode = BuildConfig.DEBUG;
byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize(); byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize();
LokiAPIDatabaseProtocol database = DatabaseFactory.getLokiAPIDatabase(this); LokiAPIDatabaseProtocol database = DatabaseFactory.getLokiAPIDatabase(this);
LokiStorageAPI.Companion.configure(isDebugMode, userHexEncodedPublicKey, userPrivateKey, database); LokiStorageAPI.Companion.configure(isDebugMode, userHexEncodedPublicKey, userPrivateKey, database);
return true;
} }
return false;
} }
public void setUpP2PAPI() { public void setUpP2PAPI() {

View File

@ -164,9 +164,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
boolean isMasterDevice = (masterHexEncodedPublicKey == null); boolean isMasterDevice = (masterHexEncodedPublicKey == null);
Preference profilePreference = this.findPreference(PREFERENCE_CATEGORY_PROFILE); Preference profilePreference = this.findPreference(PREFERENCE_CATEGORY_PROFILE);
// Hide if this is a slave device if (isMasterDevice) { profilePreference.setOnPreferenceClickListener(new ProfileClickListener()); }
profilePreference.setVisible(isMasterDevice);
profilePreference.setOnPreferenceClickListener(new ProfileClickListener());
/* /*
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS) this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS)); .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS));

View File

@ -41,6 +41,7 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.components.RatingManager; import org.thoughtcrime.securesms.components.RatingManager;
import org.thoughtcrime.securesms.components.SearchToolbar; import org.thoughtcrime.securesms.components.SearchToolbar;
import org.thoughtcrime.securesms.conversation.ConversationActivity; import org.thoughtcrime.securesms.conversation.ConversationActivity;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
@ -194,6 +195,13 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
outline.setOval(0, 0, view.getWidth(), view.getHeight()); 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.setClipToOutline(true);
profilePictureImageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { profilePictureImageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@ -203,7 +211,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
int height = profilePictureImageView.getHeight(); int height = profilePictureImageView.getHeight();
if (width == 0 || height == 0) return true; if (width == 0 || height == 0) return true;
profilePictureImageView.getViewTreeObserver().removeOnPreDrawListener(this); 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); profilePictureImageView.setImageDrawable(identicon);
return true; return true;
} }

View File

@ -30,6 +30,7 @@ public class ProfilePreference extends Preference {
private ImageView avatarView; private ImageView avatarView;
private TextView profileNameView; private TextView profileNameView;
private TextView profileNumberView; private TextView profileNumberView;
private TextView profileTagView;
@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) {
@ -64,6 +65,7 @@ public class ProfilePreference extends Preference {
avatarView = (ImageView)viewHolder.findViewById(R.id.avatar); avatarView = (ImageView)viewHolder.findViewById(R.id.avatar);
profileNameView = (TextView)viewHolder.findViewById(R.id.profile_name); profileNameView = (TextView)viewHolder.findViewById(R.id.profile_name);
profileNumberView = (TextView)viewHolder.findViewById(R.id.number); profileNumberView = (TextView)viewHolder.findViewById(R.id.number);
profileTagView = (TextView)viewHolder.findViewById(R.id.tag);
refresh(); refresh();
} }
@ -72,13 +74,15 @@ public class ProfilePreference extends Preference {
if (profileNumberView == null) return; if (profileNumberView == null) return;
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext()); 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()); final String profileName = TextSecurePreferences.getProfileName(getContext());
Context context = getContext(); Context context = getContext();
containerView.setOnLongClickListener(v -> { containerView.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 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); clipboard.setPrimaryClip(clip);
Toast.makeText(context, R.string.activity_settings_public_key_copied_message, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.activity_settings_public_key_copied_message, Toast.LENGTH_SHORT).show();
return true; return true;
@ -100,7 +104,7 @@ public class ProfilePreference extends Preference {
int height = avatarView.getHeight(); int height = avatarView.getHeight();
if (width == 0 || height == 0) return true; if (width == 0 || height == 0) return true;
avatarView.getViewTreeObserver().removeOnPreDrawListener(this); avatarView.getViewTreeObserver().removeOnPreDrawListener(this);
JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, userHexEncodedPublicKey.toLowerCase()); JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, publicKey.toLowerCase());
avatarView.setImageDrawable(identicon); avatarView.setImageDrawable(identicon);
return true; return true;
} }
@ -120,7 +124,9 @@ public class ProfilePreference extends Preference {
} }
profileNameView.setVisibility(TextUtils.isEmpty(profileName) ? View.GONE : View.VISIBLE); profileNameView.setVisibility(TextUtils.isEmpty(profileName) ? View.GONE : View.VISIBLE);
profileNumberView.setText(localAddress.toPhoneString()); profileNumberView.setText(localAddress.toPhoneString());
profileTagView.setVisibility(primaryDevicePublicKey == null ? View.GONE : View.VISIBLE);
profileTagView.setText(R.string.activity_settings_secondary_device_tag);
} }
} }

View File

@ -1183,7 +1183,7 @@ public class TextSecurePreferences {
} }
public static void setMasterHexEncodedPublicKey(Context context, String masterHexEncodedPublicKey) { public static void setMasterHexEncodedPublicKey(Context context, String masterHexEncodedPublicKey) {
setStringPreference(context, "master_hex_encoded_publicKey", masterHexEncodedPublicKey); setStringPreference(context, "master_hex_encoded_public_key", masterHexEncodedPublicKey);
} }
// endregion // endregion
} }