Move to using collections for sprites and svgs for badges
This commit is contained in:
parent
e07597eba7
commit
64eeb1e361
|
@ -104,14 +104,8 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
|
|||
configuration.getCategory(),
|
||||
resourceBundle.getString(accountBadge.getId() + "_name"),
|
||||
resourceBundle.getString(accountBadge.getId() + "_description"),
|
||||
configuration.getLdpi(),
|
||||
configuration.getMdpi(),
|
||||
configuration.getHdpi(),
|
||||
configuration.getXhdpi(),
|
||||
configuration.getXxhdpi(),
|
||||
configuration.getXxxhdpi(),
|
||||
configuration.getLowDetailSvg(),
|
||||
configuration.getHighDetailSvg(),
|
||||
configuration.getSprites(),
|
||||
configuration.getSvgs(),
|
||||
accountBadge.getExpiration(),
|
||||
accountBadge.isVisible());
|
||||
})
|
||||
|
@ -124,14 +118,8 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
|
|||
configuration.getCategory(),
|
||||
resourceBundle.getString(id + "_name"),
|
||||
resourceBundle.getString(id + "_description"),
|
||||
configuration.getLdpi(),
|
||||
configuration.getMdpi(),
|
||||
configuration.getHdpi(),
|
||||
configuration.getXhdpi(),
|
||||
configuration.getXxhdpi(),
|
||||
configuration.getXxxhdpi(),
|
||||
configuration.getLowDetailSvg(),
|
||||
configuration.getHighDetailSvg(),
|
||||
configuration.getSprites(),
|
||||
configuration.getSvgs(),
|
||||
now.plus(Duration.ofDays(1)),
|
||||
true);
|
||||
}).collect(Collectors.toList()));
|
||||
|
@ -144,20 +132,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
|
|||
final String category,
|
||||
final String name,
|
||||
final String description,
|
||||
final String ldpi,
|
||||
final String mdpi,
|
||||
final String hdpi,
|
||||
final String xhdpi,
|
||||
final String xxhdpi,
|
||||
final String xxxhdpi,
|
||||
final String lsvg,
|
||||
final String hsvg,
|
||||
final List<String> sprites,
|
||||
final List<String> svgs,
|
||||
final Instant expiration,
|
||||
final boolean visible) {
|
||||
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 {
|
||||
return new Badge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, lsvg, hsvg);
|
||||
return new Badge(id, category, name, description, sprites, svgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,44 +57,4 @@ public class BadgeConfiguration {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.entities;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Badge {
|
||||
|
@ -14,14 +15,8 @@ public class Badge {
|
|||
private final String category;
|
||||
private final String name;
|
||||
private final String description;
|
||||
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 lsvg;
|
||||
private final String hsvg;
|
||||
private final List<String> sprites6;
|
||||
private final List<String> svgs4;
|
||||
|
||||
@JsonCreator
|
||||
public Badge(
|
||||
|
@ -29,26 +24,20 @@ public class Badge {
|
|||
@JsonProperty("category") final String category,
|
||||
@JsonProperty("name") final String name,
|
||||
@JsonProperty("description") final String description,
|
||||
@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("lsvg") final String lsvg,
|
||||
@JsonProperty("hsvg") final String hsvg) {
|
||||
@JsonProperty("sprites6") final List<String> sprites6,
|
||||
@JsonProperty("svgs4") final List<String> svgs4) {
|
||||
this.id = id;
|
||||
this.category = category;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.ldpi = ldpi;
|
||||
this.mdpi = mdpi;
|
||||
this.hdpi = hdpi;
|
||||
this.xhdpi = xhdpi;
|
||||
this.xxhdpi = xxhdpi;
|
||||
this.xxxhdpi = xxxhdpi;
|
||||
this.lsvg = lsvg;
|
||||
this.hsvg = hsvg;
|
||||
this.sprites6 = Objects.requireNonNull(sprites6);
|
||||
if (sprites6.size() != 6) {
|
||||
throw new IllegalArgumentException("sprites must have size 6");
|
||||
}
|
||||
this.svgs4 = Objects.requireNonNull(svgs4);
|
||||
if (svgs4.size() != 4) {
|
||||
throw new IllegalArgumentException("svgs must have size 4");
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -67,36 +56,52 @@ public class Badge {
|
|||
return description;
|
||||
}
|
||||
|
||||
public List<String> getSprites6() {
|
||||
return sprites6;
|
||||
}
|
||||
|
||||
public List<String> getSvgs4() {
|
||||
return svgs4;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLdpi() {
|
||||
return ldpi;
|
||||
return sprites6.get(0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMdpi() {
|
||||
return mdpi;
|
||||
return sprites6.get(1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHdpi() {
|
||||
return hdpi;
|
||||
return sprites6.get(2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXhdpi() {
|
||||
return xhdpi;
|
||||
return sprites6.get(3);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXxhdpi() {
|
||||
return xxhdpi;
|
||||
return sprites6.get(4);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getXxxhdpi() {
|
||||
return xxxhdpi;
|
||||
return sprites6.get(5);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLsvg() {
|
||||
return lsvg;
|
||||
return svgs4.get(0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHsvg() {
|
||||
return hsvg;
|
||||
return svgs4.get(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,30 +117,12 @@ public class Badge {
|
|||
&& Objects.equals(category, badge.category)
|
||||
&& Objects.equals(name, badge.name)
|
||||
&& Objects.equals(description, badge.description)
|
||||
&& Objects.equals(ldpi, badge.ldpi)
|
||||
&& Objects.equals(mdpi, badge.mdpi)
|
||||
&& 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);
|
||||
&& Objects.equals(sprites6, badge.sprites6)
|
||||
&& Objects.equals(svgs4, badge.svgs4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
id,
|
||||
category,
|
||||
name,
|
||||
description,
|
||||
ldpi,
|
||||
mdpi,
|
||||
hdpi,
|
||||
xhdpi,
|
||||
xxhdpi,
|
||||
xxxhdpi,
|
||||
lsvg,
|
||||
hsvg);
|
||||
return Objects.hash(id, category, name, description, sprites6, svgs4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.entities;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -21,17 +22,11 @@ public class SelfBadge extends Badge {
|
|||
@JsonProperty("category") final String category,
|
||||
@JsonProperty("name") final String name,
|
||||
@JsonProperty("description") final String description,
|
||||
@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("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);
|
||||
@JsonProperty("sprites6") final List<String> sprites6,
|
||||
@JsonProperty("svgs4") final List<String> svgs4,
|
||||
@JsonProperty("expiration") final Instant expiration,
|
||||
@JsonProperty("visible") final boolean visible) {
|
||||
super(id, category, name, description, sprites6, svgs4);
|
||||
this.expiration = expiration;
|
||||
this.visible = visible;
|
||||
}
|
||||
|
|
|
@ -135,15 +135,15 @@ public class ConfiguredProfileBadgeConverterTest {
|
|||
arguments(idFor(0), expired, false, false, null),
|
||||
arguments(idFor(0), notExpired, false, 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), notExpired, false, false, null),
|
||||
arguments(idFor(1), expired, true, false, null),
|
||||
arguments(idFor(1), notExpired, true, false, 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), 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), notExpired, false, true, null),
|
||||
arguments(idFor(1), expired, true, true, null),
|
||||
|
|
|
@ -108,8 +108,8 @@ class ProfileControllerTest {
|
|||
profilesManager,
|
||||
usernamesManager,
|
||||
dynamicConfigurationManager,
|
||||
(acceptableLanguages, accountBadges, isSelf) -> List.of(
|
||||
new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx", "s", "S")
|
||||
(acceptableLanguages, accountBadges, isSelf) -> List.of(new Badge("TEST", "other", "Test Badge",
|
||||
"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 BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")),
|
||||
|
|
Loading…
Reference in New Issue