From edbffe72114f7363d4d69df5db3af5395d15203a Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 18 Nov 2019 12:43:26 +1100 Subject: [PATCH 1/3] Disable linking devices once we hit a cap. --- .../ApplicationPreferencesActivity.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 9e55810f50..77dbd53d0b 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -36,12 +36,15 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v4.util.ArraySet; import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; import android.widget.Toast; import org.jetbrains.annotations.NotNull; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; +import org.thoughtcrime.securesms.database.Database; +import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.loki.DeviceLinkingDialog; import org.thoughtcrime.securesms.loki.DeviceLinkingDialogDelegate; import org.thoughtcrime.securesms.loki.DeviceLinkingView; @@ -56,12 +59,14 @@ import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.whispersystems.signalservice.loki.api.LokiStorageAPI; import org.whispersystems.signalservice.loki.api.PairingAuthorisation; import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; import org.whispersystems.signalservice.loki.utilities.Analytics; import org.whispersystems.signalservice.loki.utilities.SerializationKt; import java.io.File; +import java.util.Set; import network.loki.messenger.R; @@ -192,10 +197,20 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA .setOnPreferenceClickListener(new CategoryClickListener(getContext(), PREFERENCE_CATEGORY_QR_CODE)); Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE); - // Hide if this is a slave device - linkDevicePreference.setVisible(isMasterDevice); linkDevicePreference.setOnPreferenceClickListener(new CategoryClickListener(getContext(), PREFERENCE_CATEGORY_LINK_DEVICE)); + // Disable if we hit the cap of 1 linked device + if (isMasterDevice) { + Context context = getContext(); + String ourNumber = TextSecurePreferences.getLocalNumber(context); + boolean shouldEnableDeviceLinking = DatabaseFactory.getLokiAPIDatabase(context).getPairingAuthorisations(ourNumber).size() <= 1; + linkDevicePreference.setEnabled(shouldEnableDeviceLinking); + linkDevicePreference.getIcon().setAlpha(shouldEnableDeviceLinking ? 255 : 124); + } else { + // Hide if this is a slave device + linkDevicePreference.setVisible(false); + } + Preference seedPreference = this.findPreference(PREFERENCE_CATEGORY_SEED); // Hide if this is a slave device seedPreference.setVisible(isMasterDevice); From 35ee1c139157b62a86716e73385aa49bf66e8727 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 18 Nov 2019 13:02:19 +1100 Subject: [PATCH 2/3] Fix avatar images not being updated correctly. --- .../securesms/components/AvatarImageView.java | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index 6eae6b42aa..53ce56c737 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -104,38 +104,22 @@ public class AvatarImageView extends AppCompatImageView { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - if (w == 0 || h == 0 || recipient == null) { return; } - - Drawable image; - Context context = this.getContext(); - if (recipient.isGroupRecipient()) { - - - String name = Optional.fromNullable(recipient.getName()).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context))).or(""); - MaterialColor fallbackColor = recipient.getColor(); - - if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) { - fallbackColor = ContactColors.generateFor(name); - } - - image = new GeneratedContactPhoto(name, R.drawable.ic_profile_default).asDrawable(context, fallbackColor.toAvatarColor(context)); - } else { - // Default to primary device image - String ourPublicKey = TextSecurePreferences.getLocalNumber(context); - String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String recipientAddress = recipient.getAddress().serialize(); - String profileAddress = (ourPrimaryDevice != null && ourPublicKey.equals(recipientAddress)) ? ourPrimaryDevice : recipientAddress; - image = new JazzIdenticonDrawable(w, h, profileAddress.toLowerCase()); - } - setImageDrawable(image); + updateImage(w, h); } public void update(String hexEncodedPublicKey) { - this.recipient = Recipient.from(getContext(), Address.fromSerialized(hexEncodedPublicKey), false); + Address address = Address.fromSerialized(hexEncodedPublicKey); + if (!address.equals(recipient.getAddress())) { + this.recipient = Recipient.from(getContext(), address, false); + updateImage(); + } } public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) { - this.recipient = recipient; + if (this.recipient == null || !this.recipient.equals(recipient)) { + this.recipient = recipient; + updateImage(); + } /* if (recipient != null) { requestManager.load(recipient.getContactPhoto()) @@ -170,4 +154,32 @@ public class AvatarImageView extends AppCompatImageView { } } + private void updateImage() { updateImage(getWidth(), getHeight()); } + private void updateImage(int w, int h) { + if (w == 0 || h == 0 || recipient == null) { return; } + + Drawable image; + Context context = this.getContext(); + if (recipient.isGroupRecipient()) { + + + String name = Optional.fromNullable(recipient.getName()).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context))).or(""); + MaterialColor fallbackColor = recipient.getColor(); + + if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) { + fallbackColor = ContactColors.generateFor(name); + } + + image = new GeneratedContactPhoto(name, R.drawable.ic_profile_default).asDrawable(context, fallbackColor.toAvatarColor(context)); + } else { + // Default to primary device image + String ourPublicKey = TextSecurePreferences.getLocalNumber(context); + String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context); + String recipientAddress = recipient.getAddress().serialize(); + String profileAddress = (ourPrimaryDevice != null && ourPublicKey.equals(recipientAddress)) ? ourPrimaryDevice : recipientAddress; + image = new JazzIdenticonDrawable(w, h, profileAddress.toLowerCase()); + } + setImageDrawable(image); + } + } From e785eab28b1202da767ee3979a686ee96bb09427 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 18 Nov 2019 13:21:52 +1100 Subject: [PATCH 3/3] Clean --- .../securesms/ApplicationPreferencesActivity.java | 12 ++++-------- .../securesms/components/AvatarImageView.java | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 77dbd53d0b..f9309eaf83 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -36,14 +36,12 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v4.util.ArraySet; import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; import android.widget.Toast; import org.jetbrains.annotations.NotNull; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; -import org.thoughtcrime.securesms.database.Database; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.loki.DeviceLinkingDialog; import org.thoughtcrime.securesms.loki.DeviceLinkingDialogDelegate; @@ -59,14 +57,12 @@ import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.whispersystems.signalservice.loki.api.LokiStorageAPI; import org.whispersystems.signalservice.loki.api.PairingAuthorisation; import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; import org.whispersystems.signalservice.loki.utilities.Analytics; import org.whispersystems.signalservice.loki.utilities.SerializationKt; import java.io.File; -import java.util.Set; import network.loki.messenger.R; @@ -202,10 +198,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA // Disable if we hit the cap of 1 linked device if (isMasterDevice) { Context context = getContext(); - String ourNumber = TextSecurePreferences.getLocalNumber(context); - boolean shouldEnableDeviceLinking = DatabaseFactory.getLokiAPIDatabase(context).getPairingAuthorisations(ourNumber).size() <= 1; - linkDevicePreference.setEnabled(shouldEnableDeviceLinking); - linkDevicePreference.getIcon().setAlpha(shouldEnableDeviceLinking ? 255 : 124); + String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context); + boolean isDeviceLinkingEnabled = DatabaseFactory.getLokiAPIDatabase(context).getPairingAuthorisations(userHexEncodedPublicKey).size() <= 1; + linkDevicePreference.setEnabled(isDeviceLinkingEnabled); + linkDevicePreference.getIcon().setAlpha(isDeviceLinkingEnabled ? 255 : 124); } else { // Hide if this is a slave device linkDevicePreference.setVisible(false); diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index 53ce56c737..28598f4700 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -155,14 +155,14 @@ public class AvatarImageView extends AppCompatImageView { } private void updateImage() { updateImage(getWidth(), getHeight()); } + private void updateImage(int w, int h) { if (w == 0 || h == 0 || recipient == null) { return; } Drawable image; Context context = this.getContext(); + if (recipient.isGroupRecipient()) { - - String name = Optional.fromNullable(recipient.getName()).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context))).or(""); MaterialColor fallbackColor = recipient.getColor();