Move to using collections for sprites and svgs for badges

This commit is contained in:
Ehren Kret 2021-10-13 23:25:39 -05:00
parent e07597eba7
commit 64eeb1e361
6 changed files with 59 additions and 135 deletions

View File

@ -104,14 +104,8 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
configuration.getCategory(), configuration.getCategory(),
resourceBundle.getString(accountBadge.getId() + "_name"), resourceBundle.getString(accountBadge.getId() + "_name"),
resourceBundle.getString(accountBadge.getId() + "_description"), resourceBundle.getString(accountBadge.getId() + "_description"),
configuration.getLdpi(), configuration.getSprites(),
configuration.getMdpi(), configuration.getSvgs(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
configuration.getLowDetailSvg(),
configuration.getHighDetailSvg(),
accountBadge.getExpiration(), accountBadge.getExpiration(),
accountBadge.isVisible()); accountBadge.isVisible());
}) })
@ -124,14 +118,8 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
configuration.getCategory(), configuration.getCategory(),
resourceBundle.getString(id + "_name"), resourceBundle.getString(id + "_name"),
resourceBundle.getString(id + "_description"), resourceBundle.getString(id + "_description"),
configuration.getLdpi(), configuration.getSprites(),
configuration.getMdpi(), configuration.getSvgs(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
configuration.getLowDetailSvg(),
configuration.getHighDetailSvg(),
now.plus(Duration.ofDays(1)), now.plus(Duration.ofDays(1)),
true); true);
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
@ -144,20 +132,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
final String category, final String category,
final String name, final String name,
final String description, final String description,
final String ldpi, final List<String> sprites,
final String mdpi, final List<String> svgs,
final String hdpi,
final String xhdpi,
final String xxhdpi,
final String xxxhdpi,
final String lsvg,
final String hsvg,
final Instant expiration, final Instant expiration,
final boolean visible) { final boolean visible) {
if (isSelf) { if (isSelf) {
return new SelfBadge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, lsvg, hsvg, expiration, visible); return new SelfBadge(id, category, name, description, sprites, svgs, expiration, visible);
} else { } else {
return new Badge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, lsvg, hsvg); return new Badge(id, category, name, description, sprites, svgs);
} }
} }
} }

View File

@ -57,44 +57,4 @@ public class BadgeConfiguration {
public boolean isTestBadge() { public boolean isTestBadge() {
return CATEGORY_TESTING.equals(category); 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);
}
} }

View File

@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class Badge { public class Badge {
@ -14,14 +15,8 @@ public class Badge {
private final String category; private final String category;
private final String name; private final String name;
private final String description; private final String description;
private final String ldpi; private final List<String> sprites6;
private final String mdpi; private final List<String> svgs4;
private final String hdpi;
private final String xhdpi;
private final String xxhdpi;
private final String xxxhdpi;
private final String lsvg;
private final String hsvg;
@JsonCreator @JsonCreator
public Badge( public Badge(
@ -29,26 +24,20 @@ public class Badge {
@JsonProperty("category") final String category, @JsonProperty("category") final String category,
@JsonProperty("name") final String name, @JsonProperty("name") final String name,
@JsonProperty("description") final String description, @JsonProperty("description") final String description,
@JsonProperty("ldpi") final String ldpi, @JsonProperty("sprites6") final List<String> sprites6,
@JsonProperty("mdpi") final String mdpi, @JsonProperty("svgs4") final List<String> svgs4) {
@JsonProperty("hdpi") final String hdpi,
@JsonProperty("xhdpi") final String xhdpi,
@JsonProperty("xxhdpi") final String xxhdpi,
@JsonProperty("xxxhdpi") final String xxxhdpi,
@JsonProperty("lsvg") final String lsvg,
@JsonProperty("hsvg") final String hsvg) {
this.id = id; this.id = id;
this.category = category; this.category = category;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.ldpi = ldpi; this.sprites6 = Objects.requireNonNull(sprites6);
this.mdpi = mdpi; if (sprites6.size() != 6) {
this.hdpi = hdpi; throw new IllegalArgumentException("sprites must have size 6");
this.xhdpi = xhdpi; }
this.xxhdpi = xxhdpi; this.svgs4 = Objects.requireNonNull(svgs4);
this.xxxhdpi = xxxhdpi; if (svgs4.size() != 4) {
this.lsvg = lsvg; throw new IllegalArgumentException("svgs must have size 4");
this.hsvg = hsvg; }
} }
public String getId() { public String getId() {
@ -67,36 +56,52 @@ public class Badge {
return description; return description;
} }
public List<String> getSprites6() {
return sprites6;
}
public List<String> getSvgs4() {
return svgs4;
}
@Deprecated
public String getLdpi() { public String getLdpi() {
return ldpi; return sprites6.get(0);
} }
@Deprecated
public String getMdpi() { public String getMdpi() {
return mdpi; return sprites6.get(1);
} }
@Deprecated
public String getHdpi() { public String getHdpi() {
return hdpi; return sprites6.get(2);
} }
@Deprecated
public String getXhdpi() { public String getXhdpi() {
return xhdpi; return sprites6.get(3);
} }
@Deprecated
public String getXxhdpi() { public String getXxhdpi() {
return xxhdpi; return sprites6.get(4);
} }
@Deprecated
public String getXxxhdpi() { public String getXxxhdpi() {
return xxxhdpi; return sprites6.get(5);
} }
@Deprecated
public String getLsvg() { public String getLsvg() {
return lsvg; return svgs4.get(0);
} }
@Deprecated
public String getHsvg() { public String getHsvg() {
return hsvg; return svgs4.get(3);
} }
@Override @Override
@ -112,30 +117,12 @@ public class Badge {
&& Objects.equals(category, badge.category) && Objects.equals(category, badge.category)
&& Objects.equals(name, badge.name) && Objects.equals(name, badge.name)
&& Objects.equals(description, badge.description) && Objects.equals(description, badge.description)
&& Objects.equals(ldpi, badge.ldpi) && Objects.equals(sprites6, badge.sprites6)
&& Objects.equals(mdpi, badge.mdpi) && Objects.equals(svgs4, badge.svgs4);
&& Objects.equals(hdpi, badge.hdpi)
&& Objects.equals(xhdpi, badge.xhdpi)
&& Objects.equals(xxhdpi, badge.xxhdpi)
&& Objects.equals(xxxhdpi, badge.xxxhdpi)
&& Objects.equals(lsvg, badge.lsvg)
&& Objects.equals(hsvg, badge.hsvg);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash( return Objects.hash(id, category, name, description, sprites6, svgs4);
id,
category,
name,
description,
ldpi,
mdpi,
hdpi,
xhdpi,
xxhdpi,
xxxhdpi,
lsvg,
hsvg);
} }
} }

View File

@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -21,17 +22,11 @@ public class SelfBadge extends Badge {
@JsonProperty("category") final String category, @JsonProperty("category") final String category,
@JsonProperty("name") final String name, @JsonProperty("name") final String name,
@JsonProperty("description") final String description, @JsonProperty("description") final String description,
@JsonProperty("ldpi") final String ldpi, @JsonProperty("sprites6") final List<String> sprites6,
@JsonProperty("mdpi") final String mdpi, @JsonProperty("svgs4") final List<String> svgs4,
@JsonProperty("hdpi") final String hdpi, @JsonProperty("expiration") final Instant expiration,
@JsonProperty("xhdpi") final String xhdpi, @JsonProperty("visible") final boolean visible) {
@JsonProperty("xxhdpi") final String xxhdpi, super(id, category, name, description, sprites6, svgs4);
@JsonProperty("xxxhdpi") final String xxxhdpi,
@JsonProperty("lsvg") final String lsvg,
@JsonProperty("hsvg") final String hsvg,
final Instant expiration,
final boolean visible) {
super(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, lsvg, hsvg);
this.expiration = expiration; this.expiration = expiration;
this.visible = visible; this.visible = visible;
} }

View File

@ -135,15 +135,15 @@ public class ConfiguredProfileBadgeConverterTest {
arguments(idFor(0), expired, false, false, null), arguments(idFor(0), expired, false, false, null),
arguments(idFor(0), notExpired, false, false, null), arguments(idFor(0), notExpired, false, false, null),
arguments(idFor(0), expired, true, false, null), arguments(idFor(0), expired, true, false, null),
arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", "s", "S")), arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", nameFor(0), desriptionFor(0), List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"))),
arguments(idFor(1), expired, false, false, null), arguments(idFor(1), expired, false, false, null),
arguments(idFor(1), notExpired, false, false, null), arguments(idFor(1), notExpired, false, false, null),
arguments(idFor(1), expired, true, false, null), arguments(idFor(1), expired, true, false, null),
arguments(idFor(1), notExpired, true, false, null), arguments(idFor(1), notExpired, true, false, null),
arguments(idFor(0), expired, false, true, null), arguments(idFor(0), expired, false, true, null),
arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", "s", "S", notExpired, false)), arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"), notExpired, false)),
arguments(idFor(0), expired, true, true, null), arguments(idFor(0), expired, true, true, null),
arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", "s", "S", notExpired, true)), arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"), notExpired, true)),
arguments(idFor(1), expired, false, true, null), arguments(idFor(1), expired, false, true, null),
arguments(idFor(1), notExpired, false, true, null), arguments(idFor(1), notExpired, false, true, null),
arguments(idFor(1), expired, true, true, null), arguments(idFor(1), expired, true, true, null),

View File

@ -108,8 +108,8 @@ class ProfileControllerTest {
profilesManager, profilesManager,
usernamesManager, usernamesManager,
dynamicConfigurationManager, dynamicConfigurationManager,
(acceptableLanguages, accountBadges, isSelf) -> List.of( (acceptableLanguages, accountBadges, isSelf) -> List.of(new Badge("TEST", "other", "Test Badge",
new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx", "s", "S") "This badge is in unit tests.", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"))
), ),
new BadgesConfiguration(List.of( new BadgesConfiguration(List.of(
new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),