Update badge configuration to new style
This commit is contained in:
parent
1af53f2612
commit
5f2656710c
|
@ -7,44 +7,29 @@ package org.whispersystems.textsecuregcm.configuration;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.whispersystems.textsecuregcm.util.ExactlySize;
|
||||
|
||||
public class BadgeConfiguration {
|
||||
public static final String CATEGORY_TESTING = "testing";
|
||||
|
||||
private final String id;
|
||||
private final String category;
|
||||
private final String ldpi;
|
||||
private final String mdpi;
|
||||
private final String hdpi;
|
||||
private final String xhdpi;
|
||||
private final String xxhdpi;
|
||||
private final String xxxhdpi;
|
||||
private final String lowDetailSvg;
|
||||
private final String highDetailSvg;
|
||||
private final List<String> sprites;
|
||||
private final List<String> svgs;
|
||||
|
||||
@JsonCreator
|
||||
public BadgeConfiguration(
|
||||
@JsonProperty("id") final String id,
|
||||
@JsonProperty("category") final String category,
|
||||
@JsonProperty("ldpi") final String ldpi,
|
||||
@JsonProperty("mdpi") final String mdpi,
|
||||
@JsonProperty("hdpi") final String hdpi,
|
||||
@JsonProperty("xhdpi") final String xhdpi,
|
||||
@JsonProperty("xxhdpi") final String xxhdpi,
|
||||
@JsonProperty("xxxhdpi") final String xxxhdpi,
|
||||
@JsonProperty("lowDetailSvg") final String lowDetailSvg,
|
||||
@JsonProperty("highDetailSvg") final String highDetailSvg) {
|
||||
@JsonProperty("sprites") final List<String> sprites,
|
||||
@JsonProperty("svgs") final List<String> svgs) {
|
||||
this.id = id;
|
||||
this.category = category;
|
||||
this.ldpi = ldpi;
|
||||
this.mdpi = mdpi;
|
||||
this.hdpi = hdpi;
|
||||
this.xhdpi = xhdpi;
|
||||
this.xxhdpi = xxhdpi;
|
||||
this.xxxhdpi = xxxhdpi;
|
||||
this.lowDetailSvg = lowDetailSvg;
|
||||
this.highDetailSvg = highDetailSvg;
|
||||
this.sprites = sprites;
|
||||
this.svgs = svgs;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
|
@ -57,47 +42,59 @@ public class BadgeConfiguration {
|
|||
return category;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getLdpi() {
|
||||
return ldpi;
|
||||
@NotNull
|
||||
@ExactlySize(6)
|
||||
public List<String> getSprites() {
|
||||
return sprites;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getMdpi() {
|
||||
return mdpi;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getHdpi() {
|
||||
return hdpi;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getXhdpi() {
|
||||
return xhdpi;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getXxhdpi() {
|
||||
return xxhdpi;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getXxxhdpi() {
|
||||
return xxxhdpi;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getLowDetailSvg() {
|
||||
return lowDetailSvg;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getHighDetailSvg() {
|
||||
return highDetailSvg;
|
||||
@NotNull
|
||||
@ExactlySize(4)
|
||||
public List<String> getSvgs() {
|
||||
return svgs;
|
||||
}
|
||||
|
||||
public boolean isTestBadge() {
|
||||
return CATEGORY_TESTING.equals(category);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLdpi() {
|
||||
return sprites.get(0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMdpi() {
|
||||
return sprites.get(1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHdpi() {
|
||||
return sprites.get(2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXhdpi() {
|
||||
return sprites.get(3);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXxhdpi() {
|
||||
return sprites.get(4);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXxxhdpi() {
|
||||
return sprites.get(5);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLowDetailSvg() {
|
||||
return svgs.get(0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHighDetailSvg() {
|
||||
return svgs.get(3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.validation.Payload;
|
|||
@Constraint(validatedBy = {
|
||||
ExactlySizeValidatorForString.class,
|
||||
ExactlySizeValidatorForArraysOfByte.class,
|
||||
ExactlySizeValidatorForCollection.class,
|
||||
})
|
||||
@Documented
|
||||
public @interface ExactlySize {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright 2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ExactlySizeValidatorForCollection extends ExactlySizeValidator<Collection<?>> {
|
||||
|
||||
@Override
|
||||
protected int size(final Collection<?> value) {
|
||||
return value == null ? 0 : value.size();
|
||||
}
|
||||
}
|
|
@ -64,7 +64,8 @@ public class ConfiguredProfileBadgeConverterTest {
|
|||
}
|
||||
|
||||
private static BadgeConfiguration newBadge(int i) {
|
||||
return new BadgeConfiguration(idFor(i), "other", "l", "m", "h", "x", "xx", "xxx", "s", "S");
|
||||
return new BadgeConfiguration(
|
||||
idFor(i), "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"));
|
||||
}
|
||||
|
||||
private BadgesConfiguration createBadges(int count) {
|
||||
|
|
|
@ -89,10 +89,10 @@ class DonationControllerTest {
|
|||
static BadgesConfiguration getBadgesConfiguration() {
|
||||
return new BadgesConfiguration(
|
||||
List.of(
|
||||
new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S")),
|
||||
new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST1", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST2", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"))),
|
||||
List.of("TEST"),
|
||||
Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3"));
|
||||
}
|
||||
|
|
|
@ -112,10 +112,10 @@ class ProfileControllerTest {
|
|||
new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx", "s", "S")
|
||||
),
|
||||
new BadgesConfiguration(List.of(
|
||||
new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"),
|
||||
new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S")
|
||||
new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST1", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST2", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"))
|
||||
), List.of("TEST1"), Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3")),
|
||||
s3client,
|
||||
postPolicyGenerator,
|
||||
|
|
Loading…
Reference in New Issue