From f99de74044182fdadf3c1838d8de502920f8f8df Mon Sep 17 00:00:00 2001 From: Norbel Ambanumben Date: Mon, 21 Aug 2023 09:00:00 +0100 Subject: [PATCH] Adds default property values for `color` and `animation` if backend doesnt provide any --- .../domain/TestDescriptorManager.java | 2 + .../model/database/TestDescriptor.java | 82 +++++++++++++++++-- .../ooniprobe/test/suite/OONIRunSuite.java | 2 +- .../engine/OONIRunFetchResponse.kt | 2 + 4 files changed, 79 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/domain/TestDescriptorManager.java b/app/src/main/java/org/openobservatory/ooniprobe/domain/TestDescriptorManager.java index 340a391d7..0f2d24103 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/domain/TestDescriptorManager.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/domain/TestDescriptorManager.java @@ -52,6 +52,8 @@ public static TestDescriptor fetchDescriptorFromRunId(long runId, Context contex .withDescription(descriptor.getDescription()) .withDescriptionIntl(descriptor.getDescriptionIntl()) .withIcon(descriptor.getIcon()) + .withColor(descriptor.getColor()) + .withAnimation(descriptor.getAnimation()) .withArchived(response.archived) .withAuthor(descriptor.getAuthor()) .withCreationTime(response.creationTime) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.java b/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.java index 53398cb66..dc9d06408 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/TestDescriptor.java @@ -15,6 +15,7 @@ import org.openobservatory.ooniprobe.common.AppDatabase; import org.openobservatory.ooniprobe.common.LocaleUtils; import org.openobservatory.ooniprobe.common.MapUtility; +import org.openobservatory.ooniprobe.common.ThirdPartyServices; import org.openobservatory.ooniprobe.domain.MapConverter; import org.openobservatory.ooniprobe.domain.NettestConverter; import org.openobservatory.ooniprobe.test.suite.OONIRunSuite; @@ -26,6 +27,30 @@ import java.util.HashMap; import java.util.List; +import javax.annotation.Nullable; + +enum Animations { + checkMark("anim/checkMark.json"), + circumvention("anim/circumvention.json"), + crossMark("anim/crossMark.json"), + experimental("anim/experimental.json"), + instant_messaging("anim/instant_messaging.json"), + middle_boxes("anim/middle_boxes.json"), + performance("anim/performance.json"), + websites("anim/websites.json"); + + private final String asset; + + Animations(String asset) { + this.asset = asset; + } + + @Override + public String toString() { + return this.asset; + } +} + @Table(database = AppDatabase.class) public class TestDescriptor extends BaseModel implements Serializable { @PrimaryKey() @@ -52,6 +77,12 @@ public class TestDescriptor extends BaseModel implements Serializable { @Column private String icon; + @Column + private String color; + + @Column + private String animation; + @Column private String author; @@ -136,6 +167,37 @@ public void setIcon(String icon) { this.icon = icon; } + public String getColor() { + return color != null ? color : "#495057"; + } + + public void setColor(String color) { + this.color = color; + } + + public String getAnimation() { + return animation != null ? animation : "experimental"; + } + + public void setAnimation(String animation) { + this.animation = animation; + } + + public int getParsedColor() { + return Color.parseColor(getColor()); + } + + @Nullable + public String getAnimationAsset() { + try { + return Animations.valueOf(getAnimation()).toString(); + }catch (Exception e){ + e.printStackTrace(); + ThirdPartyServices.logException(e); + return null; + } + } + public String getAuthor() { return author; } @@ -222,14 +284,6 @@ public boolean shouldUpdate(TestDescriptor updatedDescriptor) { || updatedDescriptor.translationCreationTime.after(translationCreationTime); } - public String getAnimation() { - return "anim/websites.json"; - } - - public int getParsedColor() { - return Color.parseColor("#c92a2a"); - } - public static final class Builder { private long runId; @@ -240,6 +294,8 @@ public static final class Builder { private String description; private HashMap descriptionIntl; private String icon; + private String color; + private String animation; private String author; private boolean archived; private boolean autoRun; @@ -295,6 +351,16 @@ public Builder withIcon(String icon) { return this; } + public Builder withColor(String color) { + this.color = color; + return this; + } + + public Builder withAnimation(String animation) { + this.animation = animation; + return this; + } + public Builder withAuthor(String author) { this.author = author; return this; diff --git a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/OONIRunSuite.java b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/OONIRunSuite.java index 3a4464197..523927d72 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/OONIRunSuite.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/OONIRunSuite.java @@ -26,7 +26,7 @@ public OONIRunSuite(Context context, TestDescriptor descriptor, AbstractTest... R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Experimental, R.style.Theme_MaterialComponents_NoActionBar_App_Experimental, descriptor.getDescription(), - descriptor.getAnimation(), + descriptor.getAnimationAsset(), R.string.TestResults_NotAvailable); this.tests = tests; this.descriptor = descriptor; diff --git a/engine/src/main/java/org/openobservatory/engine/OONIRunFetchResponse.kt b/engine/src/main/java/org/openobservatory/engine/OONIRunFetchResponse.kt index deff4497f..f7d749c5c 100644 --- a/engine/src/main/java/org/openobservatory/engine/OONIRunFetchResponse.kt +++ b/engine/src/main/java/org/openobservatory/engine/OONIRunFetchResponse.kt @@ -24,6 +24,8 @@ data class OONIRunDescriptor( @SerializedName("description_intl") val descriptionIntl: HashMap, val icon: String, + val color: String, + val animation: String, val name: String, @SerializedName("name_intl") val nameIntl: HashMap,