mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Update chat colors.
This commit is contained in:
committed by
Greyson Parrelli
parent
36fe150678
commit
bcc5d485ab
@@ -12,12 +12,9 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
||||
@@ -26,6 +23,8 @@ import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.SystemContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.TransparentContactPhoto;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.MentionSetting;
|
||||
@@ -84,7 +83,6 @@ public class Recipient {
|
||||
private final VibrateState callVibrate;
|
||||
private final Uri messageRingtone;
|
||||
private final Uri callRingtone;
|
||||
private final MaterialColor color;
|
||||
private final Optional<Integer> defaultSubscriptionId;
|
||||
private final int expireMessages;
|
||||
private final RegisteredState registered;
|
||||
@@ -108,6 +106,7 @@ public class Recipient {
|
||||
private final byte[] storageId;
|
||||
private final MentionSetting mentionSetting;
|
||||
private final ChatWallpaper wallpaper;
|
||||
private final ChatColors chatColors;
|
||||
private final String about;
|
||||
private final String aboutEmoji;
|
||||
private final ProfileName systemProfileName;
|
||||
@@ -330,7 +329,6 @@ public class Recipient {
|
||||
this.callVibrate = VibrateState.DEFAULT;
|
||||
this.messageRingtone = null;
|
||||
this.callRingtone = null;
|
||||
this.color = null;
|
||||
this.insightsBannerTier = InsightsBannerTier.TIER_TWO;
|
||||
this.defaultSubscriptionId = Optional.absent();
|
||||
this.expireMessages = 0;
|
||||
@@ -354,6 +352,7 @@ public class Recipient {
|
||||
this.storageId = null;
|
||||
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
|
||||
this.wallpaper = null;
|
||||
this.chatColors = null;
|
||||
this.about = null;
|
||||
this.aboutEmoji = null;
|
||||
this.systemProfileName = ProfileName.EMPTY;
|
||||
@@ -379,7 +378,6 @@ public class Recipient {
|
||||
this.callVibrate = details.callVibrateState;
|
||||
this.messageRingtone = details.messageRingtone;
|
||||
this.callRingtone = details.callRingtone;
|
||||
this.color = details.color;
|
||||
this.insightsBannerTier = details.insightsBannerTier;
|
||||
this.defaultSubscriptionId = details.defaultSubscriptionId;
|
||||
this.expireMessages = details.expireMessages;
|
||||
@@ -403,6 +401,7 @@ public class Recipient {
|
||||
this.storageId = details.storageId;
|
||||
this.mentionSetting = details.mentionSetting;
|
||||
this.wallpaper = details.wallpaper;
|
||||
this.chatColors = details.chatColors;
|
||||
this.about = details.about;
|
||||
this.aboutEmoji = details.aboutEmoji;
|
||||
this.systemProfileName = details.systemProfileName;
|
||||
@@ -556,24 +555,6 @@ public class Recipient {
|
||||
return StringUtil.isolateBidi(name);
|
||||
}
|
||||
|
||||
public @NonNull MaterialColor getColor() {
|
||||
if (isGroupInternal()) {
|
||||
return MaterialColor.GROUP;
|
||||
} else if (color != null) {
|
||||
return color;
|
||||
} else if (groupName != null || profileSharing) {
|
||||
Log.w(TAG, "Had no color for " + id + "! Saving a new one.");
|
||||
|
||||
Context context = ApplicationDependencies.getApplication();
|
||||
MaterialColor color = ContactColors.generateFor(getDisplayName(context));
|
||||
|
||||
SignalExecutors.BOUNDED.execute(() -> DatabaseFactory.getRecipientDatabase(context).setColorIfNotSet(id, color));
|
||||
return color;
|
||||
} else {
|
||||
return ContactColors.UNKNOWN_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
public @NonNull Optional<UUID> getUuid() {
|
||||
return Optional.fromNullable(uuid);
|
||||
}
|
||||
@@ -775,11 +756,11 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted, @Nullable FallbackPhotoProvider fallbackPhotoProvider) {
|
||||
return getFallbackContactPhoto(Util.firstNonNull(fallbackPhotoProvider, DEFAULT_FALLBACK_PHOTO_PROVIDER)).asDrawable(context, getColor().toAvatarColor(context), inverted);
|
||||
return getFallbackContactPhoto(Util.firstNonNull(fallbackPhotoProvider, DEFAULT_FALLBACK_PHOTO_PROVIDER)).asDrawable(context, getChatColors(), inverted);
|
||||
}
|
||||
|
||||
public @NonNull Drawable getSmallFallbackContactPhotoDrawable(Context context, boolean inverted, @Nullable FallbackPhotoProvider fallbackPhotoProvider) {
|
||||
return getFallbackContactPhoto(Util.firstNonNull(fallbackPhotoProvider, DEFAULT_FALLBACK_PHOTO_PROVIDER)).asSmallDrawable(context, getColor().toAvatarColor(context), inverted);
|
||||
return getFallbackContactPhoto(Util.firstNonNull(fallbackPhotoProvider, DEFAULT_FALLBACK_PHOTO_PROVIDER)).asSmallDrawable(context, getChatColors(), inverted);
|
||||
}
|
||||
|
||||
public @NonNull FallbackContactPhoto getFallbackContactPhoto() {
|
||||
@@ -920,6 +901,32 @@ public class Recipient {
|
||||
return wallpaper != null || SignalStore.wallpaper().hasWallpaperSet();
|
||||
}
|
||||
|
||||
public boolean hasOwnChatColors() {
|
||||
return chatColors != null;
|
||||
}
|
||||
|
||||
public @NonNull ChatColors getChatColors() {
|
||||
if (chatColors != null && chatColors.getId() instanceof ChatColors.Id.Auto) {
|
||||
return getAutoChatColor();
|
||||
} else if (chatColors != null) {
|
||||
return chatColors;
|
||||
} else if (SignalStore.chatColorsValues().hasChatColors()) {
|
||||
return Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
|
||||
} else {
|
||||
return getAutoChatColor();
|
||||
}
|
||||
}
|
||||
|
||||
private @NonNull ChatColors getAutoChatColor() {
|
||||
if (wallpaper != null) {
|
||||
return wallpaper.getAutoChatColors();
|
||||
} else if (getWallpaper() != null) {
|
||||
return getWallpaper().getAutoChatColors();
|
||||
} else {
|
||||
return ChatColorsPalette.Bubbles.getDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSystemContact() {
|
||||
return contactUri != null;
|
||||
}
|
||||
@@ -1002,7 +1009,6 @@ public class Recipient {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
|
||||
public enum Capability {
|
||||
UNKNOWN(0),
|
||||
SUPPORTED(1),
|
||||
@@ -1088,7 +1094,6 @@ public class Recipient {
|
||||
callVibrate == other.callVibrate &&
|
||||
Objects.equals(messageRingtone, other.messageRingtone) &&
|
||||
Objects.equals(callRingtone, other.callRingtone) &&
|
||||
color == other.color &&
|
||||
Objects.equals(defaultSubscriptionId, other.defaultSubscriptionId) &&
|
||||
registered == other.registered &&
|
||||
Arrays.equals(profileKey, other.profileKey) &&
|
||||
@@ -1108,6 +1113,7 @@ public class Recipient {
|
||||
Arrays.equals(storageId, other.storageId) &&
|
||||
mentionSetting == other.mentionSetting &&
|
||||
Objects.equals(wallpaper, other.wallpaper) &&
|
||||
Objects.equals(chatColors, other.chatColors) &&
|
||||
Objects.equals(about, other.about) &&
|
||||
Objects.equals(aboutEmoji, other.aboutEmoji) &&
|
||||
Objects.equals(extras, other.extras);
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.InsightsBannerTier;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.MentionSetting;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||
@@ -38,7 +38,6 @@ public class RecipientDetails {
|
||||
final Uri systemContactPhoto;
|
||||
final Uri contactUri;
|
||||
final Optional<Long> groupAvatarId;
|
||||
final MaterialColor color;
|
||||
final Uri messageRingtone;
|
||||
final Uri callRingtone;
|
||||
final long mutedUntil;
|
||||
@@ -67,6 +66,7 @@ public class RecipientDetails {
|
||||
final byte[] storageId;
|
||||
final MentionSetting mentionSetting;
|
||||
final ChatWallpaper wallpaper;
|
||||
final ChatColors chatColors;
|
||||
final String about;
|
||||
final String aboutEmoji;
|
||||
final ProfileName systemProfileName;
|
||||
@@ -91,7 +91,6 @@ public class RecipientDetails {
|
||||
this.e164 = settings.getE164();
|
||||
this.email = settings.getEmail();
|
||||
this.groupId = settings.getGroupId();
|
||||
this.color = settings.getColor();
|
||||
this.messageRingtone = settings.getMessageRingtone();
|
||||
this.callRingtone = settings.getCallRingtone();
|
||||
this.mutedUntil = settings.getMuteUntil();
|
||||
@@ -120,6 +119,7 @@ public class RecipientDetails {
|
||||
this.storageId = settings.getStorageId();
|
||||
this.mentionSetting = settings.getMentionSetting();
|
||||
this.wallpaper = settings.getWallpaper();
|
||||
this.chatColors = settings.getChatColors();
|
||||
this.about = settings.getAbout();
|
||||
this.aboutEmoji = settings.getAboutEmoji();
|
||||
this.systemProfileName = settings.getSystemProfileName();
|
||||
@@ -142,7 +142,6 @@ public class RecipientDetails {
|
||||
this.e164 = null;
|
||||
this.email = null;
|
||||
this.groupId = null;
|
||||
this.color = null;
|
||||
this.messageRingtone = null;
|
||||
this.callRingtone = null;
|
||||
this.mutedUntil = 0;
|
||||
@@ -172,6 +171,7 @@ public class RecipientDetails {
|
||||
this.storageId = null;
|
||||
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
|
||||
this.wallpaper = null;
|
||||
this.chatColors = null;
|
||||
this.about = null;
|
||||
this.aboutEmoji = null;
|
||||
this.systemProfileName = ProfileName.EMPTY;
|
||||
|
||||
@@ -140,7 +140,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
|
||||
avatar.setFallbackPhotoProvider(new Recipient.FallbackPhotoProvider() {
|
||||
@Override
|
||||
public @NonNull FallbackContactPhoto getPhotoForLocalNumber() {
|
||||
return new FallbackPhoto80dp(R.drawable.ic_note_80, recipient.getColor().toAvatarColor(requireContext()));
|
||||
return new FallbackPhoto80dp(R.drawable.ic_note_80, recipient.getChatColors());
|
||||
}
|
||||
});
|
||||
avatar.setAvatar(recipient);
|
||||
|
||||
@@ -14,31 +14,25 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.widget.TextViewCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.takisoft.colorpicker.ColorPickerDialog;
|
||||
import com.takisoft.colorpicker.ColorStateDrawable;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.thoughtcrime.securesms.AvatarPreviewActivity;
|
||||
import org.thoughtcrime.securesms.LoggingFragment;
|
||||
import org.thoughtcrime.securesms.MediaPreviewActivity;
|
||||
import org.thoughtcrime.securesms.MuteDialog;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.color.MaterialColors;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.FallbackPhoto80dp;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.groups.ui.GroupMemberListView;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -89,8 +83,6 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
private View disappearingMessagesCard;
|
||||
private View disappearingMessagesRow;
|
||||
private TextView disappearingMessages;
|
||||
private View colorRow;
|
||||
private ImageView colorChip;
|
||||
private View blockUnblockCard;
|
||||
private TextView block;
|
||||
private TextView unblock;
|
||||
@@ -109,7 +101,7 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
private View secureCallButton;
|
||||
private View insecureCallButton;
|
||||
private View secureVideoCallButton;
|
||||
private View chatWallpaperButton;
|
||||
private TextView chatWallpaperButton;
|
||||
|
||||
static ManageRecipientFragment newInstance(@NonNull RecipientId recipientId, boolean fromConversation) {
|
||||
ManageRecipientFragment fragment = new ManageRecipientFragment();
|
||||
@@ -148,8 +140,6 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
disappearingMessagesCard = view.findViewById(R.id.recipient_disappearing_messages_card);
|
||||
disappearingMessagesRow = view.findViewById(R.id.disappearing_messages_row);
|
||||
disappearingMessages = view.findViewById(R.id.disappearing_messages);
|
||||
colorRow = view.findViewById(R.id.color_row);
|
||||
colorChip = view.findViewById(R.id.color_chip);
|
||||
blockUnblockCard = view.findViewById(R.id.recipient_block_and_leave_card);
|
||||
block = view.findViewById(R.id.block);
|
||||
unblock = view.findViewById(R.id.unblock);
|
||||
@@ -294,6 +284,10 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
}
|
||||
|
||||
private void presentRecipient(@NonNull Recipient recipient) {
|
||||
Drawable colorCircle = recipient.getChatColors().asCircle();
|
||||
colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
|
||||
TextViewCompat.setCompoundDrawablesRelative(chatWallpaperButton, null, null, colorCircle, null);
|
||||
|
||||
if (recipient.isSystemContact()) {
|
||||
contactText.setText(R.string.ManageRecipientActivity_this_person_is_in_your_contacts);
|
||||
contactIcon.setVisibility(View.VISIBLE);
|
||||
@@ -315,16 +309,16 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
disappearingMessagesCard.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE);
|
||||
addToAGroup.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE);
|
||||
|
||||
MaterialColor recipientColor = recipient.getColor();
|
||||
ChatColors recipientColor = recipient.getChatColors();
|
||||
avatar.setFallbackPhotoProvider(new Recipient.FallbackPhotoProvider() {
|
||||
@Override
|
||||
public @NonNull FallbackContactPhoto getPhotoForRecipientWithoutName() {
|
||||
return new FallbackPhoto80dp(R.drawable.ic_profile_80, recipientColor.toAvatarColor(requireContext()));
|
||||
return new FallbackPhoto80dp(R.drawable.ic_profile_80, recipientColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull FallbackContactPhoto getPhotoForLocalNumber() {
|
||||
return new FallbackPhoto80dp(R.drawable.ic_note_80, recipientColor.toAvatarColor(requireContext()));
|
||||
return new FallbackPhoto80dp(R.drawable.ic_note_80, recipientColor);
|
||||
}
|
||||
});
|
||||
avatar.setAvatar(recipient);
|
||||
@@ -334,11 +328,6 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
AvatarPreviewActivity.createTransitionBundle(activity, avatar));
|
||||
});
|
||||
|
||||
@ColorInt int color = recipientColor.toActionBarColor(requireContext());
|
||||
Drawable[] colorDrawable = new Drawable[]{ContextCompat.getDrawable(requireContext(), R.drawable.colorpickerpreference_pref_swatch)};
|
||||
colorChip.setImageDrawable(new ColorStateDrawable(colorDrawable, color));
|
||||
colorRow.setOnClickListener(v -> handleColorSelection(color));
|
||||
|
||||
secureCallButton.setVisibility(recipient.isRegistered() && !recipient.isSelf() ? View.VISIBLE : View.GONE);
|
||||
insecureCallButton.setVisibility(!recipient.isRegistered() && !recipient.isSelf() ? View.VISIBLE : View.GONE);
|
||||
secureVideoCallButton.setVisibility(recipient.isRegistered() && !recipient.isSelf() ? View.VISIBLE : View.GONE);
|
||||
@@ -385,22 +374,6 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleColorSelection(@ColorInt int currentColor) {
|
||||
@ColorInt int[] colors = MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireContext());
|
||||
|
||||
ColorPickerDialog.Params params = new ColorPickerDialog.Params.Builder(requireContext())
|
||||
.setSelectedColor(currentColor)
|
||||
.setColors(colors)
|
||||
.setSize(ColorPickerDialog.SIZE_SMALL)
|
||||
.setSortColors(false)
|
||||
.setColumns(3)
|
||||
.build();
|
||||
|
||||
ColorPickerDialog dialog = new ColorPickerDialog(requireActivity(), color -> viewModel.onSelectColor(color), params);
|
||||
dialog.setTitle(R.string.ManageRecipientActivity_chat_color);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_edit) {
|
||||
startActivity(EditProfileActivity.getIntentForUserProfileEdit(requireActivity()));
|
||||
|
||||
@@ -82,16 +82,6 @@ final class ManageRecipientRepository {
|
||||
SignalExecutors.BOUNDED.execute(() -> DatabaseFactory.getRecipientDatabase(context).setMuted(recipientId, until));
|
||||
}
|
||||
|
||||
void setColor(int color) {
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
MaterialColor selectedColor = MaterialColors.CONVERSATION_PALETTE.getByColor(context, color);
|
||||
if (selectedColor != null) {
|
||||
DatabaseFactory.getRecipientDatabase(context).setColor(recipientId, selectedColor);
|
||||
ApplicationDependencies.getJobManager().add(new MultiDeviceContactUpdateJob(recipientId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void refreshRecipient() {
|
||||
SignalExecutors.UNBOUNDED.execute(() -> {
|
||||
try {
|
||||
|
||||
@@ -240,10 +240,6 @@ public final class ManageRecipientViewModel extends ViewModel {
|
||||
return sharedGroupsCountSummary;
|
||||
}
|
||||
|
||||
void onSelectColor(int color) {
|
||||
manageRecipientRepository.setColor(color);
|
||||
}
|
||||
|
||||
void onGroupClicked(@NonNull Activity activity, @NonNull Recipient recipient) {
|
||||
CommunicationActions.startConversation(activity, recipient, null);
|
||||
activity.finish();
|
||||
|
||||
Reference in New Issue
Block a user