Add support for new story gradient fields and fallback.
This commit is contained in:
parent
2e2b31aa79
commit
f751f9afa8
7 changed files with 110 additions and 98 deletions
|
@ -5,90 +5,62 @@ import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
|||
object TextStoryBackgroundColors {
|
||||
|
||||
private val backgroundColors: List<ChatColors> = listOf(
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF688BD4.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF8687C1.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFB47F8C.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF899188.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF539383.toInt()
|
||||
),
|
||||
ChatColors.forGradient(
|
||||
id = ChatColors.Id.NotSet,
|
||||
linearGradient = ChatColors.LinearGradient(
|
||||
degrees = 191.41f,
|
||||
colors = intArrayOf(0xFFF53844.toInt(), 0xFF42378F.toInt()),
|
||||
positions = floatArrayOf(0f, 1.0f)
|
||||
colors = intArrayOf(
|
||||
0xFF19A9FA.toInt(), 0xFF7097D7.toInt(), 0xFFD1998D.toInt(), 0xFFFFC369.toInt()
|
||||
),
|
||||
positions = floatArrayOf(
|
||||
0f, 0.33f, 0.66f, 1f
|
||||
),
|
||||
degrees = 180f
|
||||
)
|
||||
),
|
||||
ChatColors.forGradient(
|
||||
id = ChatColors.Id.NotSet,
|
||||
linearGradient = ChatColors.LinearGradient(
|
||||
degrees = 192.04f,
|
||||
colors = intArrayOf(0xFFF04CE6.toInt(), 0xFF0E2FDD.toInt()),
|
||||
positions = floatArrayOf(0.0f, 1.0f)
|
||||
),
|
||||
),
|
||||
ChatColors.forGradient(
|
||||
id = ChatColors.Id.NotSet,
|
||||
linearGradient = ChatColors.LinearGradient(
|
||||
degrees = 175.46f,
|
||||
colors = intArrayOf(0xFFFFC044.toInt(), 0xFFFE5C38.toInt()),
|
||||
positions = floatArrayOf(0f, 1f)
|
||||
colors = intArrayOf(
|
||||
0xFF4437D8.toInt(), 0xFF6B70DE.toInt(), 0xFFB774E0.toInt(), 0xFFFF8E8E.toInt()
|
||||
),
|
||||
positions = floatArrayOf(
|
||||
0f, 0.33f, 0.66f, 1f
|
||||
),
|
||||
degrees = 180f
|
||||
)
|
||||
),
|
||||
ChatColors.forGradient(
|
||||
id = ChatColors.Id.NotSet,
|
||||
linearGradient = ChatColors.LinearGradient(
|
||||
degrees = 180f,
|
||||
colors = intArrayOf(0xFF0093E9.toInt(), 0xFF80D0C7.toInt()),
|
||||
positions = floatArrayOf(0.0f, 1.0f)
|
||||
colors = intArrayOf(
|
||||
0xFF004044.toInt(), 0xFF2C5F45.toInt(), 0xFF648E52.toInt(), 0xFF93B864.toInt()
|
||||
),
|
||||
positions = floatArrayOf(
|
||||
0f, 0.33f, 0.66f, 1f
|
||||
),
|
||||
degrees = 180f
|
||||
)
|
||||
),
|
||||
ChatColors.forGradient(
|
||||
id = ChatColors.Id.NotSet,
|
||||
linearGradient = ChatColors.LinearGradient(
|
||||
degrees = 180f,
|
||||
colors = intArrayOf(0xFF65CDAC.toInt(), 0xFF0A995A.toInt()),
|
||||
positions = floatArrayOf(0.0f, 1.0f)
|
||||
)
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFFFC153.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFCCBD33.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF84712E.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF09B37B.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF8B8BF9.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF5151F6.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFF76E6E.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFC84641.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFC6C4A5.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFFA49595.toInt()
|
||||
),
|
||||
ChatColors.forColor(
|
||||
id = ChatColors.Id.NotSet,
|
||||
color = 0xFF292929.toInt()
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
fun getInitialBackgroundColor(): ChatColors = backgroundColors.first()
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.messages;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
@ -49,7 +50,6 @@ import org.thoughtcrime.securesms.database.SentStorySyncManifest;
|
|||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.StickerDatabase;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.DistributionListRecord;
|
||||
import org.thoughtcrime.securesms.database.model.Mention;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.MessageLogEntry;
|
||||
|
@ -1473,9 +1473,25 @@ public final class MessageContentProcessor {
|
|||
ChatColor.LinearGradient.Builder linearGradientBuilder = ChatColor.LinearGradient.newBuilder();
|
||||
|
||||
linearGradientBuilder.setRotation(gradient.getAngle().orElse(0).floatValue());
|
||||
linearGradientBuilder.addColors(gradient.getStartColor().get());
|
||||
linearGradientBuilder.addColors(gradient.getEndColor().get());
|
||||
linearGradientBuilder.addAllPositions(Arrays.asList(0f, 1f));
|
||||
|
||||
if (gradient.getPositions().size() > 1 && gradient.getColors().size() == gradient.getPositions().size()) {
|
||||
ArrayList<Float> positions = new ArrayList<>(gradient.getPositions());
|
||||
|
||||
positions.set(0, 0f);
|
||||
positions.set(positions.size() - 1, 1f);
|
||||
|
||||
linearGradientBuilder.addAllColors(new ArrayList<>(gradient.getColors()));
|
||||
linearGradientBuilder.addAllPositions(positions);
|
||||
} else if (!gradient.getColors().isEmpty()) {
|
||||
Log.w(TAG, "Incoming text story has color / position mismatch. Defaulting to start and end colors.");
|
||||
linearGradientBuilder.addColors(gradient.getColors().get(0));
|
||||
linearGradientBuilder.addColors(gradient.getColors().get(gradient.getColors().size() - 1));
|
||||
linearGradientBuilder.addAllPositions(Arrays.asList(0f, 1f));
|
||||
} else {
|
||||
Log.w(TAG, "Incoming text story did not have a valid linear gradient.");
|
||||
linearGradientBuilder.addAllColors(Arrays.asList(Color.BLACK, Color.BLACK));
|
||||
linearGradientBuilder.addAllPositions(Arrays.asList(0f, 1f));
|
||||
}
|
||||
|
||||
chatColorBuilder.setLinearGradient(linearGradientBuilder);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ object StorySendUtil {
|
|||
Optional.of(storyTextPost.textBackgroundColor),
|
||||
preview,
|
||||
SignalServiceTextAttachment.Gradient(
|
||||
Optional.of(storyTextPost.background.linearGradient.getColors(0)),
|
||||
Optional.of(storyTextPost.background.linearGradient.getColors(1)),
|
||||
Optional.of(storyTextPost.background.linearGradient.rotation.roundToInt())
|
||||
Optional.of(storyTextPost.background.linearGradient.rotation.roundToInt()),
|
||||
ArrayList(storyTextPost.background.linearGradient.colorsList),
|
||||
ArrayList(storyTextPost.background.linearGradient.positionsList)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
|
|
@ -2116,9 +2116,15 @@ public class SignalServiceMessageSender {
|
|||
if (attachment.getBackgroundGradient().isPresent()) {
|
||||
SignalServiceTextAttachment.Gradient gradient = attachment.getBackgroundGradient().get();
|
||||
|
||||
if (gradient.getStartColor().isPresent()) gradientBuilder.setStartColor(gradient.getStartColor().get());
|
||||
if (gradient.getEndColor().isPresent()) gradientBuilder.setEndColor(gradient.getEndColor().get());
|
||||
if (gradient.getAngle().isPresent()) gradientBuilder.setAngle(gradient.getAngle().get());
|
||||
if (gradient.getAngle().isPresent()) gradientBuilder.setAngle(gradient.getAngle().get());
|
||||
|
||||
if (!gradient.getColors().isEmpty()) {
|
||||
gradientBuilder.setStartColor(gradient.getColors().get(0));
|
||||
gradientBuilder.setEndColor(gradient.getColors().get(gradient.getColors().size() - 1));
|
||||
}
|
||||
|
||||
gradientBuilder.addAllColors(gradient.getColors());
|
||||
gradientBuilder.addAllPositions(gradient.getPositions());
|
||||
|
||||
builder.setGradient(gradientBuilder.build());
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.whispersystems.signalservice.internal.serialize.SignalServiceMetadata
|
|||
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -1424,9 +1425,23 @@ public final class SignalServiceContent {
|
|||
Integer startColor = attachmentGradient.hasStartColor() ? attachmentGradient.getStartColor() : null;
|
||||
Integer endColor = attachmentGradient.hasEndColor() ? attachmentGradient.getEndColor() : null;
|
||||
Integer angle = attachmentGradient.hasAngle() ? attachmentGradient.getAngle() : null;
|
||||
SignalServiceTextAttachment.Gradient gradient = new SignalServiceTextAttachment.Gradient(Optional.ofNullable(startColor),
|
||||
Optional.ofNullable(endColor),
|
||||
Optional.ofNullable(angle));
|
||||
List<Integer> colors;
|
||||
List<Float> positions;
|
||||
|
||||
if (attachmentGradient.getColorsCount() > 0 && attachmentGradient.getColorsCount() == attachmentGradient.getPositionsCount()) {
|
||||
colors = new ArrayList<>(attachmentGradient.getColorsList());
|
||||
positions = new ArrayList<>(attachmentGradient.getPositionsList());
|
||||
} else if (startColor != null && endColor != null) {
|
||||
colors = Arrays.asList(startColor, endColor);
|
||||
positions = Arrays.asList(0f, 1f);
|
||||
} else {
|
||||
colors = Collections.emptyList();
|
||||
positions = Collections.emptyList();
|
||||
}
|
||||
|
||||
SignalServiceTextAttachment.Gradient gradient = new SignalServiceTextAttachment.Gradient(Optional.ofNullable(angle),
|
||||
colors,
|
||||
positions);
|
||||
|
||||
return SignalServiceTextAttachment.forGradientBackground(text, Optional.ofNullable(style), textForegroundColor, textBackgroundColor, preview, gradient);
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.whispersystems.signalservice.api.messages;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SignalServiceTextAttachment {
|
||||
|
@ -88,27 +89,27 @@ public class SignalServiceTextAttachment {
|
|||
}
|
||||
|
||||
public static class Gradient {
|
||||
private final Optional<Integer> startColor;
|
||||
private final Optional<Integer> endColor;
|
||||
private final Optional<Integer> angle;
|
||||
private final List<Integer> colors;
|
||||
private final List<Float> positions;
|
||||
|
||||
public Gradient(Optional<Integer> startColor, Optional<Integer> endColor, Optional<Integer> angle) {
|
||||
this.startColor = startColor;
|
||||
this.endColor = endColor;
|
||||
public Gradient(Optional<Integer> angle, List<Integer> colors, List<Float> positions) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public Optional<Integer> getStartColor() {
|
||||
return startColor;
|
||||
}
|
||||
|
||||
public Optional<Integer> getEndColor() {
|
||||
return endColor;
|
||||
this.colors = colors;
|
||||
this.positions = positions;
|
||||
}
|
||||
|
||||
public Optional<Integer> getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
public List<Integer> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public List<Float> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Style {
|
||||
|
|
|
@ -392,9 +392,11 @@ message TextAttachment {
|
|||
}
|
||||
|
||||
message Gradient {
|
||||
optional uint32 startColor = 1;
|
||||
optional uint32 endColor = 2;
|
||||
optional uint32 startColor = 1; // deprecated: this field will be removed in a future release.
|
||||
optional uint32 endColor = 2; // deprecated: this field will be removed in a future release.
|
||||
optional uint32 angle = 3; // degrees
|
||||
repeated uint32 colors = 4;
|
||||
repeated float positions = 5; // percent from 0 to 1
|
||||
}
|
||||
|
||||
optional string text = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue