mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-08 09:18:39 +01:00
Add support for new story gradient fields and fallback.
This commit is contained in:
committed by
Greyson Parrelli
parent
2e2b31aa79
commit
f751f9afa8
+9
-3
@@ -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());
|
||||
}
|
||||
|
||||
+18
-3
@@ -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 {
|
||||
|
||||
+14
-13
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user