Remove single URL in favor of density based sprite sheets

This commit is contained in:
Ehren Kret 2021-09-27 16:50:18 -05:00
parent a5575902de
commit 7864405efd
6 changed files with 130 additions and 69 deletions

View File

@ -6,7 +6,6 @@
package org.whispersystems.textsecuregcm.badges;
import com.google.common.annotations.VisibleForTesting;
import java.net.URL;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
@ -103,9 +102,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
isSelf,
accountBadge.getId(),
configuration.getCategory(),
configuration.getImageUrl(),
resourceBundle.getString(accountBadge.getId() + "_name"),
resourceBundle.getString(accountBadge.getId() + "_description"),
configuration.getLdpi(),
configuration.getMdpi(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
accountBadge.getExpiration(),
accountBadge.isVisible());
})
@ -116,9 +120,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
isSelf,
id,
configuration.getCategory(),
configuration.getImageUrl(),
resourceBundle.getString(id + "_name"),
resourceBundle.getString(id + "_description"),
configuration.getLdpi(),
configuration.getMdpi(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
now.plus(Duration.ofDays(1)),
true);
}).collect(Collectors.toList()));
@ -129,15 +138,20 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
final boolean isSelf,
final String id,
final String category,
final URL imageUrl,
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 Instant expiration,
final boolean visible) {
if (isSelf) {
return new SelfBadge(id, category, imageUrl, name, description, expiration, visible);
return new SelfBadge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, expiration, visible);
} else {
return new Badge(id, category, imageUrl, name, description);
return new Badge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
}
}
}

View File

@ -7,27 +7,38 @@ package org.whispersystems.textsecuregcm.configuration;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.net.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
public class BadgeConfiguration {
public static final String CATEGORY_TESTING = "testing";
private final String id;
private final URL imageUrl;
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;
@JsonCreator
public BadgeConfiguration(
@JsonProperty("id") final String id,
@JsonProperty("imageUrl") @JsonDeserialize(converter = URLDeserializationConverter.class) final URL imageUrl,
@JsonProperty("category") final String category) {
@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) {
this.id = id;
this.imageUrl = imageUrl;
this.category = category;
this.ldpi = ldpi;
this.mdpi = mdpi;
this.hdpi = hdpi;
this.xhdpi = xhdpi;
this.xxhdpi = xxhdpi;
this.xxxhdpi = xxxhdpi;
}
@NotEmpty
@ -35,17 +46,35 @@ public class BadgeConfiguration {
return id;
}
@NotNull
@JsonSerialize(converter = URLSerializationConverter.class)
public URL getImageUrl() {
return imageUrl;
}
@NotEmpty
public String getCategory() {
return category;
}
public String getLdpi() {
return ldpi;
}
public String getMdpi() {
return mdpi;
}
public String getHdpi() {
return hdpi;
}
public String getXhdpi() {
return xhdpi;
}
public String getXxhdpi() {
return xxhdpi;
}
public String getXxxhdpi() {
return xxxhdpi;
}
public boolean isTestBadge() {
return CATEGORY_TESTING.equals(category);
}

View File

@ -7,28 +7,42 @@ package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URL;
import java.util.Objects;
public class Badge {
private final String id;
private final String category;
private final URL imageUrl;
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;
@JsonCreator
public Badge(
@JsonProperty("id") final String id,
@JsonProperty("category") final String category,
@JsonProperty("imageUrl") final URL imageUrl,
@JsonProperty("name") final String name,
@JsonProperty("description") final String description) {
@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) {
this.id = id;
this.category = category;
this.imageUrl = imageUrl;
this.name = name;
this.description = description;
this.ldpi = ldpi;
this.mdpi = mdpi;
this.hdpi = hdpi;
this.xhdpi = xhdpi;
this.xxhdpi = xxhdpi;
this.xxxhdpi = xxxhdpi;
}
public String getId() {
@ -39,10 +53,6 @@ public class Badge {
return category;
}
public URL getImageUrl() {
return imageUrl;
}
public String getName() {
return name;
}
@ -51,6 +61,30 @@ public class Badge {
return description;
}
public String getLdpi() {
return ldpi;
}
public String getMdpi() {
return mdpi;
}
public String getHdpi() {
return hdpi;
}
public String getXhdpi() {
return xhdpi;
}
public String getXxhdpi() {
return xxhdpi;
}
public String getXxxhdpi() {
return xxxhdpi;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
@ -61,13 +95,15 @@ public class Badge {
}
Badge badge = (Badge) o;
return Objects.equals(id, badge.id) && Objects.equals(category,
badge.category) && Objects.equals(imageUrl, badge.imageUrl)
&& Objects.equals(name, badge.name) && Objects.equals(description,
badge.description);
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);
}
@Override
public int hashCode() {
return Objects.hash(id, category, imageUrl, name, description);
return Objects.hash(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
}
}

View File

@ -5,9 +5,7 @@
package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URL;
import java.time.Instant;
import java.util.Objects;
@ -18,16 +16,20 @@ public class SelfBadge extends Badge {
private final Instant expiration;
private final boolean visible;
@JsonCreator
public SelfBadge(
@JsonProperty("id") final String id,
@JsonProperty("category") final String category,
@JsonProperty("imageUrl") final URL imageUrl,
@JsonProperty("name") final String name,
@JsonProperty("description") final String description,
@JsonProperty("expiration") final Instant expiration,
@JsonProperty("visible") final boolean visible) {
super(id, category, imageUrl, name, 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,
final Instant expiration,
final boolean visible) {
super(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
this.expiration = expiration;
this.visible = visible;
}

View File

@ -13,8 +13,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Clock;
import java.time.Instant;
import java.util.ArrayList;
@ -56,14 +54,6 @@ public class ConfiguredProfileBadgeConverterTest {
return "Badge-" + i;
}
private static URL imageUrlFor(int i) {
try {
return new URL("https://example.com/badge/" + i);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
private static String nameFor(int i) {
return "TRANSLATED NAME " + i;
}
@ -73,7 +63,7 @@ public class ConfiguredProfileBadgeConverterTest {
}
private static BadgeConfiguration newBadge(int i) {
return new BadgeConfiguration(idFor(i), imageUrlFor(i), "other");
return new BadgeConfiguration(idFor(i), "other", "l", "m", "h", "x", "xx", "xxx");
}
private BadgesConfiguration createBadges(int count) {
@ -143,15 +133,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", imageUrlFor(0), nameFor(0), desriptionFor(0))),
arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx")),
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", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, false)),
arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", notExpired, false)),
arguments(idFor(0), expired, true, true, null),
arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, true)),
arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", notExpired, true)),
arguments(idFor(1), expired, false, true, null),
arguments(idFor(1), notExpired, false, true, null),
arguments(idFor(1), expired, true, true, null),

View File

@ -22,8 +22,6 @@ import com.google.common.collect.ImmutableSet;
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.dropwizard.testing.junit5.ResourceExtension;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Clock;
import java.time.Instant;
import java.util.Collections;
@ -96,14 +94,6 @@ class ProfileControllerTest {
private Account profileAccount;
private static URL makeURL(String url) {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
private static final ResourceExtension resources = ResourceExtension.builder()
.addProvider(AuthHelper.getAuthFilter())
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(
@ -118,13 +108,13 @@ class ProfileControllerTest {
usernamesManager,
dynamicConfigurationManager,
(acceptableLanguages, accountBadges, isSelf) -> List.of(
new Badge("TEST", "other", makeURL("https://example.com/badge/test"), "Test Badge", "This badge is in unit tests.")
new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx")
),
new BadgesConfiguration(List.of(
new BadgeConfiguration("TEST", makeURL("https://example.com/badge/test"), "other"),
new BadgeConfiguration("TEST1", makeURL("https://example.com/badge/1"), "testing"),
new BadgeConfiguration("TEST2", makeURL("https://example.com/badge/2"), "testing"),
new BadgeConfiguration("TEST3", makeURL("https://example.com/badge/3"), "testing")
new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx")
), List.of("TEST1")),
s3client,
postPolicyGenerator,