mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-01 21:41:45 +00:00
Merge pull request #43 from loki-project/device_cap
Set linked device cap to 1
This commit is contained in:
commit
2a4eaf9644
@ -42,6 +42,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.loki.DeviceLinkingDialog;
|
import org.thoughtcrime.securesms.loki.DeviceLinkingDialog;
|
||||||
import org.thoughtcrime.securesms.loki.DeviceLinkingDialogDelegate;
|
import org.thoughtcrime.securesms.loki.DeviceLinkingDialogDelegate;
|
||||||
import org.thoughtcrime.securesms.loki.DeviceLinkingView;
|
import org.thoughtcrime.securesms.loki.DeviceLinkingView;
|
||||||
@ -192,10 +193,20 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
|||||||
.setOnPreferenceClickListener(new CategoryClickListener(getContext(), PREFERENCE_CATEGORY_QR_CODE));
|
.setOnPreferenceClickListener(new CategoryClickListener(getContext(), PREFERENCE_CATEGORY_QR_CODE));
|
||||||
|
|
||||||
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
|
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));
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
Preference seedPreference = this.findPreference(PREFERENCE_CATEGORY_SEED);
|
Preference seedPreference = this.findPreference(PREFERENCE_CATEGORY_SEED);
|
||||||
// Hide if this is a slave device
|
// Hide if this is a slave device
|
||||||
seedPreference.setVisible(isMasterDevice);
|
seedPreference.setVisible(isMasterDevice);
|
||||||
|
@ -104,38 +104,22 @@ public class AvatarImageView extends AppCompatImageView {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
if (w == 0 || h == 0 || recipient == null) { return; }
|
updateImage(w, h);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(String hexEncodedPublicKey) {
|
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) {
|
public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) {
|
||||||
|
if (this.recipient == null || !this.recipient.equals(recipient)) {
|
||||||
this.recipient = recipient;
|
this.recipient = recipient;
|
||||||
|
updateImage();
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
if (recipient != null) {
|
if (recipient != null) {
|
||||||
requestManager.load(recipient.getContactPhoto())
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user